Severe Weather Alert

Correct your YAML is wrong, it should be as follows:

 - condition: template
    value_template: '{{ "Tornado Warning" in state_attr("sensor.nws_alerts_3", "title") }}'

This is interesting. I apparently created this in the UI and itā€™s listed as {{ 'Tornado Warning' in state_attr('sensor.nws_alerts_3', 'title') }} in there. Iā€™ll have to run some experiments to see how to get it to the correct format in YAML view.

Thanks for the tip. Glad itā€™s somehow still working, though. This has been a huge help being notified of tornado warnings overnight.

In the UI thatā€™d be fine, it sanitizes the code for you.

1 Like

Out of curiosity, what are you guys using as a trigger for these severe weather automations? And do you do separate triggers for each possible severe weather alert?

Thanks for your time.

I have my google homeā€™s broadcast warnings, while everything else goes to the phone hereā€™s the announcer part:

- alias: NWS Announce Weather Alert
  trigger:
    - platform: state
      entity_id: sensor.nws_alerts
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: "{{states.sensor.nws_alerts.state | int(0) > 0}}"
      - condition: template
        value_template: "{{ trigger.to_state.state|float(0) > trigger.from_state.state|float(0) }}"
  action:
    - service: script.weather_alerts

Script:

weather_alerts:
  alias: Weather Alerts
  mode: queued
  sequence:
    - choose:
        - alias: Sever Weather
          conditions:
            - "{{ 'Tornado' in state_attr('sensor.nws_alerts', 'title').split(' - ')[0] }}"
          sequence:
            - service: script.house_annoucement
              data:
                this_message: "The National Weather Service Has issued a {{ state_attr('sensor.nws_alerts', 'title').split(' - ')[0] }} ,, {{ state_attr('sensor.nws_alerts', 'spoken_desc').split('\n\n-\n\n')[0] }}"
                volume: 0.9
                priority: True
        - alias: Weather Warning
          conditions:
            - "{{ 'Warning' in state_attr('sensor.nws_alerts', 'title').split(' - ')[0] or 'Watch' in state_attr('sensor.nws_alerts', 'title').split(' - ')[0]}}"
          sequence:
            - service: script.house_annoucement
              data:
                this_message: "The National Weather Service Has issued a {{ state_attr('sensor.nws_alerts', 'title').split(' - ')[0] }} ,, {{ state_attr('sensor.nws_alerts', 'spoken_desc').split('\n\n-\n\n')[0] }}"
                volume: 0.9

My announcement script has a night mode so these donā€™t play after like 8pm unless thereā€™s a tornado watch/warning.

Yes I am aware of the mis-spelling of the script name, I havenā€™t cared enough yet to fix it :stuck_out_tongue:

1 Like

I still use my NWS alerts integration linked in post #8

Hey there! I have your HACS installation installed but would like to find examples on how to execute automations based on the weather alert.

Thereā€™s are examples in the packages folder at the github repo.

Since the NWS alerts sensorā€™s attributes are only populated when there is an event, itā€™s nearly impossible to test. Does anyone have any ideas on how to do that?

I took a look at the yaml file in post #8 but itā€™s so complicated! haha Array indexing for multiple alert support etc.

Is there a way to have a simple automation that triggers when there is an alert and plays a voice message that is the actual alert itself? The example was playing a pre-set mp3 file and doing all kinds of text parsing for the popup alert. I believe there is a ā€œspoken_descā€ field that can be used but not sure how (see script below)

Since the visual UI editor didnā€™t make sense, I came up with this yaml automation based on the example and would appreciate some help with it from the experts here. Itā€™s definitely wrong but wanted to start somewhere. The ā€˜messageā€™ field is usually a constant string and this is the first time I try using variable expansion in its place.

alias: NWS Check for Multi Alerts
description: NWS Check for Multi Alerts
trigger:
  - platform: state
    entity_id: sensor.nws_alerts
condition:
  - "{{ states('sensor.nws_alerts') | int > 0 }}"
  - "{{ trigger.to_state.state|int > trigger.from_state.state|int }}"
action:
  - service: tts.google_translate_say
    data:
      entity_id: media_player.study_speaker
      message: |
        {{ state_attr('sensor.nws_alerts', 'spoken_desc') }}
mode: single
initial_state: true

Quick update/answer to my own question.

I found that I could set the values of the sensor to whatever I want in the Developer Tools section:

The yaml automation posted above seemed to work for my test data.

I also changed my Zone ID to AKZ215 and reloaded the Integration which had a lot of weather alerts to test against.

Just be aware tho that if there are multiple alerts that the TTS above will announce every one of them. It wonā€™t just tell you the last one.

If there are 5 alerts and when number 6 comes in it will announce the entire text contained in the ā€œspoken_descā€ section of the sensor.

thatā€™s the reason for all of the parsing that was done in the original template - so you only get the most recent one announced.

1 Like

Thank you for the tip.
I would be eternally grateful if you could add just the minimal, required logic to handle that case to my automation. I tried but couldnā€™t follow the logic in the Github post. I guess I havenā€™t mastered yaml voodoo yet haha

which case are you referring to? So that the automation only tells you the last alert received?

Yes please.

this should only announce the spoken description of the last alert received (index ā€˜[0]ā€™):

alias: NWS Check for Multi Alerts
description: NWS Check for Multi Alerts
trigger:
  - platform: state
    entity_id: sensor.nws_alerts
condition:
  - "{{ states('sensor.nws_alerts') | int > 0 }}"
  - "{{ trigger.to_state.state|int > trigger.from_state.state|int }}"
action:
  - service: tts.google_translate_say
    data:
      entity_id: media_player.study_speaker
      message: |
        {{ state_attr('sensor.nws_alerts', 'spoken_desc').split(' - ')[0] }}
mode: single
initial_state: true
2 Likes

Thank you!

Is this still an attribute? I donā€™t see it.

No.

there was a major re-write of the integration recently.

the new attributes are as follows:

Type
Status
Severity
Certainty
Sent
Onset
Expires
Ends
AreasAffected
Description
Instruction

I think the closest equivalent to the old spoken_desc attribute is the Description attribute

I think I got a good setup on it now.


1 Like