Skip to content

Instantly share code, notes, and snippets.

@miklos-szel
Last active August 20, 2024 06:52
Show Gist options
  • Select an option

  • Save miklos-szel/5eddf5f0882e502d6a8ad7f290812ba9 to your computer and use it in GitHub Desktop.

Select an option

Save miklos-szel/5eddf5f0882e502d6a8ad7f290812ba9 to your computer and use it in GitHub Desktop.
Wiim soft trigger for amps without 12v trigger (with Tasmota power plug)
#!/bin/bash
## sudo apt install python3-pip
##
# URL and command details
URL="http://192.168.0.65:49152/description.xml"
COMMAND="/usr/local/bin/upnp-client --pprint call-action $URL AVTransport/GetInfoEx InstanceID=0"
POWER_URL="/usr/bin/wget -O /dev/null -o /dev/null http://192.168.0.202/cm?cmnd=Power%20"
INTERVAL=5
# Initialize previous status
previous_status=""
delay_stop=0
# Function to check the status
check_status() {
# Execute the command and capture the output
output=$($COMMAND 2>&1)
# Extract the CurrentTransportState value
current_status=$(echo "$output" | grep -oP '(?<="CurrentTransportState": ")[^"]+')
# Check if the current status is different from the previous status
echo "curr: $current_status" |systemd-cat -t wiim -p info
echo "prev: $previous_status" |systemd-cat -t wiim -p info
if [ "$current_status" != "$previous_status" ]; then
# Update the previous status
# If the current status is "PLAYING", execute the specific command
if [ "$current_status" == "PLAYING" ]; then
echo "Turning on the Amp" |systemd-cat -t wiim -p info
$(${POWER_URL}ON)
previous_status="$current_status"
delay_stop=0
else
#only turn off the power after 5 (60 x 5 sec) minutes without activity
delay_stop=$((delay_stop+1))
echo "delay_stop $delay_stop" | systemd-cat -t wiim -p info
previous_status=""
if [ $delay_stop -eq 60 ]; then
echo "Turning off the Amp" |systemd-cat -t wiim -p info
$(${POWER_URL}OFF)
fi
fi
fi
}
# Infinite loop to run the command every 5 seconds
while true; do
check_status
sleep $INTERVAL
done
@miklos-szel
Copy link
Author

/etc/systemd/system
root@ha:/etc/systemd/system# cat cover.service
[Unit]
Description=Update cover art
After=network.target
StartLimitIntervalSec=33
StartLimitBurst=5

[Service]
ExecStart=/usr/local/bin/cover.py
StandardOutput=inherit
StandardError=inherit
User=ha

[Install]
WantedBy=default.target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment