Skip to content

Instantly share code, notes, and snippets.

@daemonp
Created December 28, 2020 07:39
Show Gist options
  • Save daemonp/b06a5232ebdc71ad6b5ba064e4fbe8d1 to your computer and use it in GitHub Desktop.
Save daemonp/b06a5232ebdc71ad6b5ba064e4fbe8d1 to your computer and use it in GitHub Desktop.
#!/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