Page 1 of 1

Weather Underground failover suggestion

Posted: Tuesday 26 September 2017 21:38
by rolandbreedveld
Because the weather underground stations in my neighbourhood, sometimes are of duty for some hours to days,
I want to suggest to add a secondary and perhaps a third station ID in case the primary station fails for e.g. more than 1 hour.
A the moment I solve this with a Unix (cron) script which changes the weather-station-id if it's of-line for longer than 1 hour directly in the database.

Re: Weather Underground failover suggestion

Posted: Wednesday 27 September 2017 13:32
by rolandbreedveld
For those who are interested:



#!/bin/bash
#----------------------------------------------------------#
# check_weater_stations.sh
# 2017-09-27 V1.0 Roland Breedveld
#----------------------------------------------------------#
IDX=10
HID=5
PRI="pws:IXXXX201"
SEC="pws:IXXXX97"
API_KEY="xxxxxxxx"
#----------------------------------------------------------#

DATE=$(date -d '1 hour ago' '+%Y-%m-%d %H:%M:00')
CUR=$(sqlite3 /home/pi/domoticz/domoticz.db "select Password from hardware where id = '${HID}' ;")
ACTIVE=$(sqlite3 /home/pi/domoticz/domoticz.db "select * from temperature where devicerowid = '${IDX}' and date >= '${DATE}' ;")

if [ "${CUR}" == "${PRI}" ]
then
if [ ! -z "${ACTIVE}" ]
then
echo "Primair Station ${PRI} active"
else
echo "Primair Station ${PRI} no data"
echo "Failover to Secundair Station ${SEC}"
sqlite3 /home/pi/domoticz/domoticz.db "update hardware set Password='${SEC}' where id = '${HID}' ;"
fi
else
WDATE=$(wget -O - http://api.wunderground.com/api/${API_K ... {PRI}.json 2>&1|grep "observation_time_rfc822"| awk -F\" '{print $4}')
echo ${WDATE}
ZDATE=$(date -d"${WDATE}" +%s)
ZNOW=$(date +%s)
ZDIFF=$(echo "0$ZNOW 0$ZDATE"|awk '{print ( $1 - $2 )}')
if [ "${ZDIFF}" -gt "1800" ]
then
echo "Primair Station ${PRI} to old: keep Secundary Station ${SEC}"
if [ -z "${ACTIVE}" ]
then
echo "Both Stations are Offline"
fi
else
echo "Go back to Primary Station ${PRI}"
sqlite3 /home/pi/domoticz/domoticz.db "update hardware set Password='${PRI}' where id = '${HID}' ;"
fi
fi

Re: Weather Underground failover suggestion

Posted: Monday 08 January 2018 21:20
by jake
Thanks for this script. Do you simply call it every hour?

It would be nicer indeed to have this kind of functionality integrated on the Domoticz hardware page for this 'hardware'

Re: Weather Underground failover suggestion

Posted: Monday 22 January 2018 1:24
by gajotnt
Would be really awesome to include in hardware page