Created
January 11, 2024 19:51
-
-
Save kristofer84/0e86ce86888013be6515d16190a88f22 to your computer and use it in GitHub Desktop.
Dead man's switch for RPi connected via Tasmota controlled switch
This file contains 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 | |
# Dead man's switch for Tasmota | |
# Presmues that timers has been enabled | |
# Continuously move the restart timers forward | |
read -r day hour <<< $(date -d "+2 hours" +"%u %H") | |
# Convert date output where Monday is 1 to timer format where Sunday is 1 | |
day=$((day%7+1)) | |
# Week schedule string | |
dayvar=$(echo '0000000' | sed s/0/1/$day) | |
# Turn off | |
timer1="{\"Enable\":1,\"Mode\":0,\"Time\":\"$hour:05\",\"Window\":0,\"Days\":\"$dayvar\",\"Repeat\":0,\"Output\":1,\"Action\":0}" | |
# Turn on | |
timer2="{\"Enable\":1,\"Mode\":0,\"Time\":\"$hour:06\",\"Window\":0,\"Days\":\"$dayvar\",\"Repeat\":0,\"Output\":1,\"Action\":1}" | |
#echo $timer1 | |
#echo $timer2 | |
mosquitto_pub -h localhost -t 'cmnd/tasmota_F795A8/Timer1' -m $timer1 | |
mosquitto_pub -h localhost -t 'cmnd/tasmota_F795A8/Timer2' -m $timer2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment