Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- IP=MYIP
- declare -A devices=(
- ["tv"]="2"
- ["garage_light"]="1"
- )
- stdbuf -oL mosquitto_sub -v -h $IP -t 'cmnd/+/POWER'|
- while IFS= read -r line
- do
- device=$(echo $line | cut -d'/' -f2)
- state=$(echo $line | cut -d' ' -f2)
- echo "received request to turn $state $device"
- # check if it is a valid signal
- if [ ${devices[$device]+check} ] ; then
- # send home assistant status on
- echo "seems legit"
- if [ "$state" == "OFF" ] ; then
- codesend ${devices[$device]} off
- mosquitto_pub -h $IP -t stat/${device}/POWER -m "OFF"
- elif [ "$state" == "ON" ] ; then
- codesend ${devices[$device]} on
- mosquitto_pub -h $IP -t stat/${device}/POWER -m "ON"
- else
- echo "unknown state $state"
- fi
- else
- echo "unknown device $device"
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement