Severe Weather Alerts from the US National Weather Service

I don’t use Google Home devices so I don’t know how to do what you’re asking.

Hopefully someone who does will help you out or maybe start another thread asking about the google home media player generically that you can then modify to use for this.

got it. Thank you for your help. Your project works awesomely btw!

1 Like

I need to make note of a required change to the code for the announcement portion.

@Dixey noticed a bug that prevented the echo’s from making the announcement for the non-MasterBedRoom automation. This bug only affects the code using the custom_component. If you use the REST sensor code that should still work OK as is.

Apparently putting the outside quotes around the actual message inside the template prevents the echo from reading the message correctly so the end result is…nothing. No errors in the log or anything. I threw those in to the code at the last minute before posting (or testing :roll_eyes:) just to make everything “consistent”.

I’m not sure why that would be an issue, tho. :thinking:

Anway, it’s an easy fix.

just replace the two “message:” sections of the non-MBR announcement with the following:

{% if states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[5] is defined %}
  Attention!,,,Attention!,,,The National Weather Service Has issued a {{ states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[5] }}
{% elif states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[4] is defined %}
  Attention!,,,Attention!,,,The National Weather Service Has issued a {{ states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[4] }}
{% elif states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[3] is defined %}
  Attention!,,,Attention!,,,The National Weather Service Has issued a {{ states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[3] }}
{% elif states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[2] is defined %}
  Attention!,,,Attention!,,,The National Weather Service Has issued a {{ states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[2] }}
{% elif states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[1] is defined %}
  Attention!,,,Attention!,,,The National Weather Service Has issued a {{ states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[1] }}
{% else %}
  Attention!,,,Attention!,,,The National Weather Service Has issued a {{ states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[0] }}
{% endif %}

I’ve also updated the public gist using the custom_component linked to above to reflect the required changes.

Thanks again to Dixey for pointing out the bug. It’s good to get it fixed before the storm season kicks in full force.

@eracknaphobia

I don’t know if you ever check your issues on your github but I created one a few days ago.

if you could look into that it would be greatly appreciated.

Here is the text from there:

I was just moving some stuff around to put all my alert stuff into a package and realized that my two alert sensors got their entity-id’s swapped around (sensor.nws_alerts became sensor.nws_alerts_2 and vice versa)

I think it was because I moved one sensor from the “sensors.yaml” into the package but left the other in the “sensors.yaml” file. So I think it loaded the sensor.yaml file first and then by default it made that one sensor.nws_alerts when it used to be sensor.nws_alerts_2.

I was able to fix it by moving both sensors into the package in the correct order again.

Is there any way that you can make an option to give them a unique name and make the entity_id from the unique name?

Thanks again for making this. It’s still working great…except for this one little snafu.

I was just digging thru the code for the custom component from @eracknaphobia related to the post just above this to see if I could figure out how to add a name to the sensor and I realized that the functionality is already in there.

Here is the full configuration example:

- platform: nws_alerts (required)
  name: My NWS Sensor (optional)
  zone_id: 'ALC023' (required)

This will create a sensor called “sensor.my_nws_sensor” in your states page that you can use in your automations and scripts. Without adding the “name:” option then the second sensor would have had “_2” appended to the sensor name to denote the second sensor.

If you only use one sensor then you can disregard this. But if you want to use a different sensor for different locations then this is a good way of splitting them out to make the sensor descriptions more manageable or for any testing necessary which is what I would use it for.

I have needed to add another function to this project due to the recent switch to Lovelace as the default UI and the disappointing way that Lovelace handles the misleadingly named “persistent” notifications.

It used to be that the pop up would occur on every page in the UI and remain until you clicked on the “Dismiss” button.

Now, in Lovelace, the persistent notifications don’t populate in the main window but iunstead just put a little orange indicator dot on top of the “bell” icon in the top right corner. And I also realized that Persistent notifications don’t really persist thru HA restarts.

