Severe Weather Alerts from the US National Weather Service

that fixed my issue. thank you so much!

1 Like

Thanks for the awesome work on this!

I’m using 0.92.2 and noticed the below in my event log:
Error during template condition: UndefinedError: 'dict object' has no attribute 'to_state'

I’ve narrowed it down to the automation for ‘NWS Weather Alert Pop Up Control’.

Any idea’s on how why it’s popping up?

did you happen to have an active weather alert when you restarted HA the last time before the error popped up?

Yes. That would be correct. We’ve had a ton of alerts here in North Texas the last few days.

I’m not really sure but i think it might have been because there was no “to_state” because the trigger was already in the state that should have caused the to_state to begin with. :crazy_face:

Is everything working otherwise beside that one error?

The weathers calmed down some around here, so I haven’t seen any new alerts. As far as I can tell, everything else seems to be working.

Hopefully it was just a glitch from having the alerts already active when you restarted HA. I’ll guess we’ll see on the next alerts. Hopefully there won’t be a time to test it. Good luck on the weather!

1 Like

can anyone share an example of a working config with the notify.alexa_media service working with the custom component. the custom component works flawlessly. I’m having issue with all the automations working. the code in the gist of finity doesn’t work for me at all. I can see part of the announce automation is working as i get a beep on my alexa devices and the volume level goes up like the automation calls for, but it doesn’t broadcast the alert info. and the pushbullet automation just shows a title of alert withno description. any help would be welcome

let’s take the easy one first…

that’s exactly what it’s supposed to do.

- service: notify.pushbullet_notify
  data_template:
    message: >
      {% if states.sensor.nws_alerts.attributes.title.split(' - ')[5] is defined %}
        "NWS: {{ states.sensor.nws_alerts.attributes.title.split(' - ')[5] }}"

that code only sends the title of the alert (…title…) to your pushbullet. You can modify it to send the description if you want. just change “title” to “display_desc”.

as far as the announcement…

can you otherwise get announcements to work outside of my code?

If you go to the services area and select the “notify.alexa_media” service and put in the following (substituting your echo entity_id) does it work?:

{
“message”:“test”,
“title”:“My title for Echo show”,
“data”:{“type”:“announce”, “method”:“all”},
“target”:“media_player.computer_room_dot”
}

Great work on this!! I have taken it and modified it for the new notify.alexa_media service, a popup in the IOS app, and packaged it as a package. To use,

  • add this line to your configuration.yaml
  packages: !include_dir_named packages
  • Create a folder called packages in your /config folder

  • Paste this code into a severeweather.yaml in your /config/packages folder

###############################################################################
#   @author         :   Steve
#   @date           :   08/16/2019
#   @package        :   Severe Weather
#   @description    :   Severe Weather alerts from the NWS
###############################################################################


homeassistant:
sensor:  
  - platform: rest
    resource: https://api.weather.gov/alerts/active/count
    name: NWS Alert Count
    value_template: >
      {% if value_json.zones.NVC003 is defined %}
        {{ value_json.zones.NVC003 }}
      {% else %}
        0
      {% endif %}
    headers:
      User-Agent: Homeassistant
      Accept: application/ld+json
    scan_interval: 60
    
  - platform: rest
    resource: https://api.weather.gov/alerts/active?zone=NVC003
    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

automation:
  - alias: 'NWS Weather Alert Pop Up Control'
    trigger:
      platform: state
      entity_id: sensor.nws_alert_count
    action:
      service: script.nws_popup_on_wx_alert
    
  - alias: NWS Notification Weather Alert
    trigger:
      platform: state
      entity_id: sensor.nws_alert_count
    condition:
      condition: template
      value_template: '{{states.sensor.nws_alert_count.state | int > 0}}'
    action:
      - service: notify.iphone
        data:
          message: "NWS: {{ states.sensor.nws_alert_event.state }}"
        
  - alias: NWS Announcement Weather Alert
    trigger:
      - platform: state
        entity_id: sensor.nws_alert_count
    condition:
      condition: and
      conditions:
        - condition: template
          value_template: '{{states.sensor.nws_alert_count.state | int > 0}}'
        ## Added a time condition because I don't want a non-emergency alert waking me up
        - condition: or
          conditions:
            - condition: time
              after: '09:00:00'
              before: '23:00:00'
            - condition: template
              value_template: >
                {{ 'Warning' in states.sensor.nws_alert_event.state }}
    action:
        #- service: media_player.volume_set
        #  data:
        #    entity_id:
        #      - media_player.computer_room_dot
        #      - media_player.kitchen_dot
        #      - media_player.livingroom_dot
        #      - media_player.master_bedroom_dot
        #    volume_level: 0.9
      - service: notify.alexa_media

        data_template:
          data:        
            type: announce
          target: 
            - group.alexa

          message: "Attention!. . . Attention!. . . The National Weather Service has issued a 
          {{ states.sensor.nws_alert_event.state }} for your area. 
          It expires at {{ as_timestamp(state_attr('sensor.nws_alert_event', 'features')[0].properties.expires)| timestamp_custom('%-I:%M %p on %-m-%-d-%Y') }}."
      - delay: '00:00:10'
      - service: notify.alexa_media
        data_template:
          data:        
            method: all
            type: announce
          target: 
            - group.alexa

          message: "Attention!. . . Attention!. . . The National Weather Service has issued a 
          {{ states.sensor.nws_alert_event.state }} for your area. 
          It expires at {{ as_timestamp(state_attr('sensor.nws_alert_event', 'features')[0].properties.expires)| timestamp_custom('%-I:%M %p on %-m-%-d-%Y') }}."
          
