I am able to read netatmo weather data collected by other netatmo stations in my region and also filter them, if they contain rain data. One of them in JSON format:
{"_id":"70:ee:50:28:00:00","place":{"location":[7.71234,48.51234],"timezone":"Europe/Paris","country":"FR","altitude":111,"city":"xxx","street":"Rue des xxxx"},"mark":12,"measures":{"02:00:00:28:ae:00":{"res":{"1598026423":[36.3,56]},"type":["temperature","humidity"]},"70:ee:50:28:a7:00":{"res":{"1598026467":[1017.3]},"type":["pressure"]},"05:00:00:04:9e:00":{"rain_60min":0,"rain_24h":0,"rain_live":0,"rain_timeutc":1598026455}},"modules":["05:00:00:04:9e:00","02:00:00:28:ae:00"],"module_types":{"05:00:00:04:9e:00":"NAModule3","02:00:00:28:ae:00":"NAModule1"}}
I just want to read the following data:
rain_60min
rain_24h
rain_live
but the measures "block" ist no array.
I have managed to use a function and generate the variable name as a string:
for(var i=0; i<msg.payload.modules.length; i++)
{
if (msg.payload.modules[i].substr(0,5) === "05:00" )
{
deb.payload = "msg.payload.measures."+msg.payload.modules[i]+".rain_60min"
}
}
= "msg.payload.measures.05:00:00:04:9e:00.rain_60min"
but how do I use this string to read the variable? I thought of a regular expression, which changes the 50:00:xx:xx:xx into a 50, so that I can use always the same variable name
msg.payload.measures.50.rain_60min
But where could I use a regular expression in Node-RED?