Added scripts
parent
882148d6e8
commit
95027a9ff1
|
@ -0,0 +1,34 @@
|
|||
#
|
||||
# darkskyAPI = your DarkSky API key below, it's free to get one
|
||||
# location = your location lat,long
|
||||
# probabilityOver = Enable rain delay if probability of rain today is grater than this number.
|
||||
# Range is 0 to 1, so 0.5 is 50%
|
||||
# sprinklerdEnableDelay = the URL to SprinklerD
|
||||
#
|
||||
darkskyAPI='0123456789abcdef9876543210fedcba'
|
||||
location='42.3601,-71.0589'
|
||||
probabilityOver=0.5
|
||||
sprinklerdEnableDelay="http://localhost/?type=option&option=24hdelay&state=reset"
|
||||
|
||||
echoerr() { printf "%s\n" "$*" >&2; }
|
||||
echomsg() { if [ -t 1 ]; then echo "$@" 1>&2; fi; }
|
||||
|
||||
command -v jq >/dev/null 2>&1 || { echoerr "jq is not installed. Aborting!"; exit 1; }
|
||||
command -v bc >/dev/null 2>&1 || { echoerr "bc not installed. Aborting!"; exit 1; }
|
||||
|
||||
probability=$(curl -s "https://api.darksky.net/forecast/"$darkskyAPI"/29.884444,-95.62" | jq '.["daily"].data[0].precipProbability' 2>/dev/null)
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echoerr "Error reading DarkSkys URL, please check!"
|
||||
echoerr "Maybe you didn't configure your API and location?"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echomsg -n "Probability of rain today is "`echo "$probability * 100" | bc`"%"
|
||||
|
||||
if (( $(echo "$probability > $probabilityOver" | bc -l) )); then
|
||||
echomsg -n ", enabeling rain delay"
|
||||
curl -s "$sprinklerdEnableDelay" > /dev/null
|
||||
fi
|
||||
|
||||
echomsg ""
|
|
@ -0,0 +1,25 @@
|
|||
#!/bin/bash
|
||||
|
||||
URL="http://sprinkler/?type=option&option=24hdelay&state=reset&time="
|
||||
|
||||
|
||||
if [[ "$1" =~ ^[0-9]+$ ]]; then
|
||||
days=$1
|
||||
else
|
||||
echo "No days listed, using 1 day"
|
||||
days=1
|
||||
fi
|
||||
|
||||
delaytime=$(/bin/date -d "now + $days days" "+%s")
|
||||
cnt=0
|
||||
|
||||
while [ "$rtn" != "200" ]; do
|
||||
rtn=$(/usr/bin/curl -s -o /dev/null -w "%{http_code}" "$URL$delaytime")
|
||||
if [ "$rtn" != "200" ]; then
|
||||
cnt=$[$cnt + 1]
|
||||
if [ $cnt -lt 3 ]; then
|
||||
sleep 10
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
Loading…
Reference in New Issue