Severe Weather Alerts from the US National Weather Service

Well, since I already had the list version in the works I’ll go ahead and post it’s results so I don’t feel like I completely wasted my time. :wink: :laughing:

attribution: Data provided by Weather.gov
title: Flood Warning, Flood Warning, Flood Warning, Flood Warning
event_id: https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.e0a8f1875d4c3d3cb672a8e0f94f91daf5dee704.005.1, https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.e0a8f1875d4c3d3cb672a8e0f94f91daf5dee704.004.1, https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.e0a8f1875d4c3d3cb672a8e0f94f91daf5dee704.001.1, https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.e0a8f1875d4c3d3cb672a8e0f94f91daf5dee704.002.1
message_type: Update, Update, Update, Update
display_desc: 
>
Headline: The Flood Warning remains in effect
Status: Actual
Message Type: Update
Severity: Severe
Certainty: Observed
...
...

(also I forgot to post the example screenshot above - updated…)

Notice you don’t need the split() at all to get the same results.

But again I don’t know if that’s worth the breaking change.

Shouldn’t be too hard to modify in the PR’ed version :wink:
Merge and adjust the function, should be in _init_.py in the version I’ve PR’ed :slight_smile:

EDIT: or even a beta branch since I haven’t tested the YAML config :stuck_out_tongue:

Basically the UpdateCoordinator handles the data grabbing and removes the need to do the old @Throttle method.

It also gives you neat info like:

2021-07-16 12:57:23 DEBUG (MainThread) [custom_components.nws_alerts] Data will be update every 0:05:00
2021-07-16 14:07:37 DEBUG (MainThread) [custom_components.nws_alerts] Finished fetching NWS Alerts data in 0.854 seconds

From what I understand it keeps from bogging down the main HA loop as well. (You might have to confirm this with balloob or frenck tho)

EDIT: Feel free to hit me up on discord if you want to discus further.

I just updated to the dev branch in my test HA instance and got a “migration” error.

2021-07-16 17:14:26 ERROR (MainThread) [homeassistant.config_entries] nws_alerts.async_migrate_entry did not return boolean

any idea what that might mean?

All I did was (from a stopped HA server) delete the old files from the nws_alerts directory and added all the files from the PR in the dev branch.

Would that be the correct way to do the change-over or am I missing something?

Do I need to delete the old integration first?

I really dislike discord… :slightly_smiling_face:

That’s my bad, forgot to return True at the end of async_migrate_entry

OK, I added it to my local instance and it seemed to work.

I’ll get it added to the repo.

Ya I PR’ed it fast :stuck_out_tongue:

1 Like

ninja… :laughing:

stupid sentence checker…

1 Like

here’s another one for you.

deleted the integration from the UI config and tried a yaml config:

2021-07-16 17:36:12 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up nws_alerts platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/nws_alerts/sensor.py", line 44, in async_setup_platform
    async_add_entities([NWSAlertSensor(hass, config)], True)
  File "/config/custom_components/nws_alerts/sensor.py", line 57, in __init__
    super().__init__(hass.data[DOMAIN][entry.entry_id][COORDINATOR])
KeyError: 'nws_alerts'

Try commenting line 38 in __init__.py

same error

I’ll keep digging, I’m also adding tests :slight_smile:

1 Like

Formatting of the weather alert.
This is my code for an ALEXA announcement.

      service: media_player.play_media
    - data:
        data:
          method: speak
          type: announce
        message:
          I've detected a change in national weather service advisories for the East Valley.
          {% for i in range(states('sensor.nws_alert_count') | int) %}
          {%- if i > 0 -%}
          ---------
          {%- endif %}
          {{ state_attr('sensor.nws_alert_event', 'features')[0].properties.headline }}
          {{ state_attr('sensor.nws_alert_event', 'features')[0].properties.description }}
          {% endfor %}
      service: notify.alexa_media_everywhere
        Hi There,
        I've detected a change in national weather service advisories for the East Valley.
        
          Flash Flood Watch issued July 21 at 2:01PM MDT until July 25 at 12:00AM MDT by NWS Phoenix AZ
          The Flash Flood Watch continues for

* A portion of south central Arizona, including the following areas,
Aguila Valley, Apache Junction/Gold Canyon, Buckeye/Avondale, Cave
Creek/New River, Central Phoenix, Deer Valley, East Valley,
Fountain Hills/East Mesa, Gila Bend, New River Mesa, North
Phoenix/Glendale, Northwest Pinal County, Northwest Valley,
Scottsdale/Paradise Valley, Sonoran Desert Natl Monument, South
Mountain/Ahwatukee, Southeast Valley/Queen Creek, Tonopah Desert
and West Pinal County.

The ALEXA automation works but is quirky in it message.
For example it will say
“Buckeye/ (slash)Avondale, Cave (it will pause because of the line break in the message, then it will say) Creek/New River”

Is there anyway to prevent the pause at the end of the line?

Thanks for the help.

Strip the line breaks.

How would one do that when the message comes from the NWS and then the automation is triggered.

Try

{{ state_attr('sensor.nws_alert_event', 'features')[0].properties.description|trim }}

using “| trim” didn’t work for me the way I think you expect it to.

But you can try the following:

{{ state_attr('sensor.nws_alert_event', 'features')[0].properties.description | replace('\n', '') }}

that should replace all newline characters with nothing (effectively removing all of them).

Do you also want to get rid of the slashes in the spoken description too?

if so you should be able to also add another replace filter:

{{ state_attr('sensor.nws_alert_event', 'features')[0].properties.description | replace('\n', '') | replace('/', ', ') }}
1 Like

Thanks to @finity and @firstof9 to helping me out.
It now does what I would like it to do.
Again appreciate everyone’s help.

Ah right I knew it was one of the two replace or trim… lol

1 Like

I just released a new update based on a lot of (very patient :wink:) work by @firstof9. thanks! :slightly_smiling_face:

There shouldn’t be any breaking changes. But of course if there are any issues let us know.

Now that those changes are in I’ll update this again in a few days for the message type changes.

2 Likes