root před 2 roky
revize
1bf21897fb
3 změnil soubory, kde provedl 76 přidání a 0 odebrání
  1. 6 0
      installvondaniel.txt
  2. 58 0
      sis2mqtt.sh
  3. 12 0
      sispmctl.service

+ 6 - 0
installvondaniel.txt

@@ -0,0 +1,6 @@
+apt install mosquitto-clients -y
+chmod +x sis2mqtt.sh
+cp sispmctl.service /etc/systemd/system/
+systemctl daemon-reload
+systemctl enable sispmctl.service
+systemctl start sispmctl.service

+ 58 - 0
sis2mqtt.sh

@@ -0,0 +1,58 @@
+#!/bin/bash
+
+MQTT_Host="172.30.81.130"
+MQTT_User="raspberry"
+MQTT_Pass="8Wv2fxBgrSfO"
+MQTT_Client="nhi-sz-rl-harb"
+Prefix="HA/NHI/SZ/HARB/SISPMCTL"
+
+SISPMCTLBIN="/usr/local/bin/sispmctl"
+
+function SendStatus {
+  for SIS_Device in $(${SISPMCTLBIN} -s | grep "serial" | cut -d " " -f6); do
+    OutletNr=1
+    for Outlet in $(${SISPMCTLBIN} -q -D ${SIS_Device} -n -g all); do
+      if [ $Outlet -ne 0 ] ; then
+        OutletText="ON"
+      else
+        OutletText="OFF"
+      fi
+      mosquitto_pub -h ${MQTT_Host} -u ${MQTT_User} -P ${MQTT_Pass} -i ${MQTT_Client} -t "${Prefix}/tele/${SIS_Device}/POWER${OutletNr}" -m ${OutletText}
+      OutletNr=$((OutletNr+1))
+    done
+  done
+}
+
+SendStatus
+
+while true; do
+  mosquitto_sub -h ${MQTT_Host} -u ${MQTT_User} -P ${MQTT_Pass} -i ${MQTT_Client} -t ${Prefix}/cmd/# -v | while read -r payload; do
+    Topic=$(echo $payload | cut -d " " -f1)
+    Message=$(echo $payload | cut -d " " -f2)
+
+    DeviceID=$(echo $Topic | awk -F/ '{print $(NF-1)}')
+    OutletID=$(echo $Topic | awk -F/ '{print $NF}')
+    OutletID=$(echo $OutletID | tr -d "POWER")
+
+    Message=$(echo $Message | awk '{ print toupper($0) }')
+    if [ "x$Message" == "xON" ] || [ "x$Message" == "x1" ] ; then
+      Param="o"
+      SchaltWort="on"
+    else
+      Param="f"
+      SchaltWort="off"
+    fi
+
+    ${SISPMCTLBIN} -q -D $DeviceID -${Param} $OutletID
+
+    if [ $? -eq 0 ] ; then
+      mosquitto_pub -h ${MQTT_Host} -u ${MQTT_User} -P ${MQTT_Pass} -i ${MQTT_Client} -t "${Prefix}/lastresult" -m "Outlet $OutletID on Device $DeviceID successfully turned $SchaltWort"
+    else
+      mosquitto_pub -h ${MQTT_Host} -u ${MQTT_User} -P ${MQTT_Pass} -i ${MQTT_Client} -t "${Prefix}/lastresult" -m "Error while switching Outlet $OutletID on Device $DeviceID"
+    fi
+
+    SendStatus
+  done
+
+  sleep 10
+done

+ 12 - 0
sispmctl.service

@@ -0,0 +1,12 @@
+[Unit]
+Description=Sispm Mqtt bridge Service
+Requires=network.target
+
+[Service]
+Type=simple
+#ExecStart=/scripts/sis2mqtt/sispmctl-to-MQTT.py
+ExecStart=/scripts/sis2mqtt/sis2mqtt.sh
+Nice=5
+
+[Install]
+WantedBy=multi-user.target