script:
  nws_popup_on_wx_alert:
      alias: NWS Weather Alert Pop Up
      sequence:
        ## Dismiss any current alert so the UI isn't filled 
        ## up with these if there are more then one.
        ## Only show the latest alert
        - service: persistent_notification.dismiss
          data:
            notification_id: "nwswxalert"
        ## Create a new persistant notification in the UI for a new alert
        - service_template: >
            {% if states.sensor.nws_alert_event.state != 'None' %}
              persistent_notification.create
            {% endif %}
          data_template:
            notification_id: "nwswxalert"
            message: "{{ state_attr('sensor.nws_alert_event', 'features')[0].properties.description }}"
            title: '{{ states.sensor.nws_alert_event.state }}'    

Thanks! :slightly_smiling_face:

Two things tho…

  1. the latest gist instructions I have are already in package format and also already include the updated code for using it with the latest alexa_media.

  2. in your code above you don’t need the “homeassistant:” entry on the first line.

Other than that thanks for your contribution. :+1:

I have created a directory packages in config/
in that directory, I created a file: severeweather.yaml and copied the code into it.

In configuration.yaml I added:

packages: !include_dir_named packages

When I do a config check, I get the following message:

integration not found: packages

I am running hassio 2.10; hass.io supervisor 184 home assistant 0.97.0 on an RPi

???

where did you put the “packages: !include…” line?

It needs to go under your homeassistant: section.

You got it…this should be added to the documentation…I just added that line in configuration.yaml because that’s what the documentation said.

Thanks

Yeah, Sorry I didn’t specify that since it’s part of the HA regular documentation.

I can throw that in there pretty easily tho.

thanks for pointing it out.

@finity Any idea what could be causing the following error, seeing this for the first time today, since configured a few months ago.

2019-09-06 17:43:50 ERROR (SyncWorker_7) [homeassistant.components.rest.sensor] Error fetching data: <PreparedRequest [GET]> from https://api.weather.gov/alerts/active?zone=XXXXXX,XXXXXX failed with HTTPSConnectionPool(host='api.weather.gov', port=443): Read timed out. (read timeout=10)

This happens when HA can’t access the server. Maybe the weather server was down for a moment, or your Internet connection was down for a moment, or something on the way between you and the server.

Thanks for letting me know.

Yeah, I get that occasionally too. It’s just the nature of things on the interwebs. :slightly_smiling_face:

