Probability of rain HTML table to object?

Node-Red v3.0.2

I'm trying to make use of a website which provides a table with time and probability of rain in a 5 minute interval.

GOAL: being able to select a sing value from the array and if the value>70 open the awnings.

values are from 0-255 -- precipitation intensity = 10^((value-109)/32)

(https://gpsgadget.buienradar.nl/data/raintext/?lat=51.00&lon=4.00)

example of rain predicted:
buienradar-2

This is awesome to open the Awnings when rain is predicted.

But I have spent many hours trying to convert the table to something useful.
I managed to get the HTML content, resulting in a string but I only need an array of the 20 values without the time stamp.

any help would be so great!!

Maybe this will help

[{"id":"bd51408616dbe48c","type":"inject","z":"febe25a17f3bb5df","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":720,"y":740,"wires":[["1f375249a3f2ecd2"]]},{"id":"1f375249a3f2ecd2","type":"http request","z":"febe25a17f3bb5df","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://gpsgadget.buienradar.nl/data/raintext/?lat=51.00&lon=4.00","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"User-Agent","keyValue":"","valueType":"other","valueValue":"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"}],"x":870,"y":740,"wires":[["0fb22bcc67b4e698"]]},{"id":"0fb22bcc67b4e698","type":"csv","z":"febe25a17f3bb5df","name":"","sep":"|","hdrin":"","hdrout":"none","multi":"mult","ret":"\\n","temp":"rain,time","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":1010,"y":740,"wires":[["5f6c316fe3a8dd73","cb1a327d1601059d","c37fb9f45fa9ec34"]]},{"id":"5f6c316fe3a8dd73","type":"change","z":"febe25a17f3bb5df","name":"Output if time now is in the array of objects","rules":[{"t":"set","p":"payload","pt":"msg","to":"(\t    $time := $split($moment().tz(\"Europe/Brussels\").format(\"HH:mm\"), \":\");\t    $time := $time[0] & \":\" & $substring($time[1],0,1) & ($number($substring($time[1], 1)) < 5 ? \"0\" : \"5\");\t$$.payload[$.time = $time]\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":780,"wires":[["fda977eaceb6409b"]]},{"id":"cb1a327d1601059d","type":"change","z":"febe25a17f3bb5df","name":"output intensity levels","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.rain","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":680,"wires":[["c37fb9f45fa9ec34"]]},{"id":"c37fb9f45fa9ec34","type":"debug","z":"febe25a17f3bb5df","name":"debug 290","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1290,"y":680,"wires":[]},{"id":"4ed8cb18f7407789","type":"inject","z":"febe25a17f3bb5df","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"rain\":\"000\",\"time\":\"18:25\"},{\"rain\":\"000\",\"time\":\"18:30\"},{\"rain\":\"000\",\"time\":\"18:35\"},{\"rain\":\"000\",\"time\":\"19:40\"},{\"rain\":\"000\",\"time\":\"19:45\"},{\"rain\":\"000\",\"time\":\"19:50\"},{\"rain\":\"000\",\"time\":\"19:55\"},{\"rain\":\"000\",\"time\":\"20:00\"},{\"rain\":\"000\",\"time\":\"20:05\"},{\"rain\":\"000\",\"time\":\"20:10\"},{\"rain\":\"000\",\"time\":\"20:15\"},{\"rain\":\"000\",\"time\":\"20:20\"},{\"rain\":\"000\",\"time\":\"20:25\"},{\"rain\":\"000\",\"time\":\"20:30\"},{\"rain\":\"000\",\"time\":\"20:35\"},{\"rain\":\"000\",\"time\":\"20:40\"},{\"rain\":\"000\",\"time\":\"20:45\"},{\"rain\":\"000\",\"time\":\"20:50\"},{\"rain\":\"000\",\"time\":\"20:55\"},{\"rain\":\"000\",\"time\":\"21:00\"},{\"rain\":\"000\",\"time\":\"21:05\"},{\"rain\":\"000\",\"time\":\"21:10\"},{\"rain\":\"000\",\"time\":\"21:15\"},{\"rain\":\"000\",\"time\":\"21:20\"}]","payloadType":"json","x":870,"y":780,"wires":[["5f6c316fe3a8dd73"]]},{"id":"fda977eaceb6409b","type":"debug","z":"febe25a17f3bb5df","name":"debug 291","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1270,"y":820,"wires":[]}]

how to parse text using csv node. The how to check at time for intensity, and also how to output a array of levels.
[edit] Added timezone

1 Like

Thank you very much! I would not have found this solution...

I tried something else but I got stuck with a NaN error.

[{"id":"5935b2c29b205807","type":"debug","z":"df2a78d8c582aad3","name":"RESULT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":1760,"wires":[]},{"id":"fa80396d9baf4756","type":"inject","z":"df2a78d8c582aad3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":1700,"wires":[["a96cdc1189dc239e"]]},{"id":"a96cdc1189dc239e","type":"http request","z":"df2a78d8c582aad3","name":"Rain data","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://gpsgadget.buienradar.nl/data/raintext?lat=51.82&lon=4.65","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":240,"y":1760,"wires":[["abcc0dcced4f5079","65b4907a04fdd88f"]]},{"id":"abcc0dcced4f5079","type":"debug","z":"df2a78d8c582aad3","name":"RAW","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":450,"y":1700,"wires":[]},{"id":"65b4907a04fdd88f","type":"change","z":"df2a78d8c582aad3","name":"remove time","rules":[{"t":"change","p":"payload","pt":"msg","from":"\\|\\d\\d\\:\\d\\d","fromt":"re","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":1760,"wires":[["4d8c9efe6cd95d31","0228f1e5fb579550"]]},{"id":"0228f1e5fb579550","type":"function","z":"df2a78d8c582aad3","name":"make object","func":"var lines = msg.payload.split(\"\\n\");\nvar rain = [];\nvar rain_raw = [];\n\nfor (let index = 0; index < 20; index++) {\n   \n    rain[index] = { payload: lines[index] };\n    \n   //   rain[index] = parseInt(rain_raw);\n\n\n}\n// rain[0] = { payload: lines[0] };\n// rain[1] = { payload: lines[1] };\n// rain[2] = { payload: lines[2] };\n\n //rain[0] = \"000\";\n\n\nvar self_use = msg.payload[0].pwr - msg.payload[0].ps0\n\nmsg.payload = {\n    rain:\n        [\n            parseInt(rain[0], 10), rain[1], rain[2], rain[3], rain[4], rain[5], rain[6], rain[7],\n            rain[8], rain[9], rain[10], rain[11], rain[12], rain[13], rain[14],\n            rain[15], rain[16], rain[17], rain[18], rain[19],\n        ]\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":1760,"wires":[["5935b2c29b205807"]]},{"id":"4d8c9efe6cd95d31","type":"debug","z":"df2a78d8c582aad3","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":1700,"wires":[]}]

I finished my flow, iw works perfectly, many thanks to @E1cid !

for fellow enthusiasts in The Netherlands, here is my flow:
(edit "rain expected?" function variable msg.payload[12] to act on another time. '0' = now, '01' = now + 5,minutes, '12' = now+ 60 minutes etc.

[{"id":"506542bac0d4b639","type":"function","z":"faccc2278a3570b0","name":"format message","func":"msg.payload = \"Regen verwacht, markiezen omhoog\";\nmsg.topic = \"INFORMATIE:\"\nmsg.sound = \"bike\";\n//msg.retry = 31;\n//msg.expire = 1800;\nmsg.priority = 0;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1630,"y":390,"wires":[["3f17f8b6767eede9"]]},{"id":"3f17f8b6767eede9","type":"ntc-node-red-pushover-notifications","z":"faccc2278a3570b0","keys":"49f08967972432a7","title":"","name":"","x":1800,"y":390,"wires":[[]]},{"id":"9108933555252499","type":"function","z":"faccc2278a3570b0","name":"string array > number","func":"let stringArray = msg.payload;\nlet numberArray = stringArray.map(Number);\nmsg.payload = numberArray;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":450,"wires":[["9e3fb4b4611274ce","44cf4fd0cdf922b4"]]},{"id":"23fd63cf081edfa1","type":"inject","z":"faccc2278a3570b0","name":"check every 10min. (7-22u)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"*/10 7-21 * * *","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":310,"wires":[["3dd704ad3acf4122"]]},{"id":"3dd704ad3acf4122","type":"http request","z":"faccc2278a3570b0","name":"Buienradar HTTP request","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://gpsgadget.buienradar.nl/data/raintext/?lat=50.00&lon=3.00","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"User-Agent","keyValue":"","valueType":"other","valueValue":"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"}],"x":210,"y":390,"wires":[["1cf659edde4a4568"]]},{"id":"24cf0dcf3846bc33","type":"inject","z":"faccc2278a3570b0","name":"send test message","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":1707,"y":252,"wires":[["cef4e89944793caa"]]},{"id":"e973f5fc49f241f5","type":"trigger","z":"faccc2278a3570b0","name":"send twice with delay","op1":"","op2":"","op1type":"pay","op2type":"payl","duration":"2","extend":false,"overrideDelay":false,"units":"min","reset":"false","bytopic":"all","topic":"topic","outputs":1,"x":1340,"y":450,"wires":[["4de7efe3351a94aa","8e7b3990bfec0193"]],"info":"NOTE: sending the 'original object' does not output anything..."},{"id":"1cf659edde4a4568","type":"csv","z":"faccc2278a3570b0","name":"html data > CSV","sep":"|","hdrin":"","hdrout":"none","multi":"mult","ret":"\\n","temp":"rain,time","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":180,"y":450,"wires":[["84aaf0b2fa82a364","405172543e631fb3"]]},{"id":"84aaf0b2fa82a364","type":"change","z":"faccc2278a3570b0","name":"filter rain data","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.rain","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":450,"wires":[["9108933555252499","c431b68cb1040c2e"]]},{"id":"405172543e631fb3","type":"debug","z":"faccc2278a3570b0","name":"html data > CSV","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":180,"y":510,"wires":[]},{"id":"f17e0b44eedbfe53","type":"comment","z":"faccc2278a3570b0","name":"UITLEG","info":"Dit is een flow om een actie uit te voeren wanneer er regen wordt verwacht.\n\nHiervoor gebruik ik een Buienradar gadget: \nhttps://www.buienradar.nl/overbuienradar/gratis-weerdata\n\n\nBuienradar widget\n(1.0) Neerslagdata op basis van coördinaten\n\nOp basis van de door u gewenste coördinaten (latitude en longitude) kunt u de neerslag\ntot twee uur vooruit ophalen in tekstvorm. De data wordt iedere 5 minuten geüpdatet. \nOp deze pagina kunt u de neerslag in tekst vinden. \n\nDe waarde 0 geeft geen neerslag aan (droog), \nde waarde 255 geeft zware neerslag aan. \n\nGebruik de volgende formule voor het omrekenen naar de \nneerslagintensiteit in de eenheid millimeter per uur (mm/u):\n\nNeerslagintensiteit = 10^((waarde-109)/32)\n\nTer controle: een waarde van 77 is gelijk aan een neerslagintensiteit van 0,1 mm/u. \n\n[Update 20 juli 2017]: Afgelopen dagen gaf deze widget geen data door. \nDit is inmiddels verbeterd. \nGebruik hiervoor de url https://gps.buienradar.nl/getrr.php?lat=51&lon=3 \nen niet de onderliggende url. \n\n","x":510,"y":250,"wires":[]},{"id":"75c96a3f0e1dd7cf","type":"inject","z":"faccc2278a3570b0","name":"test: value = 88 (RAIN)","props":[{"p":"payload[12]","v":"88","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":660,"y":310,"wires":[["9e3fb4b4611274ce"]]},{"id":"4de7efe3351a94aa","type":"debug","z":"faccc2278a3570b0","name":"send twice with delay","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1340,"y":510,"wires":[]},{"id":"9894a539fa408d94","type":"inject","z":"faccc2278a3570b0","name":"test: value = 0 (NO RAIN)","props":[{"p":"payload[12]","v":"0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":670,"y":350,"wires":[["9e3fb4b4611274ce"]]},{"id":"9e3fb4b4611274ce","type":"function","z":"faccc2278a3570b0","name":"rain expected?","func":"var input = msg.payload[12];\n\n// Buienradar data heeft een waarde van 0 - 255\n// 77 bijv. is gelijk aan 0.1mm per uur\n\n// bepaal hieronder bij welke waarde de zonwering\n// omhoog moet gaan\nvar drempelwaarde = 77;\n\n// controleer de drempelwaarde\nif (input >= drempelwaarde) {\n    msg.payload = true;\n}\nelse {\n    msg.payload = false;\n}\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":450,"wires":[["2f8ee8b7309e77b3","1c1defaa05c38bca"]]},{"id":"2f8ee8b7309e77b3","type":"rbe","z":"faccc2278a3570b0","name":"pass if changed","func":"rbe","gap":"","start":"","inout":"out","septopics":false,"property":"payload","topi":"topic","x":1100,"y":450,"wires":[["e973f5fc49f241f5","8dc76ee4573745ff","cef4e89944793caa"]]},{"id":"8dc76ee4573745ff","type":"debug","z":"faccc2278a3570b0","name":"pass if changed","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1100,"y":510,"wires":[]},{"id":"1c1defaa05c38bca","type":"debug","z":"faccc2278a3570b0","name":"rain expected?","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":880,"y":510,"wires":[]},{"id":"1484cda8584ca9f3","type":"comment","z":"faccc2278a3570b0","name":"send OPEN command to awnings","info":"","x":1720,"y":450,"wires":[]},{"id":"cef4e89944793caa","type":"switch","z":"faccc2278a3570b0","name":"pushover: only trigger when true","property":"payload","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":1370,"y":390,"wires":[["506542bac0d4b639"]]},{"id":"d55afbdadbc07c0c","type":"comment","z":"faccc2278a3570b0","name":"RAIN? send message","info":"","x":1647,"y":342,"wires":[]},{"id":"c431b68cb1040c2e","type":"debug","z":"faccc2278a3570b0","name":"filter rain data","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":400,"y":510,"wires":[]},{"id":"8e7b3990bfec0193","type":"link out","z":"faccc2278a3570b0","name":"OPEN AWNING","mode":"link","links":["b320318a8f7d3208"],"x":1555,"y":450,"wires":[]},{"id":"c95f394dd6a7191a","type":"comment","z":"faccc2278a3570b0","name":"Check for rain using the Buienradar Gadget","info":"","x":270,"y":250,"wires":[]},{"id":"44cf4fd0cdf922b4","type":"debug","z":"faccc2278a3570b0","name":"string array > number","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":510,"wires":[]},{"id":"49f08967972432a7","type":"ntc-node-red-pushover-keys","name":"Node-Red"}]
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.