Severe Weather Alerts from the US National Weather Service

I’ve just officially released the updated version of the integration.

I’ve also updated the example automations, etc package and the dashboard code to use the new alert attribute structure.

I’ve tested it pretty extensively and I’m fairly sure everything works but I may have missed something so of course let me know if there are issues.

As far as the automations are concerned I’m not sure why but I’ve always made the assumption in the past that any new alert would be at the top of alerts list (index 0) but during my testing I’m not 100% sure that’s correct.

So I’ve changed the automations to send notifications and announcements about all alerts. Obviously it would get annoying to hear the same alerts over and over so I’ve built-in a history of all notified & announced alerts and if any “new” alert is already in those lists the alert gets ignored in the notifications and announcements.

Hopefully it will be more reliable in sending notifications of important info without any false repeat alerts.

6 Likes

Since it’s storm season here in AZ, I’ve been able to confirm the first entry is the latest NWS alert.

The dict for Alerts does make things a bit easier to parse out too. :beers:

1 Like

I figured as much but the issue I seemed to run into in testing is if several alerts were issued at the same time then you couldn’t always ensure the first one would be the worst one.

Example, I had for testing a zone in California that had more than one of each heat advisories, heat watches, air quality alerts, then later severe thunderstorm watches and warnings - there were 12 active alerts at one time. and in my subjective opinion the thunderstorm warnings were more important than the thunderstorm watches which were more important than the heat advisories were more important than the air quality alerts but those were all intermingled amongst each other.

So even if (as we assumed) that the newest was the first in the list if we limit the announcement to the first then we might still miss something more important that might have gotten issued essentially simultaneously with something less important and it ends up being further down.

That’s why I use the queued mode for my alerts so they all get in.

1 Like

Here is an example of the state changes over the last week.

image

The jumps from 2 to 3 to 4 to 5 etc might be able to be handled ok by a queued automation. The jump directly 2 to 5 or from 6 to 8 couldn’t be.

And TBH, I’m pretty sure some of those 1 step state changes were when a few old alerts expired and they were replaced en masse by their newly sent replacements. so 4 might have all expired at once then 5 might have been sent at once.

That assumption is supported by me getting multiple persistent notifications and mobile notifications all at once for based on each alerts unique ID.

Of course for a “normal” severe weather event it’s not likely to get more than one alert at a time so the queued method would be perfectly fine. But unfortunately the times we are in now are getting less “normal” all the time. :frowning_face:

1 Like

I know you deleted your post but just in case you still needed it there is an example of the new data structure in post 545 above.

Thanks, yeah, after I posted my question I happened to scroll up and saw it, so deleted the useless post :slight_smile:

1 Like

I’m a bit lost with the new version and hoping some kind person can nudge me toward a working card again.
I have been using a conditional card that pops up only when there is an alert and it has been working great for a long time.
Now that I have tried to do it with the new version I can’t seem to figure it out.

card:
  content: |
    {% if states.sensor.nws_alert_event.attributes.features[0] is defined %}
      Headline   

      {{states.sensor.nws_alert_event.attributes.features[0].properties.headline }}

      Details

      {{states.sensor.nws_alert_event.attributes.features[0].properties.description }}

      Instructions

      {{states.sensor.nws_alert_event.attributes.features[0].properties.instruction }}
    {% else %}
    {% endif %}
  type: markdown
  theme: AMOLED Blue
conditions:
  - entity: sensor.nws_alert_event
    state_not: none
type: conditional

Can anyone tell me what I’m missing?

Thanks

You’ll want to use state_attr('sensor.nws_alert_event','Alerts')[0].

Edit:
Further examples:

state_attr('sensor.nws_alerts', 'Alerts')[0].Event

state_attr('sensor.nws_alerts', 'Alerts')[0].Headline
1 Like

You can still use your current format but you’ll need to use the correct attributes.

