Created
December 28, 2020 07:39
-
-
Save daemonp/b06a5232ebdc71ad6b5ba064e4fbe8d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# monitor asound status changes and trigger mqtt events | |
SND_STATUS="/proc/asound/card1/pcm0p/sub0/status" | |
MQTT_TOPIC="shellies/shelly1-xxxxx/relay/0/command" | |
MQTT_HOST="mqtt.home" | |
while true ; do | |
value=`cat $SND_STATUS | egrep 'state|closed'` | |
if [[ "$value" =~ "RUNNING" ]] && [[ "$status" != "on" ]] ; then | |
status=on | |
[[ -t 1 ]] && echo $status | |
# Fire MQTT to turn on amp | |
mosquitto_pub -h $MQTT_HOST -t MQTT_TOPIC -m $status | |
elif [[ "$value" =~ "closed" ]] && [[ "$status" != "off" ]]; then | |
status=off | |
[[ -t 1 ]] && echo $status | |
# Fire MQTT to turn off amp | |
mosquitto_pub -h $MQTT_HOST -t MQTT_TOPIC -m $status | |
fi | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment