Severe Weather Alerts from the US National Weather Service

Would love to get a component or a appdaemon python file for your lib… someway of adding one or more feeds of CAP-streams. Maybe filtering them by distance from “home location” and using them in home-assistant

I’ve only got some really basic skills in python so I don’t even know where to start :smiley:

For this to work, the CAP feed will need to define an area for each entry that specifies geo location coordinates. Not all CAP feeds that I’ve seen do that; in some cases it’s just a textual description of the affected area.

For the glue code that joins the CAP feed via @kelvinn’s capparselib library to Home Assistant, you could take a look at how I’ve done something similar for GeoRSS feeds.

Ah crap, noticed now that the polygon field was optional… to bad since it would have been an easy way to do it! Still a CAP component would be great!

I’ll take a look at your georss code to! Thanks!

Indeed, a lot of CAP feeds either just reference a geocode, or include a Point geometry.

I’ve stitched to two together when receiving the alerts, e.g. an alert comes from NOAA with geocode of 48299, then I look that up in a geocode list and associate a geometry with it. For Points I just add a buffer of a bit.

Here’s an example:

https://alerted.us/api/v1/alerts/?lng=-98.71762&lat=30.73275

The cap_slug is also available as a website, e.g.:

https://alerted.us/alerts/9a99f75ac8c89ff67dd413ecbd4448/

I basically did the entire side project just before having a kid, and then had to drop everything until she is mostly self sufficient. I’m just now getting time to focus on some of these things a little bit.

I think this is achievable using the rest platform, e.g.

sensor:
  - platform: rest
    resource: https://alerted.us/api/v1/alerts/?lng=-98.71762&lat=30.73275
    value_template: '{{ value_json | length }}'

I think it is possible to do a filter by date, but I’d need to read up on HASS datetime functions.

[quote="finity, post:1, topic:71853"]
- alias: NWS Notification Weather Alert
....
action: 
  - service: notify.pushbullet_notify 
    data: 
      message: "NWS: {{ states.sensor.nws_alert_event.state }}"
[/quote]

I think there may be an error in your acton. Shouldn’t “data” instead be “data_template” since you’re using a template in the message?

I never thought about it and if I was to start out from scratch I would say you are right but for some reason it actually does work that way.

I’ve used that notification syntax for around 8 months before using it here and it has always worked fine.

:thinking:

Hmm odd but ok… if it ain’t broke, don’t fix it.

1 Like

I was thinking that a more general CAP parser in hass would be best since a lot of countries are using CAP protocol for their messages. For example here is the swedish version http://api.krisinformation.se/v1/capmessage

Yeah, I’ve been getting freeze warning notifications off & on all night with that code.

Holy Crap! :astonished:

That was a pure wall of text!

That would call for a parsing genius to figure that out.

Or some sweet sweet Chrome plugin that parses it for me :wink:

1 Like

That is sweet. I’ll have to play around with that.

I am trying to set this up and is my very first time creating anything. I have read as many guides as I can find but I cant seem to get this correct. the configuration check keeps failing. I tried weather: which I get no error saving (the green check mark) but the check config says:
Platform not found: weather.rest
Platform not found: weather.rest.
Here is my config if someone can point out my error please?
# weather Alerts
weather:

  • platform: rest
    resource: https://api.weather.gov/alerts/active/count
    name: NWS Alert Count
    value_template: >
    {% if value_json.zones.WIC009 is defined %}
    {{ value_json.zones.WIC009 }}
    {% else %}
    0
    {% endif %}
    headers:
    User-Agent: Homeassistant
    Accept: application/ld+json
    scan_interval: 60

  • platform: rest
    resource: https://api.weather.gov/alerts/active?zone=WIC009
    name: NWS Alert Event
    value_template: >
    {% if value_json.features[0] is defined %}
    {{ value_json[‘features’][0][‘properties’].event }}
    {% else %}
    None
    {% endif %}
    json_attributes:

    • features
      headers:
      User-Agent: Homeassistant
      Accept: application/geo+json
      scan_interval: 60
1 Like

First, you should get in the habit of posting your code correctly following the instructions in the blue box at the top of the page. It makes it possible to indentation errors.

But on to your problem…

The code above doesn’t go under the weather: platform, it goes under the sensor: platform. So it would be:

sensor:
  - platform: rest
    resource: https://api.weather.gov/alerts/active/count
    name: NWS Alert Count
    .....
     
  - platform: rest
    resource: https://api.weather.gov/alerts/active?zone=INZ009
    name: NWS Alert Event
    value_template: >
    ....

I’m sorry. I should have specified that in my first post better.

I’ll fix it.

Duly noted and my apologies! I have made the change and now I get an error of
duplicated mapping key at line 106, column -775:
sensor:
Im pretty sure its a indent or formatting error and moved various line spacing back and forth. I am just learning this and imho not very bright or good with coding, but willing to learn. Any suggestions?
Thanks for helping btw!

Finally figured it out after taking a break and being really frustrated. I was adding a new section with sensor where I should have just put it under the existing sensor. Also formatting was the bigger issue. Being extremely new to this (and any type of programming) indentation is king!
Thanks for helping and providing this code.

Any idea what could be causing this error? I added the sensors to my sensors.yaml file,I created a nws_weather_alert.yaml file with the automation code from op and created the nws_popup_on_wx_alert.py

image

EDIT: Nevermind, I had some spacing wrong. It Validated!
Thanks

I really like this feature, came in handy over the weekend as we had wind gusts up to 50 MPH.

I have received 3 Pushover alerts yesterday that stated “unavailable” would there be a way to ignore and not send notifications if there is no data available?

One last question, is there a way to display this notification only in my Weather Tab?
Thanks

I’m actually about ready to post an update to this set up that solves the “unavailable” situation and the multiple notifications. I’m just trying to finalize a couple of tweaks on it.

As far as just having it pop up in one tab I’m not if that’s possible. And TBH, I don’t think that I would want that anyway since it kind of defeats the purpose of the notification if you aren’t on that tab when the notification comes in.

Thanks, will be looking forward to the update, although I haven’t received an “unavailable” message since.

My only reason to have it on a single tab is that I already receive the notification on my phone and also on my Apple Watch, so since I am aware of the alert, I would just then need to look under the “Weather” tab for the details.
Also, thanks for all your work so far and sharing with the community.