20.10.2021, 19:23
Hi @all,
due to the great hints of you guys I got the first script running for the current temperature and humidity value.
Now I want to get also the current weather description and the daily forecast for temperature min and max.
Unfortunately this values are not working. In the script log I see the following message:
Here is my actual script:
Do you have an idea what might be wrong?
Many thanks for your help!
Best Regards
Steffen
due to the great hints of you guys I got the first script running for the current temperature and humidity value.
Now I want to get also the current weather description and the daily forecast for temperature min and max.
Unfortunately this values are not working. In the script log I see the following message:
Code:
User script:39: attempt to index field 'temp' (a nil value)
stack traceback:
Here is my actual script:
Code:
require('json')
http = require('socket.http')
appid = 'XXX'
lat = 'XXX'
lon ='XXX'
lang = 'en'
units = 'metric'
url = 'http://api.openweathermap.org/data/2.5/onecall?lat=%s&lon=%s&units=%s&lang=%s&appid=%s'
url = string.format(url, lat, lon, units, lang, appid)
res, code, headers, status = http.request(url)
log (code, status, headers)
data = json.pdecode(res)
--Fault messages:
if not data then
alert('Error converting data')
return
end
if not res then
alert('Error collecting data')
return
end
current = data.current
daily = data.daily
-- current temperature
grp.write('41/1/1', current.temp)
-- current Weather condition
grp.write('41/1/2', current.weather.description)
--current Humidity
grp.write('41/1/3', current.humidity)
--daily forecast Temperature min
grp.write('41/1/4', daily.temp.min)
--daily forecast Temperature max
grp.write('41/1/5', daily.temp.max)
Do you have an idea what might be wrong?
Many thanks for your help!
Best Regards
Steffen