Hi all,
Since I cannot use the buienradar script
http://www.domoticz.com/forum/viewtopic ... +in#p38236 for my location because the Latitude cannot be lower than 44 I am trying to get my precipitation info from Weather Underground.
In plain Lua I managed to read 1 field (of two I want) based on this:
http://www.domoticz.com/wiki/Real-time_ ... structions
As I have all my other script in dzVents (I am a fan, what can I say

) I want this to work too.
The API url is
http://api.wunderground.com/api/YOURAPI ... cante.json and the output is like this:
- Spoiler: show
- {
"response": {
"version":"0.1",
"termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
"features": {
"conditions": 1
}
}
, "current_observation": {
"image": {
"url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png",
"title":"Weather Underground",
"link":"http://www.wunderground.com"
},
"display_location": {
"full":"Alicante, Spain",
"city":"Alicante",
"state":"A",
"state_name":"Spain",
"country":"SP",
"country_iso3166":"ES",
"zip":"00000",
"magic":"1",
"wmo":"08359",
"latitude":"38.xxxx",
"longitude":"-0.xxxx",
"elevation":"82.0"
},
"observation_location": {
"full":"Rabassa, Alacant, L\u0027ALACANTí",
"city":"Rabassa, Alacant",
"state":"L\u0027ALACANTí",
"country":"ES",
"country_iso3166":"ES",
"latitude":"38.372799",
"longitude":"-0.499062",
"elevation":"269 ft"
},
"estimated": {
},
"station_id":"ILALACAN3",
"observation_time":"Last Updated on December 28, 12:25 PM CET",
"observation_time_rfc822":"Wed, 28 Dec 2016 12:25:59 +0100",
"observation_epoch":"1482924359",
"local_time_rfc822":"Wed, 28 Dec 2016 12:26:21 +0100",
"local_epoch":"1482924381",
"local_tz_short":"CET",
"local_tz_long":"Europe/Madrid",
"local_tz_offset":"+0100",
"weather":"Mostly Cloudy",
"temperature_string":"60.1 F (15.6 C)",
"temp_f":60.1,
"temp_c":15.6,
"relative_humidity":"72%",
"wind_string":"Calm",
"wind_dir":"NNE",
"wind_degrees":15,
"wind_mph":0.0,
"wind_gust_mph":"3.0",
"wind_kph":0,
"wind_gust_kph":"4.8",
"pressure_mb":"1035",
"pressure_in":"30.57",
"pressure_trend":"0",
"dewpoint_string":"51 F (11 C)",
"dewpoint_f":51,
"dewpoint_c":11,
"heat_index_string":"NA",
"heat_index_f":"NA",
"heat_index_c":"NA",
"windchill_string":"NA",
"windchill_f":"NA",
"windchill_c":"NA",
"feelslike_string":"60.1 F (15.6 C)",
"feelslike_f":"60.1",
"feelslike_c":"15.6",
"visibility_mi":"6.2",
"visibility_km":"10.0",
"solarradiation":"--",
"UV":"1","precip_1hr_string":"0.00 in ( 0 mm)",
"precip_1hr_in":"0.00",
"precip_1hr_metric":" 0",
"precip_today_string":"0.00 in (0 mm)",
"precip_today_in":"0.00",
"precip_today_metric":"0",
"icon":"mostlycloudy",
"icon_url":"http://icons.wxug.com/i/c/k/mostlycloudy.gif",
"forecast_url":"http://www.wunderground.com/global/stations/08359.html",
"history_url":"http://www.wunderground.com/weatherstat ... =ILALACAN3",
"ob_url":"http://www.wunderground.com/cgi-bin/fin ... ,-0.499062",
"nowcast":""
}
}
and I want to read the data from the fields "precip_today_metric" and "precip_1hr_metric" to use to update 2 virtual rain devices.
I thought I was going the right way but not getting there
Code: Select all
return {
active = true,
on = {
['timer'] = 'every 5 minutes',
},
execute = function(domoticz)
----
local localhost = '127.0.0.1:8080'
local city = "Alicante" --city
local countryCode = "ES" --country
local rth = domoticz.devices['nexthourRain'] --my virtual rainsensor for hourly
local rtd = domoticz.devices['todayRain'] --my virtual rainsensor for hourly
local wuAPIkey = "XXXXXXX" -- WUnderground API Key
local latitude = 38.xxxx
local longitude = -0.4xxx
local altitude = 81
-[[ this is wereh the info is fetched from URL http://api.wunderground.com/api/'..wuAPIkey..'/conditions/q/'..countryCode..'/'..city..'.json'
local rainin1hour = this should contain the value of the field "precip_1hr_metric" from URL
domoticz.log('Expected rain in the next hour is ' .. rainin1hour, domoticz.LOG_INFO)
rth.updateRain(0, .. rainin1hour) --only updating the counter, not the rate
local raintoday = this should contain the value of the field "precip_today_metric" from URL
domoticz.log('Expected rain for today is ' .. raintoday, domoticz.LOG_INFO)
rtd.updateRain(0, .. raintoday) --only updating the counter, not the rate
--]]
----
end
}
Could someone help me?
Dannybloe, I think I am looking at you ..