Last active
December 11, 2023 21:29
-
-
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
This file contains hidden or 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/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