card:
  content: |
    {% if states.sensor.nws_alert_event.attributes.Alerts[0] is defined %}
      Headline   

      {{states.sensor.nws_alert_event.attributes.Alerts[0].Headline }}

      Details

      {{states.sensor.nws_alert_event.attributes.Alerts[0].Description }}

      Instructions

      {{states.sensor.nws_alert_test.attributes.Alerts[0].Instruction }}
    {% else %}
    {% endif %}
  type: markdown
  theme: AMOLED Blue
conditions:
  - entity: sensor.nws_alert_event
    state_not: none
type: conditional

That is all assuming your sensor is called “nws_alert_event”.

But as noted above you should probably change it to the recommended format.

Also, I don’t know if you have looked at the other folders at the github repo but there you’ll find an example markdown card for your dashboard.

Your card above will only ever show the first event in the alert list but the one at the repo will show all of the alerts.

I am replying only in hope that someone posts a good working example of a replacement for what I had before the update. I want a Lovelace card for alerts but with the new thing I have nothing.

It depends on what you had before the update. Without know what you had no one can help you with the update.

And if you had just the stock package from my github repo then the readme for the release tells you that there are updated package & dashboard examples. Did you look at the new code in the package/dashboard folders there?

Or since you are replying to danbutter did you see the updated example code that I posted to help them out?

Thank you - I’m sorry I was just clicking through and not paying close enough attention. The example in the GitHub has me all set.

1 Like

Awesome! Glad to hear it.

It’s also just been brought to my attention that the instructions to find your location data (zone or county ID) aren’t correct anymore.

I’ve updated the instructions in the readme. This shouldn’t affect any existing users only new users trying to find that data.

but in looking at that I see that there’s a new endpoint for getting alerts based on those location ID’s

for example:

https://api.weather.gov/alerts/active.atom?zone=CAC057

it looks like it’s in XML format instead of json.

It hasn’t impacted the integration functionality and hopefully the other API endpoints continue to work but it’s something I’ll try to keep in mind.

I have one (hopefully last) piece of the automation puzzle. There is an automation which turned off an input boolean “Severe Weather” when the NWS Alerts sensor no longer had anything with the word “warning” in it…

alias: Household - Climate (Severe Weather Mode) Deactivate
description: ""
trigger:
  - platform: template
    value_template: |
      {{ 'warning' not in state_attr('sensor.nws_alerts', 'title') | lower }}
    alias: NWS Alert Sensor Does Not Contain Phrase (Warning)
condition: []
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.severe_weather
    alias: Deactivate Severe Weather Mode
mode: single

What changes do I need for this to work as expected with the new format?

Thanks again…

Thanks for the replies. I was trying to follow this link: https://github.com/finity69x2/nws_alerts/blob/f91d51e0621964b6bb707500c0d02e1a6bd6a333/lovelace/alerts_tab
and it isn’t working so I didn’t know where else to look.
I’ll try to modify my install when we have some weather so I can be sure it is working.

I’m not sure where that li8nk came from but if you go to the repo then click on the lovelace folder the new alerts_tab.yaml is found in there.

This should get you what you want:

alias: Household - Climate (Severe Weather Mode) Deactivate
description: ""
trigger:
  - platform: state
    entity_id: sensor.nws_alerts
condition:
  - condition: template
    value_template: |
      {% set ns = namespace(events='') %}
      {% for x in range(0,states('sensor.nws_alerts_test')|int ) %}
        {% set event = state_attr('sensor.nws_alerts_test', 'Alerts')[x].Event %}
        {% set ns.events = ns.events ~ ' ' ~ (event) %}
      {% endfor -%}
      {{ 'Warning' not in ns.events  }}
    alias: NWS Alert Sensor Does Not Contain Phrase (Warning)
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.severe_weather
    alias: Deactivate Severe Weather Mode
mode: single
1 Like

Thank you. I think I’ve got everything switched over now. It’s not looking like I have any strange weather in the immediate future, but I’ve switched everything so I’ll wait and see how it goes.

I appreciate everything.

1 Like