Sanity check for NWS weather alert Flow

I had this working but recent weather events weren't popping up as alerts on my dash. When I went to investigate, I am sure I broke something, then fixed it, and broke it again. I could use a sanity check.

The flow is very simple: Go to NWS alerts.weather.gov page for a county, check to see if there is a standard "no alerts right now" message (which only appears when there are no alerts, obviously), does a check to see if a TRUE or FALSE is passed -- TRUE means no alert and nothing pops up, FALSE means there is an alert, and the payload should be displayed as an alert.

This has been devlishly difficult to test as I can only really test it when there are real alerts. Any help or advice would be appreciated, I tried to make the alert flow as simple as possible but still managed to bang it up somehow.

[{"id":"1279864a.6f913a","type":"tab","label":"Weather Alert Flow","disabled":false,"info":"This flow looks for current weather alerts.  By default it looks for tornado or thunderstorm, but it can be changed to look for hurricane, flood, or other alert."},{"id":"d4bb8926.65fd68","type":"inject","z":"1279864a.6f913a","name":"","topic":"","payload":"","payloadType":"date","repeat":"3600","crontab":"","once":true,"onceDelay":0.1,"x":150,"y":40,"wires":[["f6fe9d7c.fb7ad"]]},{"id":"cca7689b.bafc68","type":"http request","z":"1279864a.6f913a","name":"NWS Alert Feed","method":"GET","ret":"txt","paytoqs":false,"url":"https://alerts.weather.gov/cap/wwaatmget.php?x=HIC003&y=1","tls":"","persist":false,"proxy":"","authType":"","x":260,"y":140,"wires":[["4d989955.e8e8d8"]]},{"id":"f6fe9d7c.fb7ad","type":"function","z":"1279864a.6f913a","name":"Set User Agent String","func":"\nmsg.headers = {};\nmsg.headers['user-agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36';\nreturn msg;","outputs":1,"noerr":0,"x":180,"y":100,"wires":[["cca7689b.bafc68"]]},{"id":"d1464890.346298","type":"comment","z":"1279864a.6f913a","name":"Set feed to be your county alerts feed.","info":"Use the NWS alert rss feed for your state from this list.\n\nhttps://alerts.weather.gov/","x":170,"y":180,"wires":[]},{"id":"f20b3f92.7a35a","type":"ui_toast","z":"1279864a.6f913a","position":"dialog","displayTime":"5","highlight":"red","sendall":true,"outputs":1,"ok":"OK","cancel":"","raw":true,"topic":"ALERT","name":"nws alert","x":680,"y":140,"wires":[[]]},{"id":"5358ae02.bb6a1","type":"switch","z":"1279864a.6f913a","name":"alert choice","property":"payload[1]","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":590,"y":200,"wires":[[],["f20b3f92.7a35a"]]},{"id":"bb5848c4.39b7d8","type":"debug","z":"1279864a.6f913a","name":"check","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload[1]","targetType":"msg","x":590,"y":80,"wires":[]},{"id":"8d613c6f.a190e","type":"comment","z":"1279864a.6f913a","name":"Alert Feed Address","info":"The check explicitly looks for \"There are no active watches, warnings or advisories\" in the second TITLE tag of the xml return and does a check on it.  If FALSE, nothing pops up -- if TRUE, you get the verbose weather alert.\n\n\nCounty Alert Feed\nhttps://alerts.weather.gov/cap/wwaatmget.php?x=HIC003&y=1","x":430,"y":240,"wires":[]},{"id":"22347a4e.96aa16","type":"comment","z":"1279864a.6f913a","name":"Alert text still needs formatting","info":"","x":1030,"y":280,"wires":[]},{"id":"19a61356.77355d","type":"string","z":"1279864a.6f913a","name":"active?","methods":[{"name":"contains","params":[{"type":"str","value":"\"There are no active watches, warnings or advisories\""}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":500,"y":140,"wires":[["5358ae02.bb6a1"]]},{"id":"4d989955.e8e8d8","type":"html","z":"1279864a.6f913a","name":"","property":"payload","outproperty":"payload","tag":"title","ret":"text","as":"single","x":410,"y":200,"wires":[["19a61356.77355d","bb5848c4.39b7d8"]]},{"id":"b2461177.e877d","type":"play audio","z":"1279864a.6f913a","name":"","voice":"43","x":750,"y":20,"wires":[]}]

You appear to have posted only the request node, not the rest of the flow. Also please read this for how to share your flow here so that it is importable.

Thank you. I went to that link and followed the info. Instructions don't work for chromebook for some reason, so I did it manually. Great start.

The HTML node outputs the right alert when it is available, but I can't get it to pass anything other than FLASE to the alert, when it used to pass the entire alert. It's something simple, but not for me right now. Perhaps I am handling the array wrong, but I usually had success spitting out message[1] since that's where the actual alert is.

[{"id":"1279864a.6f913a","type":"tab","label":"Weather Alert Flow","disabled":false,"info":"This flow looks for current weather alerts.  By default it looks for tornado or thunderstorm, but it can be changed to look for hurricane, flood, or other alert."},{"id":"d4bb8926.65fd68","type":"inject","z":"1279864a.6f913a","name":"","topic":"","payload":"","payloadType":"date","repeat":"3600","crontab":"","once":true,"onceDelay":0.1,"x":150,"y":40,"wires":[["f6fe9d7c.fb7ad"]]},{"id":"cca7689b.bafc68","type":"http request","z":"1279864a.6f913a","name":"NWS Alert Feed","method":"GET","ret":"txt","paytoqs":false,"url":"https://alerts.weather.gov/cap/wwaatmget.php?x=HIC003&y=1","tls":"","persist":false,"proxy":"","authType":"","x":260,"y":140,"wires":[["4d989955.e8e8d8"]]},{"id":"f6fe9d7c.fb7ad","type":"function","z":"1279864a.6f913a","name":"Set User Agent String","func":"\nmsg.headers = {};\nmsg.headers['user-agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36';\nreturn msg;","outputs":1,"noerr":0,"x":180,"y":100,"wires":[["cca7689b.bafc68"]]},{"id":"d1464890.346298","type":"comment","z":"1279864a.6f913a","name":"Set feed to be your county alerts feed.","info":"Use the NWS alert rss feed for your state from this list.\n\nhttps://alerts.weather.gov/","x":170,"y":180,"wires":[]},{"id":"f20b3f92.7a35a","type":"ui_toast","z":"1279864a.6f913a","position":"dialog","displayTime":"5","highlight":"red","sendall":true,"outputs":1,"ok":"OK","cancel":"","raw":true,"topic":"ALERT","name":"nws alert","x":680,"y":140,"wires":[[]]},{"id":"5358ae02.bb6a1","type":"switch","z":"1279864a.6f913a","name":"alert choice","property":"payload[1]","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":590,"y":200,"wires":[[],["f20b3f92.7a35a"]]},{"id":"bb5848c4.39b7d8","type":"debug","z":"1279864a.6f913a","name":"check","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload[1]","targetType":"msg","x":590,"y":80,"wires":[]},{"id":"8d613c6f.a190e","type":"comment","z":"1279864a.6f913a","name":"Alert Feed Address","info":"The check explicitly looks for \"There are no active watches, warnings or advisories\" in the second TITLE tag of the xml return and does a check on it.  If FALSE, nothing pops up -- if TRUE, you get the verbose weather alert.\n\n\nCounty Alert Feed\nhttps://alerts.weather.gov/cap/wwaatmget.php?x=HIC003&y=1","x":430,"y":240,"wires":[]},{"id":"22347a4e.96aa16","type":"comment","z":"1279864a.6f913a","name":"Alert text still needs formatting","info":"","x":1030,"y":280,"wires":[]},{"id":"19a61356.77355d","type":"string","z":"1279864a.6f913a","name":"active?","methods":[{"name":"contains","params":[{"type":"str","value":"\"There are no active watches, warnings or advisories\""}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":500,"y":140,"wires":[["5358ae02.bb6a1"]]},{"id":"4d989955.e8e8d8","type":"html","z":"1279864a.6f913a","name":"","property":"payload","outproperty":"payload","tag":"title","ret":"text","as":"single","x":410,"y":200,"wires":[["19a61356.77355d","bb5848c4.39b7d8"]]},{"id":"b2461177.e877d","type":"play audio","z":"1279864a.6f913a","name":"","voice":"43","x":750,"y":20,"wires":[]}]

What type is the string node? node-red-contrib-something probably.
I notice that the information you are want is in msg.payload[1], have you allowed for that in the string node, also the Switch node after the string node is testing msg.payload[1], is that correct?

Interestingly that is the second report of problems with Chrome and those instructions. You should find that if you click the button first, then paste the text in then is should work ok.

@colin, the flow inspector shows it to be node-red-contrib-string

Thanks for the reply. So I found that if I checked the entire msg.payload up front, it used to solve the problem of an alert popping up no matter what. Then after passing that check, I want the msg.payload[1] to be actually in the alert. It's how I thought I handled the false positive by inverting the logic. If that makes sense, since it only is FALSE if there is an alert.

I'm at a loss as to why nothing is popping up when there is an alert now. Nothing seems to have changed on the NSW front.

When debugging the first thing to do is to find out which node is not doing what you expect, so add a debug node showing what is coming out of the string node.

You can test it without waiting for an alert by using an Inject and a Change node to build a test message to pass in to the html node (or the string node).

In fact, having installed node-red-contrib-string I can see that you are testing msg.payload, but in fact the string you want to test is in msg.payload[1]. So that is not going to work.

Also note that you can use the builtin Switch node to do the test, you don't need to use a contrib node.

As it is now, I get an udefined return from the text node whih looks for "There are no active watches, warnings or advisories"

I am using both, because I need to check for the presence of the "no alert" text and then use the switch node to pass along a real alert if it is there. Are you saying I can remove the text node and just use the switch mode? I think the main confusion is that there isn't even a payload[1] unless there is an alert.

However, setting everything up to just look for payload[1] doesn't work. I recall going in and switching them all to [1] and I was left with no output.

That is because it is expecting msg.payload to be a string, but it is an array. The easiest fix is probably to put a change node before the string node, to move msg.payload[1] into msg.payload.

Yes, The switch node can look for a string in msg.payload[1].
Also, when I run your flow I see, in msg.payload[1] "There are no active watches, warnings or advisories"

I get that from time to time too when I am fiddling with the flow. Still not working properly for me, I must be taking the wrong approach.

Post what you have now and I will take a look. You weren't far off before.

I appreciate it. Quite frustrated at this point. I used the new method of hitting the formatting button first, then pasting this time.

[
    {
        "id": "1279864a.6f913a",
        "type": "tab",
        "label": "Weather Alert Flow",
        "disabled": false,
        "info": "This flow looks for current weather alerts."
    },
    {
        "id": "d4bb8926.65fd68",
        "type": "inject",
        "z": "1279864a.6f913a",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "3600",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "x": 150,
        "y": 40,
        "wires": [
            [
                "f6fe9d7c.fb7ad"
            ]
        ]
    },
    {
        "id": "cca7689b.bafc68",
        "type": "http request",
        "z": "1279864a.6f913a",
        "name": "NWS Alert Feed",
        "method": "GET",
        "ret": "txt",
        "paytoqs": false,
        "url": "https://alerts.weather.gov/cap/wwaatmget.php?x=HIC003&y=1",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 260,
        "y": 160,
        "wires": [
            [
                "4d989955.e8e8d8"
            ]
        ]
    },
    {
        "id": "f6fe9d7c.fb7ad",
        "type": "function",
        "z": "1279864a.6f913a",
        "name": "Set User Agent String",
        "func": "\nmsg.headers = {};\nmsg.headers['user-agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36';\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 180,
        "y": 100,
        "wires": [
            [
                "cca7689b.bafc68"
            ]
        ]
    },
    {
        "id": "d1464890.346298",
        "type": "comment",
        "z": "1279864a.6f913a",
        "name": "Set feed to be your county alerts feed.",
        "info": "Use the NWS alert rss feed for your state from this list.\n\nhttps://alerts.weather.gov/",
        "x": 190,
        "y": 200,
        "wires": []
    },
    {
        "id": "f20b3f92.7a35a",
        "type": "ui_toast",
        "z": "1279864a.6f913a",
        "position": "dialog",
        "displayTime": "5",
        "highlight": "red",
        "sendall": true,
        "outputs": 1,
        "ok": "OK",
        "cancel": "",
        "raw": false,
        "topic": "ALERT",
        "name": "nws alert",
        "x": 640,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "5358ae02.bb6a1",
        "type": "switch",
        "z": "1279864a.6f913a",
        "name": "alert choice",
        "property": "payload[1]",
        "propertyType": "msg",
        "rules": [
            {
                "t": "false"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 530,
        "y": 100,
        "wires": [
            [],
            [
                "f20b3f92.7a35a"
            ]
        ]
    },
    {
        "id": "bb5848c4.39b7d8",
        "type": "debug",
        "z": "1279864a.6f913a",
        "name": "check",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload[1]",
        "targetType": "msg",
        "x": 650,
        "y": 40,
        "wires": []
    },
    {
        "id": "8d613c6f.a190e",
        "type": "comment",
        "z": "1279864a.6f913a",
        "name": "Alert Feed Address",
        "info": "The check explicitly looks for \"There are no active watches, warnings or advisories\" in the second TITLE tag of the xml return and does a check on it.  If FALSE, nothing pops up -- if TRUE, you get the verbose weather alert.\n\n\nCounty Alert Feed\nhttps://alerts.weather.gov/cap/wwaatmget.php?x=PAC029&y=1",
        "x": 430,
        "y": 240,
        "wires": []
    },
    {
        "id": "22347a4e.96aa16",
        "type": "comment",
        "z": "1279864a.6f913a",
        "name": "Alert text still needs formatting",
        "info": "",
        "x": 1030,
        "y": 280,
        "wires": []
    },
    {
        "id": "4d989955.e8e8d8",
        "type": "html",
        "z": "1279864a.6f913a",
        "name": "",
        "property": "payload",
        "outproperty": "payload",
        "tag": "title",
        "ret": "text",
        "as": "multi",
        "x": 410,
        "y": 200,
        "wires": [
            [
                "884c75fb.36f078",
                "bb5848c4.39b7d8"
            ]
        ]
    },
    {
        "id": "884c75fb.36f078",
        "type": "change",
        "z": "1279864a.6f913a",
        "name": "",
        "rules": [
            {
                "t": "move",
                "p": "payload[1]",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "There are no active watches, warnings or advisories",
                "fromt": "str",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 420,
        "y": 40,
        "wires": [
            [
                "5358ae02.bb6a1"
            ]
        ]
    }
]

A minor point, when exporting the flow it is better to select Compact at the bottom of the window, so it appears on one line.

You had changed the html select node to output multiple messages instead of an array, the rest of the flow assumes it is an array.
In the final switch node you were testing msg.payload[1] but in the change node you set msg.payload true or false.
You had the debug node set to show msg.payload[1] which generally isn't a good idea when debugging as you want to see what is in the payload, not make assumptions about whether the payload is an array or not. That was probably confusing you.
The technique I used to debug is to start at the beginning with a debug node on the output of a node. Check that node is sending what you expect, then move on to the next node and check that, and so on.

Try this

[{"id":"ea59bf41.170328","type":"inject","z":"18c3846b.fec5fc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":40,"wires":[["27559896.19c0c"]]},{"id":"b49256dc.82eea","type":"http request","z":"18c3846b.fec5fc","name":"NWS Alert Feed","method":"GET","ret":"txt","paytoqs":false,"url":"https://alerts.weather.gov/cap/wwaatmget.php?x=HIC003&y=1","tls":"","persist":false,"proxy":"","authType":"","x":260,"y":160,"wires":[["3935b972.f4bed6"]]},{"id":"27559896.19c0c","type":"function","z":"18c3846b.fec5fc","name":"Set User Agent String","func":"\nmsg.headers = {};\nmsg.headers['user-agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36';\nreturn msg;","outputs":1,"noerr":0,"x":180,"y":100,"wires":[["b49256dc.82eea"]]},{"id":"d4e7ef7c.1776f","type":"comment","z":"18c3846b.fec5fc","name":"Set feed to be your county alerts feed.","info":"Use the NWS alert rss feed for your state from this list.\n\nhttps://alerts.weather.gov/","x":190,"y":200,"wires":[]},{"id":"174bc408.d94a74","type":"ui_toast","z":"18c3846b.fec5fc","position":"dialog","displayTime":"5","highlight":"red","sendall":true,"outputs":1,"ok":"OK","cancel":"","raw":false,"topic":"ALERT","name":"nws alert","x":640,"y":160,"wires":[[]]},{"id":"482c4ac.2c441b4","type":"switch","z":"18c3846b.fec5fc","name":"alert choice","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":530,"y":100,"wires":[["dfbc9986.7a50a"],["174bc408.d94a74"]]},{"id":"dfbc9986.7a50a","type":"debug","z":"18c3846b.fec5fc","name":"check","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":40,"wires":[]},{"id":"422f2eb9.6cd15","type":"comment","z":"18c3846b.fec5fc","name":"Alert Feed Address","info":"The check explicitly looks for \"There are no active watches, warnings or advisories\" in the second TITLE tag of the xml return and does a check on it.  If FALSE, nothing pops up -- if TRUE, you get the verbose weather alert.\n\n\nCounty Alert Feed\nhttps://alerts.weather.gov/cap/wwaatmget.php?x=PAC029&y=1","x":430,"y":240,"wires":[]},{"id":"3935b972.f4bed6","type":"html","z":"18c3846b.fec5fc","name":"","property":"payload","outproperty":"payload","tag":"title","ret":"text","as":"single","x":410,"y":200,"wires":[["c40471aa.4c3b2"]]},{"id":"c40471aa.4c3b2","type":"change","z":"18c3846b.fec5fc","name":"","rules":[{"t":"move","p":"payload[1]","pt":"msg","to":"payload","tot":"msg"},{"t":"change","p":"payload","pt":"msg","from":"There are no active watches, warnings or advisories","fromt":"str","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":40,"wires":[["482c4ac.2c441b4"]]}]

Thanks for the help. I usually move that debug node around to see what's what.

Right now as it is, I get the FALSE output -- which would seem right, however the alert pops up with a random H or U now, which makes no sense to me.

If I had the ability right now, I would build a little node that would take your county's NWS feed address as input an pop up an alert if there was one. With so many weather dashboards being built, I was surprised not to find one myself. And so here I am...

edit: It seems that I was still checking my pasted version of the alert, and not the one you offered. So no random characters this go around. I am getting proper output from the boolean with no alerts, but still have to find a way to inject a simulated alert payload. Ongoing...

It depends how far back you want to do the inject. It would be easy enough to inject it after the html select node.

If there is an alert isn't it going to send multiple events? You can put an RBE node in the path to stop that if you need to.

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