Correct your YAML is wrong, it should be as follows:
- condition: template
value_template: '{{ "Tornado Warning" in state_attr("sensor.nws_alerts_3", "title") }}'
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.
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
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.
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
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