Rain prediction - weather underground
Moderator: leecollings
-
- Posts: 1
- Joined: Monday 16 April 2018 19:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain prediction - weather underground
Hello all,
Tried to use this script but is not functioning. Before debugging i would like to know if this script can be used in Domoticz stable 3.8153. If so can someone post the complete script. Thanx all. Greetings Jerry
Tried to use this script but is not functioning. Before debugging i would like to know if this script can be used in Domoticz stable 3.8153. If so can someone post the complete script. Thanx all. Greetings Jerry
-
- Posts: 247
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Rain prediction - weather underground
Should work.
Please post the error you get, and your script.
Please post the error you get, and your script.
-
- Posts: 7
- Joined: Wednesday 10 January 2018 19:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8153
- Location: Poland
- Contact:
Re: Rain prediction - weather underground
Hello
Very interesting project, but don't work with my domoticz. I put in a log and script, what could be a problem?
2018-05-25 08:40:01.448 Error: dzVents: Error: An error occured when calling event handler weather_rain
2018-05-25 08:40:01.448 Error: dzVents: Error: ...oticz/scripts/dzVents/generated_scripts/weather_rain.lua:23: attempt to index field 'hourly_forecast' (a nil value)
Very interesting project, but don't work with my domoticz. I put in a log and script, what could be a problem?
2018-05-25 08:40:01.448 Error: dzVents: Error: An error occured when calling event handler weather_rain
2018-05-25 08:40:01.448 Error: dzVents: Error: ...oticz/scripts/dzVents/generated_scripts/weather_rain.lua:23: attempt to index field 'hourly_forecast' (a nil value)
- Spoiler: show
-
- Posts: 247
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Rain prediction - weather underground
Hi arek156
If you use the countrycode + citycode there are 2 results. WUnderground shows the 2 posible locations and no weather results.
Because of that the data you try to get is non-existing(nil)
With these changes it should be ok:
Replace ' .. countryCode .. '/' .. city .. '.json'
with
zmw:00000.168.12490.json' so that the it will result in :
'curl http://api.wunderground.com/api/' .. wuAPIkey .. '/forecast/q/zmw:00000.168.12490.json'
On the other hand, dzvents has given us better ways since the original post (thank you Dannybloe!!)
I include an adapted version of your script in order to use asynchonous http requests --> so domoticz does not get blocked/lagged if there is an issue with getting the data.
For this your dzvents version must be higher than 2.3
If you use the countrycode + citycode there are 2 results. WUnderground shows the 2 posible locations and no weather results.
Because of that the data you try to get is non-existing(nil)
With these changes it should be ok:
Replace ' .. countryCode .. '/' .. city .. '.json'
with
zmw:00000.168.12490.json' so that the it will result in :
'curl http://api.wunderground.com/api/' .. wuAPIkey .. '/forecast/q/zmw:00000.168.12490.json'
On the other hand, dzvents has given us better ways since the original post (thank you Dannybloe!!)
I include an adapted version of your script in order to use asynchonous http requests --> so domoticz does not get blocked/lagged if there is an issue with getting the data.
For this your dzvents version must be higher than 2.3
Code: Select all
return {
on = {
timer = { 'every 15 minutes'},
httpResponses = { 'wUnderG' } -- matches callback string below
},
execute = function(domoticz, triggerItem)
-- Variables to customize ------------------------------------------------
local wuAPIkey = "xxxxxx" -- Your Weather Underground API Key
local rainswitch1 = domoticz.devices('Rain-1-hour') -- The switch for rain in the next hour
local rainswitch24 = domoticz.devices('Rain-today') -- the switch for rain Today
local popDay = domoticz.devices('popday') -- The percentage virtual sensor
------------------------------------------------------------------------------------ pop24
local wUrl = 'http://api.wunderground.com/api/' .. wuAPIkey .. '/forecast/hourly/q/zmw:00000.168.12490.json'
if (triggerItem.isTimer) then
domoticz.openURL({
url = wUrl,
method = 'GET',
callback = 'wUnderG'
})
elseif (triggerItem.isHTTPResponse) then
local response = triggerItem
if (response.ok and response.isJSON) then
--hear goes the check for the next hour
local pop1 = tonumber(response.json.hourly_forecast[1].pop)
popDay.updatePercentage(pop1)
if pop1 >= 30 then --switch will be turned on if probability is higher than 30%
rainswitch1.switchOn().checkFirst()
else
rainswitch1.switchOff().checkFirst()
end
--hear goes the check for today
local pop24 = tonumber(response.json.forecast.txt_forecast.forecastday[1].pop)
if pop24 >= 30 then
rainswitch24.switchOn().checkFirst()
else
rainswitch24.switchOff().checkFirst()
end
end
else
print('**wUnderG failed to fetch info')
end
end
}
Re: Rain prediction - weather underground
thanks, but how to find b]zmw:00000.168.12490.json'[/b] for my location...elmortero wrote: ↑Tuesday 29 May 2018 20:46 Hi arek156
If you use the countrycode + citycode there are 2 results. WUnderground shows the 2 posible locations and no weather results.
Because of that the data you try to get is non-existing(nil)
With these changes it should be ok:
Replace ' .. countryCode .. '/' .. city .. '.json'
with
zmw:00000.168.12490.json' so that the it will result in :
'curl http://api.wunderground.com/api/' .. wuAPIkey .. '/forecast/q/zmw:00000.168.12490.json'
On the other hand, dzvents has given us better ways since the original post (thank you Dannybloe!!)
I include an adapted version of your script in order to use asynchonous http requests --> so domoticz does not get blocked/lagged if there is an issue with getting the data.
For this your dzvents version must be higher than 2.3
-
- Posts: 247
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Rain prediction - weather underground
If you enter the URL you had in a browser you will get a JSON response.
In that there will be all the stations for PL/Poznan each with their zmw
The one I used in above script is the first one of the results
In that there will be all the stations for PL/Poznan each with their zmw
The one I used in above script is the first one of the results
-
- Posts: 7
- Joined: Wednesday 10 January 2018 19:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8153
- Location: Poland
- Contact:
Re: Rain prediction - weather underground
Hello
I'm using dzVents 2.2.0 and unfortunately adding a line of code does not help, I'm throwing in again the error that appeared in the log and the entire script. I will be grateful for your help
2018-05-30 17:47:03.139 Error: dzVents: Error: An error occured when calling event handler weather_rain
2018-05-30 17:47:03.139 Error: dzVents: Error: ...oticz/scripts/dzVents/generated_scripts/weather_rain.lua:25: attempt to index field 'hourly_forecast' (a nil value)
I'm using dzVents 2.2.0 and unfortunately adding a line of code does not help, I'm throwing in again the error that appeared in the log and the entire script. I will be grateful for your help