So in order to get some of the original functionality back I’ve made some changes to the code in the gist that I will summarize here:

  1. I added an input boolean to control the actions of a Lovelace Conditional card. (gist line 49)

  2. I added a new template sensor to also control the actions of a Lovelace Conditional card. (gist line 60)

  3. I made changes to the pop up control script to set the correct input boolean state. (gist line 282)

  4. I added an automation to dismiss the persistent notification based on the state of the input boolean (gist line 250)

5 Lastly, I added a trigger to the pop control automation to re-trigger the persistent notification at HA restart. (gist line 79)

here is the link to the gist again:

NWS Alerts Using Custom Component

Then to get this to all work correctly in love lace you need to add the attributes state custom card to your lovelace UI:

Then add the following to every view that you want to have the pop up show up on:

  - type: conditional
    conditions:
      - entity: sensor.nws_alerts_are_active
        state: 'on'
      - entity: input_boolean.bool_9
        state: 'on'
    card:
      type: entities
      entities:
        - input_boolean.bool_9
        - type: custom:entity-attributes-card
          entity: sensor.nws_alers
          filter:
            include:
              - sensor.nws_alerts.display_desc

I don’t think it will cycle thru the different pop ups based on the number of active alerts but I think it will show every alert display description in the pop up card.

And then in the card that is displayed all you need to do to dismiss the window is turn off the switch (input boolean) in that same card.

I haven’t done much real world testing on this since I haven’t had more than one alert at a time so if anything changes I’ll post it back here again.

And just as another FYI, I finally figured out how to use packages and the gist is now written to be used as a package in HA. Just copy the indicated section of code into the file name of your choosing and store it in your /packages folder and everything should work.

I hope…at least it does for me. :wink:

I’m thinking about using your lib in a generic cap-component for hass. Just googled and found this here!

1 Like

First of all… Thank you for the absolutely amazing work!!!

I posted two small feature requests regarding formating of alerts here: https://github.com/eracknaphobia/nws_custom_component/issues/2

Any possibility of getting this as a formal component in hass? This absolutely needs to be in there, again amazing work!

Any plan to merge this into Home Assistant? I love the work! Like many others, I came here because I just learned of WUnderground shutting down the free api.

1 Like

I’m not a developer in any sense of the word so I wouldn’t even know how to begin to do that.

I updated the gist with the updated code to use it with the newest version of the Alexa Media TTS custom component.

@finity I just upgrade to 0.92.1 and I am now receiving this error ‘Integration feedparser not found when trying to verify its sensor platform’
Did something change with this sensor setup? It was working fine in 0.91 and I didn’t see a breaking change for this.

platform: feedparser
name: NWS Alert RSS Feed

Did you add an empty file named “__init__.py” to the nws_alerts folder?

@walt
Yes I did. If I comment out the sensor in my config.yaml the error goes away.

I’m sure it has to do with “The great migration” so its probably a folder structure issue for the feedparser custom component.

I haven’t updated to v92x so I cant troubleshoot it yet. I will be soon tho.

However, you really don’t need the feedparser portion of the package for everything else to work. You can just comment it out and everything else will still function until we get it working again.

Or you can go to the author of the feedparser component and ask for support there. Which, honestly, is the best solution since I’m sure there are others who use it and are probably affected too.

So this is interesting, Am I suppose to have the “custom-components/sensor.feedparser” installed? I haven’t added this and it seemed to be working. If I am that’s probably why the error. I didn’t see that this was required for the nws_alert.

Check your /custom_components/nws_alerts folder and make sure you have the following files:

__init__.py
sensor.py

and a folder:

__pycache__

which should have the files:

__init__.cpython-37.pyc
sensor.cpython-37.pyc

I don’t see the pycache folder or the 2 files. Do I need to create them? On 0.91 it was working fine.

I did add the custom component/sensor.feedparser and the invalid config error went away. I assume that is what was needed even though I never had that previously and I didn’t see it being required for the nws_alert.

I think the pycache folder and files will be created for you.

no. it’s not necessary.

i said as much in my post right above yours. :wink:

But if you just copied the complete package from the github then you need it installed because the config is included in the package.

I think i’ll remove it from the package so it causes less confusion.