Weather Underground failover suggestion

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.
Post Reply
User avatar
rolandbreedveld
Posts: 61
Joined: Wednesday 09 March 2016 12:25
Target OS: Raspberry Pi
Domoticz version: stable
Contact:

Weather Underground failover suggestion

Post by rolandbreedveld » Tuesday 26 September 2017 21:38

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.
Raspberry Pi2+3 | P1 SmartMeter | Z-Wave Razberry 2.0 | 4 Greenwave devices | FIBARO FGS223 +FGRM222 | Aerotec MultiSensor 6 | 4 NeoCoolCam PowerPlug | Logitech Harmony Hub | FritzBox
Interface to 123Solar + PowerOne 3.0 and SMA SB1200

User avatar
rolandbreedveld
Posts: 61
Joined: Wednesday 09 March 2016 12:25
Target OS: Raspberry Pi
Domoticz version: stable
Contact:

Re: Weather Underground failover suggestion

Post by rolandbreedveld » Wednesday 27 September 2017 13:32

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
Raspberry Pi2+3 | P1 SmartMeter | Z-Wave Razberry 2.0 | 4 Greenwave devices | FIBARO FGS223 +FGRM222 | Aerotec MultiSensor 6 | 4 NeoCoolCam PowerPlug | Logitech Harmony Hub | FritzBox
Interface to 123Solar + PowerOne 3.0 and SMA SB1200

jake
Posts: 387
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Weather Underground failover suggestion

Post by jake » Monday 08 January 2018 22:20

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'

gajotnt
Posts: 46
Joined: Monday 06 February 2017 13:48
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Azores
Contact:

Re: Weather Underground failover suggestion

Post by gajotnt » Monday 22 January 2018 2:24

Would be really awesome to include in hardware page

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests