Skip to content

Instantly share code, notes, and snippets.

@joshespi
Last active December 11, 2023 21:29
Show Gist options
  • Save joshespi/106b4084df5341af8f60e4d323b8cc57 to your computer and use it in GitHub Desktop.
Save joshespi/106b4084df5341af8f60e4d323b8cc57 to your computer and use it in GitHub Desktop.
Checks power status of device 0 then turns it off if the device is on
#!/bin/bash
# Get the current hour in local time
current_hour_local=$(date +%H)
# Check if the current time is before 7 AM or after 5 PM
if [ "$current_hour_local" -lt 7 ] || [ "$current_hour_local" -ge 17 ]; then
# Run cec-client and capture the power status of the TV
power_status=$(echo 'pow 0' | cec-client -s -d 1 | grep 'power status' | awk '{print $3}')
# Check if the power status is "on"
if [ "$power_status" == "on" ]; then
# If the TV is on, send the standby command
echo 'standby 0' | cec-client -s -d 1
echo "TV is on. Sent standby command."
else
echo "TV is not on. No action needed."
fi
else
echo "Within the specified time range (7 AM - 5 PM). No action needed."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment