Skip to content

Instantly share code, notes, and snippets.

@courville
Last active January 4, 2019 14:03
Show Gist options
  • Save courville/627acd136941a3839fd076d5a1bd28cc to your computer and use it in GitHub Desktop.
Save courville/627acd136941a3839fd076d5a1bd28cc to your computer and use it in GitHub Desktop.
update domoticz scene timer to close roller shutters at dusk but not before 8pm and not after 10pm at Paris location
#!/bin/sh
#
# domoticz-closerollershutters
# use sunwait to get civil dusk time to calculates when to close roller shutters with the constraints to be in this interval >20h <22h, civildusk i.e. min(max(civildusk,20h),22h)
tdusk=`/usr/local/bin/sunwait -p 48.866667N 2.333333W | grep "Sun rises" | sed "s/^.* sets \([0-9]*\) .*$/\1/g"`
hdusk=`echo $tdusk | cut -c 1-2`
mdusk=`echo $tdusk | cut -c 3-4`
sdusk=`date -d"$hdusk:$mdusk" +%s`
notbefore=`date -d"20:00" +%s`
notafter=`date -d"22:00" +%s`
# max(sdusk,notbefore)
temp=$(($sdusk>$notbefore?$sdusk:$notbefore))
# min(ans,notafter)
result=$(($temp>$notafter?$notafter:$temp))
hdown=`date -d@$result +%H`
mdown=`date -d@$result +%M`
isvacation=`curl -s "http://localhost:8084/json.htm?type=devices&rid=43" | grep Status | sed 's/^.*Status.* : "\([^"]*\)",$/\1/g'`
if [ "$isvacation" = "Off" ]
then
echo we are not on vacation, fine: setting shutter closing time to $hdown:$mdown
# close roller shutters
ACTION=updatescenetimer
t=4
curl "http://localhost:8084/json.htm?type=command&param=$ACTION&idx=$t&active=true&timertype=2&hour=$hdown&min=$mdown&randomness=false&command=0&days=1234567"
else
echo lucky us: we are on vacation, no change
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment