It happens for me, the bedroom tv stays on because the timer did not end, also had to manual end the timer of the tablet on the wall, from time to time, so I made this script as a backup for Domoticz for critical timers that should end.
Maybe it would be nice to have this built-in Domoticz, as a check, when a server restarts, or process, it checks on startup what timers are still valid, maybe retime the switch, based on last update and seconds filled in the switch and status (on), so you get a restored version of Domoticz, when a server restarted, process etc.
I like to use these (dummy switches) timers allot, because you can reset them with a new period of time, or switch them off, where there, the blocky timers have no control at all, only the timer itself.
Have fun !!

filename : domoticz.timers.status.sh
Code: Select all
#!/bin/bash
# domoticz.timers.status.sh
#
# Domoticz check status timers (dummy switch with buit-in timer) and stop it when "Switch-off delay" time has expires.
#
# When a Domoticz server restart, or just process restart (by logrotate), the (dummy switches) timers are lost, this script will check the status en end the timer(s) that has expires.
#
# 1. Make a dummy switch inside Domoticz and set the "Switch-off delay" in seconds, for example 3600 (1 hour)
# 2. Change the IP address "DOMOTICZIP="127.0.0.1"" now set to the same machine
# 3. Set the timer(s) IDX "IDXTOCHECK=`echo -e "146:150:151:152:153:166:177:200"`"
# 4. Run this script every 10-30-60 minutes
#
#
# By ILoveIOT 2019
#
# Domoticz IP address
DOMOTICZIP="127.0.0.1"
# Domoticz IDX(s) to check use : for separate, if u use only 1 idx, use 200: or 100:
#IDXTOCHECK=`echo -e "200:"`
IDXTOCHECK=`echo -e "146:150:151:152:153:166:173:177:200"`
#########################################################################################
#########################################################################################
CDATE=`/bin/date`
# Do the loop for "IDXTOCHECK"
c=1
temps=`echo "$IDXTOCHECK" | /usr/bin/cut -f $c -d ":"`
while [ -n "$temps" ]; do
STATUSOFTIMER=`/usr/bin/curl -s 'http://'$DOMOTICZIP':8080/json.htm?type=devices&rid='$temps'' | /bin/grep Status | /usr/bin/awk '{ print $3 }' | /bin/sed 's/,/ /g' | /usr/bin/tr -d '"'`
if [ $STATUSOFTIMER = "On" ] ; then
# Get the last switch update from Domoticz
LASTUPDATETIME=`/usr/bin/curl -s 'http://'$DOMOTICZIP':8080/json.htm?type=devices&rid='$temps'' | /bin/grep LastUpdate | /usr/bin/awk '{ print $4 }' | /bin/sed 's/,/ /g' | /usr/bin/tr -d '"'`
LASTUPDATEDATE=`/usr/bin/curl -s 'http://'$DOMOTICZIP':8080/json.htm?type=devices&rid='$temps'' | /bin/grep LastUpdate | /usr/bin/awk '{ print $3 }' | /usr/bin/tr -d '"' | /usr/bin/cut -c6-10 | /usr/bin/tr - /`
# Get the Switch-off delay seconds from the switch, from Domoticz
TIMERVALUEINSECONDS=`/usr/bin/curl -s 'http://'$DOMOTICZIP':8080/json.htm?type=devices&rid='$temps'' | /bin/grep "AddjValue" | /usr/bin/awk '{ print $3 }' | head -n 1 | /bin/sed 's/.0,/ /g'`
# Calculate the end date
ENDDATE=`/bin/date -d "$LASTUPDATEDATE $LASTUPDATETIME $TIMERVALUEINSECONDS sec" "+%m/%d %H:%M:%S"`
# Get the current date for compare
CURRENTDATE=`/bin/date "+%m/%d %H:%M:%S"`
# Convert the end and current time for compare
ENDDATEINSEC=`/bin/date -d "$ENDDATE" '+%s'`
CURRENTDATEINSEC=`/bin/date -d "$CURRENTDATE" '+%s'`
# If the timer has expired switch it off in Domoticz.
if [ $CURRENTDATEINSEC \> $ENDDATEINSEC ]; then
/usr/bin/curl -i -s "http://$DOMOTICZIP:8080/json.htm?type=command¶m=switchlight&idx=$temps&switchcmd=Off" >> /dev/null 2>&1
# Some mail output for debug when console not active
# Get the IDX name just for debuging, so you see the name of the IDX on console
IDXNAME=`/usr/bin/curl -s 'http://'$DOMOTICZIP':8080/json.htm?type=devices&rid='$temps'' | /bin/grep Name | /bin/sed -n '2p' | /usr/bin/awk '{print $3,$4,$5,$6,$7,$8}' | /usr/bin/tr -d '"' | /usr/bin/tr -d ','`
echo ""
echo "IDX : $temps"
echo "IDXNAME : $IDXNAME"
echo "STATUSOFTIMER : $STATUSOFTIMER"
echo "TIMERVALUEINSECONDS : $TIMERVALUEINSECONDS"
echo "LASTUPDATE : $LASTUPDATEDATE $LASTUPDATE"
echo "ENDDATE : $ENDDATE"
echo "CURRENTDATE : $CURRENTDATE"
echo "ENDDATEINSEC : $ENDDATEINSEC"
echo "CURRENTDATEINSEC : $CURRENTDATEINSEC"
echo ""
fi
# Some console output for debug
# Get the IDX name just for debuging, so you see the name of the IDX on console
#IDXNAME=`/usr/bin/curl -s 'http://'$DOMOTICZIP':8080/json.htm?type=devices&rid='$temps'' | /bin/grep Name | /bin/sed -n '2p' | /usr/bin/awk '{print $3,$4,$5,$6,$7,$8}' | /usr/bin/tr -d '"' | /usr/bin/tr -d ','`
#echo ""
#echo "IDX : $temps"
#echo "IDXNAME : $IDXNAME"
#echo "STATUSOFTIMER : $STATUSOFTIMER"
#echo "TIMERVALUEINSECONDS : $TIMERVALUEINSECONDS"
#echo "LASTUPDATE : $LASTUPDATEDATE $LASTUPDATE"
#echo "ENDDATE : $ENDDATE"
#echo "CURRENTDATE : $CURRENTDATE"
#echo "ENDDATEINSEC : $ENDDATEINSEC"
#echo "CURRENTDATEINSEC : $CURRENTDATEINSEC"
#echo ""
fi
# End the loop IDXTOCHECK
let c=$c+1
temps=`echo "$IDXTOCHECK" | cut -f $c -d ":"`
done
#echo ""
#echo "Started @ $CDATE"
#echo "Finished @ `date`"
#echo ""
exit
#EOF