Anyone using lovelace to display attributes of an alert. I leave near the ocean and often get costal flooding, or rip current alerts. I have a conditional card that will only display the alert if there is one, but I dont know enough about how to handle complex attributes like these. For example I’d just like to display

        "headline": "Beach Hazards Statement issued September 30 at 12:20PM EDT until September 30 at 8:00PM EDT by NWS Wakefield VA",
        "description": "* LOCATION...Along the Ocean side in Virginia Beach.\n\n* TIMING...Until 8 PM EDT this evening.\n\n* SURF OR RIP CURRENT RISK...There is a high risk of rip\ncurrents. Three to 4 ft breakers are expected along the surf.",
        "instruction": "A Beach Hazards Statement is issued when threats such as rip\ncurrents...longshore currents...sneaker waves and other hazards\ncreate life-threatening conditions in the surf zone. Caution\nshould be used when in or near the water.\n\nThere is a high risk of rip currents.\n\nRip currents are powerful channels of water flowing quickly away\nfrom shore...which occur most often at low spots or breaks in the\nsandbar and in the vicinity of structures such as jetties and\npiers. Heed the advice of lifeguards...beach patrol flags and\nsigns.\n\nIf you become caught in a rip current...relax and float. Don't\nswim against the current. If able, swim in a direction following\nthe shoreline. If unable to escape, face the shore and call or\nwave for help.",
        "response": "Avoid",
        "parameters": {
          "NWSheadline": [
            "BEACH HAZARDS STATEMENT REMAINS IN EFFECT UNTIL 8 PM EDT THIS EVENING... ...HIGH RIP CURRENT RISK REMAINS IN EFFECT UNTIL 8 PM EDT THIS EVENING"

from the entire attribute list below

{
  "features": [
    {
      "id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3843746-3282092",
      "type": "Feature",
      "geometry": null,
      "properties": {
        "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3843746-3282092",
        "@type": "wx:Alert",
        "id": "NWS-IDP-PROD-3843746-3282092",
        "areaDesc": "Virginia Beach",
        "geocode": {
          "UGC": [
            "VAZ098"
          ],
          "SAME": [
            "051810"
          ]
        },
        "affectedZones": [
          "https://api.weather.gov/zones/forecast/VAZ098"
        ],
        "references": [
          {
            "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3842142-3281012",
            "identifier": "NWS-IDP-PROD-3842142-3281012",
            "sender": "[email protected]",
            "sent": "2019-09-29T15:19:00-04:00"
          },
          {
            "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3842142-3281011",
            "identifier": "NWS-IDP-PROD-3842142-3281011",
            "sender": "[email protected]",
            "sent": "2019-09-29T15:19:00-04:00"
          },
          {
            "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3843306-3281817",
            "identifier": "NWS-IDP-PROD-3843306-3281817",
            "sender": "[email protected]",
            "sent": "2019-09-30T05:18:00-04:00"
          },
          {
            "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3843306-3281819",
            "identifier": "NWS-IDP-PROD-3843306-3281819",
            "sender": "[email protected]",
            "sent": "2019-09-30T05:18:00-04:00"
          },
          {
            "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3843306-3281818",
            "identifier": "NWS-IDP-PROD-3843306-3281818",
            "sender": "[email protected]",
            "sent": "2019-09-30T05:18:00-04:00"
          }
        ],
        "sent": "2019-09-30T12:20:00-04:00",
        "effective": "2019-09-30T12:20:00-04:00",
        "onset": "2019-09-30T12:20:00-04:00",
        "expires": "2019-09-30T20:00:00-04:00",
        "ends": "2019-09-30T20:00:00-04:00",
        "status": "Actual",
        "messageType": "Update",
        "category": "Met",
        "severity": "Moderate",
        "certainty": "Likely",
        "urgency": "Expected",
        "event": "Rip Current Statement",
        "sender": "[email protected]",
        "senderName": "NWS Wakefield VA",
        "headline": "Rip Current Statement issued September 30 at 12:20PM EDT until September 30 at 8:00PM EDT by NWS Wakefield VA",
        "description": "* LOCATION...Along the Ocean side in Virginia Beach.\n\n* TIMING...Until 8 PM EDT this evening.\n\n* SURF OR RIP CURRENT RISK...There is a high risk of rip\ncurrents. Three to 4 ft breakers are expected along the surf.",
        "instruction": "A Beach Hazards Statement is issued when threats such as rip\ncurrents...longshore currents...sneaker waves and other hazards\ncreate life-threatening conditions in the surf zone. Caution\nshould be used when in or near the water.\n\nThere is a high risk of rip currents.\n\nRip currents are powerful channels of water flowing quickly away\nfrom shore...which occur most often at low spots or breaks in the\nsandbar and in the vicinity of structures such as jetties and\npiers. Heed the advice of lifeguards...beach patrol flags and\nsigns.\n\nIf you become caught in a rip current...relax and float. Don't\nswim against the current. If able, swim in a direction following\nthe shoreline. If unable to escape, face the shore and call or\nwave for help.",
        "response": "Avoid",
        "parameters": {
          "NWSheadline": [
            "BEACH HAZARDS STATEMENT REMAINS IN EFFECT UNTIL 8 PM EDT THIS EVENING... ...HIGH RIP CURRENT RISK REMAINS IN EFFECT UNTIL 8 PM EDT THIS EVENING"
          ],
          "VTEC": [
            "/O.CON.KAKQ.RP.S.0013.000000T0000Z-191001T0000Z/"
          ],
          "PIL": [
            "AKQCFWAKQ"
          ],
          "BLOCKCHANNEL": [
            "CMAS",
            "EAS",
            "NWEM"
          ],
          "eventEndingTime": [
            "2019-09-30T20:00:00-04:00"
          ]
        }
      }
    },
    {
      "id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3843746-3282093",
      "type": "Feature",
      "geometry": null,
      "properties": {
        "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3843746-3282093",
        "@type": "wx:Alert",
        "id": "NWS-IDP-PROD-3843746-3282093",
        "areaDesc": "Virginia Beach",
        "geocode": {
          "UGC": [
            "VAZ098"
          ],
          "SAME": [
            "051810"
          ]
        },
        "affectedZones": [
          "https://api.weather.gov/zones/forecast/VAZ098"
        ],
        "references": [
          {
            "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3842142-3281012",
            "identifier": "NWS-IDP-PROD-3842142-3281012",
            "sender": "[email protected]",
            "sent": "2019-09-29T15:19:00-04:00"
          },
          {
            "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3842142-3281011",
            "identifier": "NWS-IDP-PROD-3842142-3281011",
            "sender": "[email protected]",
            "sent": "2019-09-29T15:19:00-04:00"
          },
          {
            "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3843306-3281817",
            "identifier": "NWS-IDP-PROD-3843306-3281817",
            "sender": "[email protected]",
            "sent": "2019-09-30T05:18:00-04:00"
          },
          {
            "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3843306-3281819",
            "identifier": "NWS-IDP-PROD-3843306-3281819",
            "sender": "[email protected]",
            "sent": "2019-09-30T05:18:00-04:00"
          },
          {
            "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3843306-3281818",
            "identifier": "NWS-IDP-PROD-3843306-3281818",
            "sender": "[email protected]",
            "sent": "2019-09-30T05:18:00-04:00"
          }
        ],
        "sent": "2019-09-30T12:20:00-04:00",
        "effective": "2019-09-30T12:20:00-04:00",
        "onset": "2019-09-30T12:20:00-04:00",
        "expires": "2019-09-30T20:00:00-04:00",
        "ends": "2019-09-30T20:00:00-04:00",
        "status": "Actual",
        "messageType": "Update",
        "category": "Met",
        "severity": "Moderate",
        "certainty": "Likely",
        "urgency": "Expected",
        "event": "Beach Hazards Statement",
        "sender": "[email protected]",
        "senderName": "NWS Wakefield VA",
        "headline": "Beach Hazards Statement issued September 30 at 12:20PM EDT until September 30 at 8:00PM EDT by NWS Wakefield VA",
        "description": "* LOCATION...Along the Ocean side in Virginia Beach.\n\n* TIMING...Until 8 PM EDT this evening.\n\n* SURF OR RIP CURRENT RISK...There is a high risk of rip\ncurrents. Three to 4 ft breakers are expected along the surf.",
        "instruction": "A Beach Hazards Statement is issued when threats such as rip\ncurrents...longshore currents...sneaker waves and other hazards\ncreate life-threatening conditions in the surf zone. Caution\nshould be used when in or near the water.\n\nThere is a high risk of rip currents.\n\nRip currents are powerful channels of water flowing quickly away\nfrom shore...which occur most often at low spots or breaks in the\nsandbar and in the vicinity of structures such as jetties and\npiers. Heed the advice of lifeguards...beach patrol flags and\nsigns.\n\nIf you become caught in a rip current...relax and float. Don't\nswim against the current. If able, swim in a direction following\nthe shoreline. If unable to escape, face the shore and call or\nwave for help.",
        "response": "Avoid",
        "parameters": {
          "NWSheadline": [
            "BEACH HAZARDS STATEMENT REMAINS IN EFFECT UNTIL 8 PM EDT THIS EVENING... ...HIGH RIP CURRENT RISK REMAINS IN EFFECT UNTIL 8 PM EDT THIS EVENING"
          ],
          "VTEC": [
            "/O.CON.KAKQ.BH.S.0013.000000T0000Z-191001T0000Z/"
          ],
          "PIL": [
            "AKQCFWAKQ"
          ],
          "BLOCKCHANNEL": [
            "CMAS",
            "EAS",
            "NWEM"
          ],
          "eventEndingTime": [
            "2019-09-30T20:00:00-04:00"
          ]
        }
      }
    }
  ],
  "friendly_name": "NWS Alert Event"
}