I’m new to HA and node red, and have very little experience in programming. For some godforsaken reason I decided that for my first real project I wanted to get an alert when a window is opened and rain is expected in the coming 12 hours.
I didn’t find a template for this, so I decided to try creating this in one red. After a lot of trial and error I have gotten to the point where I make an API request and end up with a bunch of data in an array.
Now I just need to handle the array, but I’m not sure how exactly to do this.
My flow looks like this:
[{"id":"ae7ea8bfe37d7db7","type":"http request","z":"e28683cf.db011","name":"Api request","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/18.067/lat/59.327/data.json","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":250,"y":180,"wires":[["99e9c87c.453f18"]]}]
(The coordinates in this flow just point to Stockholm, for sharing purposes)
The output data looks like this:
And this is the documentation for the API for SMHI (swedish weather institute):
https://opendata.smhi.se/apidocs/metfcst/parameters.html
So I´m able to successfully make an API request and get an object/array with values in it. The structure seems to be that timeseries[0] is the first hour, and under timeseries.parameters we have the data I want - pcat. This value seems to change from 0 (no rain) to 6 ( heavy rain) which is how I’ll evaluate if rain is expected.
At this stage, I want to do something like this:
> Get test.timeseries[0-11].parameters[1] # 12 hours worth of data
> Loop through timeseries 0-11 and check timeseries[0-11].parameters[1].value # check the mcat parameter
> If all parameters [1] == 0 then # No rain in the coming 12 hours, do nothing.
> Else ## Rain, proceed with the flow.
This is based on my understanding of the documentation that when rain is expected in any way pcat will change to value 1-6 depending on category.
I have no idea how to do this in practice, and hoping someone could help me finish this (to the point described above where I can continue the flow if rain is detected, I can keep experimenting with notifications if I can just get to that point).
Also, there are probably a lot of nonsense in my current NR flow, I won’t be able to answer why I did certain things because this was just a lot of trial and error from a year ago.