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.
Weather Underground failover suggestion
Moderators: leecollings, remb0
- rolandbreedveld
- Posts: 156
- Joined: Wednesday 09 March 2016 11:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Weather Underground failover suggestion
Raspberry Pi(SSD)+UPS HAT,Dashticz on WallTablet,HomeBridge, P1, HarmonyHub,FritzBox,API to 123Solar+ABB-PowerOne+SMA,ESP-Leds(flashed LSC),Tasmota,Shelly,MQTT,Mosquito,Node-Red,http://wiki.breedveld.net/index.php?title=RPiWaterMeter, Mercedes-Me
- rolandbreedveld
- Posts: 156
- Joined: Wednesday 09 March 2016 11:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Weather Underground failover suggestion
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
#!/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
Raspberry Pi(SSD)+UPS HAT,Dashticz on WallTablet,HomeBridge, P1, HarmonyHub,FritzBox,API to 123Solar+ABB-PowerOne+SMA,ESP-Leds(flashed LSC),Tasmota,Shelly,MQTT,Mosquito,Node-Red,http://wiki.breedveld.net/index.php?title=RPiWaterMeter, Mercedes-Me
-
- Posts: 744
- Joined: Saturday 30 May 2015 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Re: Weather Underground failover suggestion
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'
It would be nicer indeed to have this kind of functionality integrated on the Domoticz hardware page for this 'hardware'
-
- Posts: 70
- Joined: Monday 06 February 2017 12:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V4.9700
- Location: Azores
- Contact:
Re: Weather Underground failover suggestion
Would be really awesome to include in hardware page
Who is online
Users browsing this forum: Amazon [Bot] and 1 guest