| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #!/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
|