Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save volschin/a4e9e8398432671e2488be5f079f4aa8 to your computer and use it in GitHub Desktop.

Select an option

Save volschin/a4e9e8398432671e2488be5f079f4aa8 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