# openHAB

# OpenHAB3 - Logs auslesen in Shell

```bash
sudo su
tail -f /var/lib/docker/volumes/openhab_openhab_userdata/_data/logs/openhab.log -f /var/lib/docker/volumes/openhab_openhab_userdata/_data/logs/events.log
```

# Environment Variables

\#OPENHAB\_HOME=/usr/share/openhab2  
\#OPENHAB\_CONF=/etc/openhab2  
\#OPENHAB\_RUNTIME=/usr/share/openhab2/runtime  
\#OPENHAB\_USERDATA=/var/lib/openhab2  
\#OPENHAB\_LOGDIR=/var/log/openhab2

# Surveillance Station Bewegung zu openHAB

Kamerabewegungserkennung ueber Synology Surveillance Station ueber Webhook an openhab rest api senden:

[![image.png](https://bookstack.eike-f.de/uploads/images/gallery/2023-04/scaled-1680-/6Qiimage.png)](https://bookstack.eike-f.de/uploads/images/gallery/2023-04/6Qiimage.png)

statt 'ON' kann auch 'TOGGLE' verwendet werden

Vogelhaus TP-Link Tapo C100 Kamera Cam Baumstr REST API

[http://192.168.1.76:8080/rest/items/ITEMNAME](http://192.168.1.76:8080/rest/items/ITEMNAME)

plain/text

POST

<div id="bkmrk--0" style="background:none;line-height:0px;overflow:hidden;padding:10px 5px 5px;visibility:visible;opacity:1;width:auto;height:auto;display:none;"></div><div id="bkmrk--1" style="background:none;line-height:0px;overflow:hidden;padding:10px 5px 5px;visibility:visible;opacity:1;width:auto;height:auto;display:none;"></div>

# Surveillance Station GetSnapshot via API

1\) Infos zur API und ihren einzelnen Versionen rausholen:

GET

```
http://192.168.1.10:5000/webapi/query.cgi?api=SYNO.API.Info&method=Query&version=1&query=ALL
```

2\) Login via API:

GET

```
192.168.1.10:5000/webapi/auth.cgi?api=SYNO.API.Auth&method=login&version=7&account=MEINBENUTZER&passwd=MEINPASSWORT&session=SurveillanceStation&format=sid 
```

also Response kommt etwa

```json
{
    "data": {
        "account": "Eike",
        "device_id": "-Ezsffph96I7C.......o4sr2EI9h36Ym-j2w",
        "ik_message": "",
        "is_portal_port": false,
        "sid": "vF-JE8-4Xe6Yet........9XbSc_7z8NpLhf5VtU",
        "synotoken": "--------"
    },
    "success": true
}
```

daraus den sid (String Identifier) kopieren und an den getCameraList Request haengen:

3\) getCameraList

GET

```
http://192.168.1.10:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=List&version=3&_sid=vF-JE8-4......bSc_7z8NpLhf5VtU
```

Aus Response die ID der Kamera entnehmen:

[![image.png](https://bookstack.eike-f.de/uploads/images/gallery/2023-04/scaled-1680-/nA9image.png)](https://bookstack.eike-f.de/uploads/images/gallery/2023-04/nA9image.png)

4\) getSnapshot

id in Request fuer den Snapshot einfuegen

GET

```
192.168.1.10:5000/webapi/entry.cgi?version=9&id=10&api=SYNO.SurveillanceStation.Camera&method=GetSnapshot&profileType=1&_sid=vF-JE8-4Xe........_7z8NpLhf5VtU
```

<p class="callout success">Erfolg!</p>

[![image.png](https://bookstack.eike-f.de/uploads/images/gallery/2023-04/scaled-1680-/ryfimage.png)](https://bookstack.eike-f.de/uploads/images/gallery/2023-04/ryfimage.png)

<div id="bkmrk--1" style="background:none;line-height:0px;overflow:hidden;padding:10px 5px 5px;visibility:visible;opacity:1;width:auto;height:auto;display:none;"></div>

# Skript ausführen (RestAPI curl POST)

auf openhab server:  
/home/openhabian/tb-temp.sh

```bash
#!/bin/bash

#while :
#do
#  cpuUsage=$(top -bn1 | awk '/Cpu/ { print $2}')
#  memUsage=$(free -m | awk '/Mem/{print $3}')
#  sleep 10
#done


key01=$1
value01=$2
echo 'Starte Thingsboard POST Request mit: '$key01' und '$value01

curl -v -X POST -d "{\"$key01\": $value01}" https://thingsboard.cloud/api/v1/EYDyfp3Ep14qyFuluIZM/telemetry --header "Content-Type:application/json"

```

in openhab rules:  
e3dc-to-thingsboard.rules

```
rule "Sende PV-Anlagedaten Hausverbrauch an Thingsboard"
when
    Item E3DC_Haus changed
then
    logInfo("Thingsboard","Sende Power House")
    executeCommandLine("/home/openhabian/tb-temp.sh@@Power_House_W@@"+E3DC_Haus.state.toString, 2*1000)
end

rule "Sende PV-Anlagedaten minütlich an Thingsboard"
when
    Time cron "0 * * * * ?" //jede Minute (wenn Sekunden = 0)
then
    logInfo("Thingsboard","Sende minütlich")
    executeCommandLine("/home/openhabian/tb-temp.sh@@Power_Grid_W@@"+E3DC_Netz.state.toString, 2*1000)
    executeCommandLine("/home/openhabian/tb-temp.sh@@Power_PV_W@@"+E3DC_PV.state.toString, 2*1000)
    executeCommandLine("/home/openhabian/tb-temp.sh@@Power_Battery_W@@"+E3DC_Battery.state.toString, 2*1000)
    executeCommandLine("/home/openhabian/tb-temp.sh@@SOC_Battery_Perc@@"+E3DC_SOC.state.toString, 2*1000)
    executeCommandLine("/home/openhabian/tb-temp.sh@@Power_PV-String-East_W@@"+E3DC_Power_String1.state.toString, 2*1000)
    executeCommandLine("/home/openhabian/tb-temp.sh@@Power_PV-String-West_W@@"+E3DC_Power_String2.state.toString, 2*1000)
end


```