Trying to retrieve weather data from the openweather api. The call succeeds, getting the data also succeeds when retrieving e.g temp. But when i try to retrieve the data from rain.1h i don’t get the data. With the next flow it succeeds, but not with homeyscript. Anyone an idea?
Weather.hourly[4].rain[uur]
uur
is a variable, if you use .uur
it’s taken as a literal (so it would match an object looking like { "rain" : { "uur" : … } }
)
Ok will try. Strange thing was that I had to use a variable. Just adding .1h did give an error. So made a variable: uur = ‘1h’. Any idea why i got an error?
Probably because you used .rain.1h
, which is valid JSONPath but not valid JavaScript. Instead, you should use .rain['1h']
.
Still learning, learning learning.
Pff as a Noob it is quite a steep learning proces. Can’t count all the mistakes I already made. Including losing a total script after a network error in Homeyscript👎🏻. Thx Robert for all your help.
Maybe there’s a good reason to use Homeyscript to get weater data, but do you know there’s an openweather Homey app? you could install that and get the info there, either from normal flow cards or reading the info from Homeyscript.
Yep, with the api call I can get an hourly rain forecast for the next 24 hours. I use it for automatically watering my garden in summertime. Also trying to delete some apps that way, uv forecast etc etc
It worked, but this gives another problem. rain.’1h’ is only shown in the json file when there will be rain. When there will be no rain, rain.’1h’ will not be available in the json file. In that case i get an error “ Cannot read property ‘1h’ of undefined, and my script stops.
How can i handel that if there is no rain my variable will be 0.00 and when there is rain my variable will get that information
Rain1uur = Weather.hourly[1].rain ? Weather.hourly[1].rain['1h'] : 0;
That simple, googled everything and tried every solution, non worked. Will try it tonight. Thx:beers:
Trying to get this working for both temperature and rain.
When I add temp into a variable it works but when I try to get rain.1h into this same variable it doesn,t work. When instead of [variable] ad +variable it works to get the rain data but in that case temperature gets 'undefined. Is there a way to get both data with the same variables?
This does not work for rain, but works for temperature
Naamloos1|690x460
This works for rain
You can’t access multiple levels of an object using a single variable; temperature
works because it’s a scalar (numerical) value inside the hourly
object, but rain
is an object (i.e. it introduces a deeper level).
Ok thx, unfortunately. Searched it all and couldn’t find it either.