As the previous used weather alarm website http://www.meteoalarm.eu moved to a new European weather alarm site http://www.meteoalarm.org, also the RSS and ATOM feeds used by the python script, provided by @ycahome and all other solutions based on the old website, stopped working.
See: viewtopic.php?t=19519&start=100
As I used previously Node RED to parse the data and send it by MQTT to Domoticz, I created a new flow to do the same with the KNMI Website.
As the European website gets its data from the National Meteorological Bodies, I decided not to use the EU feeds, but the feed presented by KNMI.
So this post is only useful for those living in The Netherlands or those, who are interested in Dutch Weather alarms.
The Dutch website with the map can be visited at https://www.knmi.nl/nederland-nu/weer/w ... en/utrecht.
Insert your province, as Utrecht is the default,
The flow is presented in the picture below:
Some explanation of the working.
At the far left you will see an "Inject"node, which provides a 10 minute "tick". So the data to Domoticz is updated every 10 minutes.
It requests the data from the KNMI webfeed at https://cdn.knmi.nl/knmi/xml/rss/rss_KN ... wingen.xml
As this is XML data, it is sent through a XML node in order to convert it from a XML string to its JavaScript object representation.
This is used as input in a "Function" node. The Function takes care of the conversion to the Domoticz format.
The contents is as follows:
Code: Select all
var i;
var desc;
var mod_desc;
var al_txt;
var no_al_txt;
for (i = 0; i < msg.payload.rss.channel[0].item.length; i++) {
if (msg.payload.rss.channel[0].item[i].title[0] === "Waarschuwingen Gelderland") {
desc = msg.payload.rss.channel[0].item[i].description[0];
mod_desc = desc.replace(/(<([^>]+)>)/ig, '.'); // Modified description without HTML tags. Tags replaced by . (dot)
no_al_txt = mod_desc.substring((mod_desc.indexOf(".") + 2), (mod_desc.indexOf(".", (mod_desc.indexOf(".") + 1)) + 1));
al_txt = mod_desc.substring((mod_desc.indexOf("..") + 2), (mod_desc.indexOf("..", (mod_desc.indexOf("..") + 1)) + 1));
}
}
switch (desc.substring(5,desc.indexOf("."))) {
case "Groen":
msg.payload = { "command": "udevice", "idx": 395, "nvalue": 1, "svalue": no_al_txt };
break;
case "Geel" :
msg.payload = { "command": "udevice", "idx": 395, "nvalue": 2, "svalue": al_txt };
break;
case "Oranje":
msg.payload = { "command": "udevice", "idx": 395, "nvalue": 3, "svalue": al_txt };
break;
case "Rood":
msg.payload = { "command": "udevice", "idx": 395, "nvalue": 4, "svalue": al_txt };
break;
default:
msg.payload = { "command": "udevice", "idx": 395, "nvalue": 0, "svalue": "No Data available" };
break;
}
return msg
The user has to change line 7 and insert his/her own desired area (either a province or a coastal area).
It is followed by a "switch case" statement. The user has to replace the number after "idx" for his/her own IDX number of the Domoticz virtual "Alert" sensor.
Remark!
It has been tested with code green, code yellow and code orange.
However I did not see any code red, so we will have to wait in order to test.
If everything is finished you will see:
And hopefully very soon:
The complete flow, you will find below:
Code: Select all
[{"id":"6c6dcd5fb912ade7","type":"http request","z":"2275566b.451742","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://cdn.knmi.nl/knmi/xml/rss/rss_KNMIwaarschuwingen.xml","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":350,"y":460,"wires":[["74b6e54b66b937f2"]]},{"id":"206e54fce96bfcf8","type":"inject","z":"2275566b.451742","name":"10 Minute tick","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"600","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":460,"wires":[["6c6dcd5fb912ade7"]]},{"id":"74b6e54b66b937f2","type":"xml","z":"2275566b.451742","name":"","property":"payload","attr":"","chr":"","x":530,"y":460,"wires":[["f1c7fef468771b6a"]]},{"id":"f1c7fef468771b6a","type":"function","z":"2275566b.451742","name":"Function","func":"var i;\nvar desc;\nvar mod_desc;\nvar al_txt;\nvar no_al_txt;\nfor (i = 0; i < msg.payload.rss.channel[0].item.length; i++) {\n if (msg.payload.rss.channel[0].item[i].title[0] === \"Waarschuwingen Gelderland\") {\n desc = msg.payload.rss.channel[0].item[i].description[0];\n mod_desc = desc.replace(/(<([^>]+)>)/ig, '.'); // Modified description without HTML tags. Tags replaced by . (dot)\n no_al_txt = mod_desc.substring((mod_desc.indexOf(\".\") + 2), (mod_desc.indexOf(\".\", (mod_desc.indexOf(\".\") + 1)) + 1));\n al_txt = mod_desc.substring((mod_desc.indexOf(\"..\") + 2), (mod_desc.indexOf(\"..\", (mod_desc.indexOf(\"..\") + 1)) + 1));\n }\n}\nswitch (desc.substring(5,desc.indexOf(\".\"))) {\n case \"Groen\":\n msg.payload = { \"command\": \"udevice\", \"idx\": 395, \"nvalue\": 1, \"svalue\": no_al_txt };\n break;\n\n case \"Geel\" :\n msg.payload = { \"command\": \"udevice\", \"idx\": 395, \"nvalue\": 2, \"svalue\": al_txt };\n break;\n\n case \"Oranje\":\n msg.payload = { \"command\": \"udevice\", \"idx\": 395, \"nvalue\": 3, \"svalue\": al_txt };\n break;\n\n case \"Rood\":\n msg.payload = { \"command\": \"udevice\", \"idx\": 395, \"nvalue\": 4, \"svalue\": al_txt };\n break;\n\n default:\n msg.payload = { \"command\": \"udevice\", \"idx\": 395, \"nvalue\": 0, \"svalue\": \"No Data available\" };\n break;\n}\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":460,"wires":[["5b307902260f6b0a"]]},{"id":"5b307902260f6b0a","type":"mqtt out","z":"2275566b.451742","name":"Domoticz In","topic":"domoticz/in","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"2d06e6e96ce54335","x":890,"y":460,"wires":[]},{"id":"cae751d6c4047878","type":"comment","z":"2275566b.451742","name":"Meteoalarm KNMI","info":"","x":570,"y":400,"wires":[]},{"id":"2d06e6e96ce54335","type":"mqtt-broker","name":"Jonas_MQTT_Server","broker":"192.168.10.24","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]