2018-05-30 17:47:03.139 Error: dzVents: Error: An error occured when calling event handler weather_rain
2018-05-30 17:47:03.139 Error: dzVents: Error: ...oticz/scripts/dzVents/generated_scripts/weather_rain.lua:25: attempt to index field 'hourly_forecast' (a nil value)
- Spoiler: show
-
- Posts: 247
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Rain prediction - weather underground
It is not working because in your URL you only get forecast but try to read hourly_forecast.
This works (tested it here). Also I joined the 2 URLs into one. (forecast and hourly)
This works (tested it here). Also I joined the 2 URLs into one. (forecast and hourly)
Code: Select all
return {
active = true,
on = {
timer = {'every 15 minutes'}
},
execute = function(domoticz)
-- Variables to customize ------------------------------------------------
local wuAPIkey = "xxxxxxxxx" -- Your Weather Underground API Key
local rainswitch1 = domoticz.devices('Rain-1-hour') -- The switch for rain in the next hour
local rainswitch24 = domoticz.devices('Rain-today') -- the switch for rain Today
local popDay = domoticz.devices('popday') -- The percentage virtual sensor
------------------------------------------------------------------------------------ pop24
--begin of the part to get hourly rain chances
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
local linker1 = tostring('curl http://api.wunderground.com/api/' .. wuAPIkey .. '/forecast/hourly/q/zmw:00000.168.12490.json')
local config=assert(io.popen(linker1))
local loc = config:read('*all')
config:close()
local jsonLocation = json:decode(loc)
local pop1 = tonumber(jsonLocation.hourly_forecast[1].pop)
popDay.updatePercentage(pop1)
if pop1 >= 30 and rainswitch1.state ~= 'On' --switch will be turned on if probability is higher than 30%
then rainswitch1.switchOn()
end
if pop1 < 30 and rainswitch1.state ~= 'Off' --if the probability is lower than 30% switch will be turned off
then rainswitch1.switchOff()
end
local pop24 = tonumber(jsonLocation.forecast.txt_forecast.forecastday[1].pop)
if pop24 >= 30 and rainswitch24.state ~= 'On'
then rainswitch24.switchOn()
end
if pop24 < 30 and rainswitch24.state ~= 'Off'
then rainswitch24.switchOff()
end
end
}
-
- Posts: 7
- Joined: Wednesday 10 January 2018 19:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8153
- Location: Poland
- Contact:
Re: Rain prediction - weather underground
Everything works, thanks to the elmortero.
Wysłane z Huawei P9
Wysłane z Huawei P9
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Rain prediction - weather underground
Getting this error in the events-box
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
-
- Posts: 247
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Rain prediction - weather underground
EdwinK, maybe also post the log where it tells more about the error.
Or tell what the balloon says when you move the mouse over the red cross.
Or tell what the balloon says when you move the mouse over the red cross.
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Rain prediction - weather underground
O.. I thought I had done that.
The error is: expected ']' near 'local'
(it's in the severe weather part of the script).
Because of the error I removed that part for now.
The error is: expected ']' near 'local'
(it's in the severe weather part of the script).
Because of the error I removed that part for now.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
- rbisschops
- Posts: 63
- Joined: Monday 12 May 2014 11:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2.2563
- Location: Schiedam, Netherlands
- Contact:
Re: Rain prediction - weather underground
Hi all, you can not get a new api key anymore for WU. Also the API description seems not visible anymore.Anyone has a link to the API description that works? Or maybee an ofline copy?
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
- rbisschops
- Posts: 63
- Joined: Monday 12 May 2014 11:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2.2563
- Location: Schiedam, Netherlands
- Contact:
Re: Rain prediction - weather underground
@elmortero: thanks, that helps. Script is working like a charm, it can use minor updates for version 2.4.X of dzVents
. Will test and submit my latest version here as well.

RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Rain prediction - weather underground
Now that the access to the Weather Underground API is almost over, does anyone know of a replacement for this?
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Rain prediction - weather underground
Too bad... I really need that rain-percentage for the sunscreen script (now it's time to check for those. It's starting to snow)
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
-
- Posts: 14
- Joined: Monday 07 January 2019 6:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Rain prediction - weather underground
I am using a script that is using the data from Darksky, maybe that is an option for you? You can make up to 1000 requests per day for free.
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Rain prediction - weather underground
Maybe if you are willing to share that script 

Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
Who is online
Users browsing this forum: No registered users and 1 guest