Did you put them in config.yaml?
Yes since they are a template sensor.
I understand why you are doing it but I think in most cases itās unnecessary.
I have only specific alerts that I want to get enhanced notifications of - severe thunderstorms or tornados. So I filter my enhanced notifications specifically for those.
the rest will pop up in my sidebar as a regular notification. They are interesting only as a minor thing to be aware of.
I donāt think Iāve ever had a non-weather related alert ever come thru using my integration. not ever. So I donāt see a use case (in my situation) for creating extra sensors to filter on when the vast majority of alerts would not be filtered out using those sensors.
But thatās just me.
@RogerB1 why do you think you need those sensors?
Iāve just always had it setup this way and I like they way it works and prefer this since I see no reason to change it since I get exactly what I want. These notifications donāt go to my phone or the app, I use a weather app for my phone. These are just in house announcements.
i donāt iām just trying to get things right. So in my script for nws this is what i have.
alias: NWS Alerts Announce Thunderstorm Warning
sequence:
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: >-
media_player.arc_ultra,media_player.foyer_speaker,media_player.master_bedroom
options:
voice: jarvis
message: The national weather service has issued a {{ repeat.item.description }}
target:
entity_id: tts.piper_2
- delay: "00:00:15"
description: ""
and this is my automation.
alias: NWS Announcements
description: National Weather Service Announcement
triggers:
- entity_id: sensor.nws_alerts_alerts
trigger: state
conditions:
- condition: numeric_state
entity_id: sensor.nws_alerts_alerts
above: 0
actions:
- repeat:
sequence:
- variables:
alert: "{{ repeat.item }}"
- if:
- condition: template
value_template: >-
{{ ('Severe Thunderstorm Warning' in alert.Event) and
(alert.Type == 'Alert') }}
then:
- entity_id: script.nws_alerts_announce_thunderstorm_warning
action: script.turn_on
- delay:
minutes: 1
for_each: >-
{{ trigger.to_state.attributes.Alerts | reject('in',
trigger.from_state.attributes.Alerts) | list() | sort(attribute='ID') }}
mode: queued
initial_state: "on"
max: 10
Does this look right? i couldnāt get conversation process to work at all. so trying tts. i think i want to edit this for just all around events like flooding to. but i forget the default value lol. we get mostly storm,tornado and flood watches. i was thinking of filtering his way but i think iād rather just get all the alerts.
I tried with another zone and got nothing. I get a Error: Error rendering data template: UndefinedError: ārepeatā is undefined when the script runs
I think the problem is that in the message you are using:
message: The national weather service has issued a {{ repeat.item.description }}
but ā{{ repeat.item.description }}ā doesnāt exist in the context of that script. in order for the script to use a variable is has to be declared in the script itself or passed into it from the automation.
I would guess the script has no idea what ā{{ repeat.item.description }}ā is so it errors out. I think you should be able to see that in your homeassistant.log.
if you want the description in the announcement then you need to send that data as a script variable.
this hasnāt been tested but I think it should work:
for the automation:
alias: NWS Announcements
description: National Weather Service Announcement
triggers:
- entity_id: sensor.nws_alerts_alerts
trigger: state
conditions:
- condition: numeric_state
entity_id: sensor.nws_alerts_alerts
above: 0
actions:
- repeat:
sequence:
- variables:
alert: "{{ repeat.item }}"
- if:
- condition: template
value_template: >-
{{ ('Severe Thunderstorm Warning' in alert.Event) and
(alert.Type == 'Alert') }}
then:
- action: script.turn_on
target:
entity_id: script.nws_alerts_announce_thunderstorm_warning
data:
description: "{{ alert.Description}}"
- delay:
minutes: 1
for_each: >-
{{ trigger.to_state.attributes.Alerts | reject('in',
trigger.from_state.attributes.Alerts) | list() | sort(attribute='ID') }}
mode: queued
initial_state: "on"
max: 10
then the script:
alias: NWS Alerts Announce Thunderstorm Warning
sequence:
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: >-
media_player.arc_ultra,media_player.foyer_speaker,media_player.master_bedroom
options:
voice: jarvis
message: The national weather service has issued a {{ description }}
target:
entity_id: tts.piper_2
- delay: "00:00:15"
description: ""
as far as the other code for the media players to actually make the announcement youāll need to verify thatās correct for yourself.
ok iāll try this tonight. one thing iām curious about though if i wanted to get watches along with alerts, would it be a matter of changing the value template to something like this
- condition: template
value_template: >-
{{ ('Tornado Watch' in alert.Event) and
(alert.Type == 'Alert') }}
One more bit of spam. So i got it working a lot better. I put the tts directly in to the automation instead of the script. For what ever reason it didnāt want to pass the info on to the script. I kept getting errors of " * Error while executing automation automation.nws_announcements: extra keys not allowed @ data[ādescriptionā]". Soubnds like a templating error and honestly i hate templating with a passion. I was also able to slow it down using ollama and just put in the prompt āTry to talk slowly and not to fast.ā and also to keep responses accurate. Iāll create more conditions for other alerts i want to add. iām sure there is a cleaner way of doing it but sometimes if you donāt have the experience in that area itās best to do it the way you know lol. As i have learned painfully with HA
alias: NWS Announcements
description: National Weather Service Announcement
triggers:
- entity_id: sensor.nws_alerts_alerts
trigger: state
conditions:
- condition: numeric_state
entity_id: sensor.nws_alerts_alerts
above: 0
actions:
- repeat:
sequence:
- variables:
alert: "{{ repeat.item }}"
- if:
- condition: template
value_template: >-
{{ ('Tornado Watch' in alert.Event) and (alert.Type == 'Alert')
}}
then:
- delay:
minutes: 1
enabled: false
- action: conversation.process
metadata: {}
data:
agent_id: conversation.llama3_2
text: "\" {{ repeat.item.Description }} \""
response_variable: response
- action: assist_satellite.announce
metadata: {}
data:
message: >-
"{{ response.response.speech.plain.speech if
response.response.speech.plain.speech is defined else 'No
response available.' }}"
preannounce: false
target:
entity_id: assist_satellite.voice_pe_assist_satellite
for_each: >-
{{ trigger.to_state.attributes.Alerts | reject('in',
trigger.from_state.attributes.Alerts) | list() | sort(attribute='ID') }}
mode: queued
initial_state: "on"
max: 10
I agree. Whatever works. There has been plenty of times I got things working with brute force instead of elegance.
This is my finished working monstrosity in case anyone wnats to try. i have this option for each alert. iād like to streamline it for just the alerts i want. but as said before i hate templating. i assume it would be in this field i need to do it just not sure how. One more thing, is there a visual map for the zones? my county is huge and apparently im not in the right zone
- condition: template
value_template: >-
{{ ('Tornado Watch' in alert.Event) and (alert.Type == 'Alert')
}}
alias: NWS Announcements
description: National Weather Service Announcement
triggers:
- entity_id: sensor.nws_alerts_alerts
trigger: state
conditions:
- condition: numeric_state
entity_id: sensor.nws_alerts_alerts
above: 0
actions:
- repeat:
sequence:
- variables:
alert: "{{ repeat.item }}"
- if:
- condition: template
value_template: >-
{{ ('Tornado Watch' in alert.Event) and (alert.Type == 'Alert')
}}
then:
- action: conversation.process
metadata: {}
data:
agent_id: conversation.llama3_2
text: "\" {{ repeat.item.Description }} \""
response_variable: response
- action: sonos.snapshot
metadata: {}
data:
with_group: true
entity_id: >-
media_player.arc_ultra,media_player.foyer_speaker,media_player.master_bedroom
- action: media_player.volume_set
data:
volume_level: 0.85
target:
entity_id:
- media_player.foyer_speaker
- media_player.master_bedroom
- action: media_player.volume_set
metadata: {}
data:
volume_level: 0.1
target:
entity_id: media_player.arc_ultra
- action: media_player.play_media
metadata: {}
data:
media_content_id: /local/sounds/nws_alert_tone.mp3
media_content_type: music
target:
entity_id: media_player.foyer_speaker,media_player.master_bedroom
- delay:
hours: 0
minutes: 0
seconds: 25
milliseconds: 0
- action: tts.speak
metadata: {}
data:
cache: true
message: "\"{{ response.response.speech.plain.speech }}\""
media_player_entity_id: media_player.foyer_speaker,media_player.master_bedroom
options:
voice: jarvis
target:
entity_id: tts.piper_2
- delay:
hours: 0
minutes: 0
seconds: 17
milliseconds: 0
- action: media_player.play_media
metadata: {}
data:
media_content_id: /local/sounds/nws_alert_tone2.mp3
media_content_type: music
target:
entity_id: media_player.foyer_speaker,media_player.master_bedroom
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- action: sonos.restore
metadata: {}
data:
with_group: true
entity_id: >-
media_player.arc_ultra,media_player.foyer_speaker,media_player.master_bedroom
You should be able to go here ( Public Zone Maps ) and it will show a map of your selected state with all the zones.
you can also use GPS coordinates in the integration config to get the best results for your exact location.
Iām finally updating my automations for this again, and after reading this I may have to look into this repeat.item. I havenāt used it before.
I just used simple for loopsā¦
alias: NWS Announce Weather Alert
triggers:
- entity_id:
- sensor.nws_alerts
trigger: state
attribute: Alerts
conditions:
- condition: and
conditions:
- condition: template
value_template: "{{states.sensor.nws_alerts_alerts.state | int > 0}}"
- condition: template
value_template: "{{ trigger.to_state.state|float > trigger.from_state.state|float }}"
- condition: template
value_template: |-
{% for Event in states.sensor.nws_alerts_alerts.attributes.Alerts %}
{{
('Severe' in states.sensor.nws_alerts_alerts.attributes.Alerts[ loop.index - 1 ].Event
or
'Tornado' in states.sensor.nws_alerts_alerts.attributes.Alerts[ loop.index - 1 ].Event)
and
'Warning' in states.sensor.nws_alerts_alerts.attributes.Alerts[ loop.index - 1 ].Event
}}
{% endfor %}
actions:
- data:
entity_id:
- media_player.announcements
volume_level: 0.9
action: media_player.volume_set
- data_template:
message: >
{% for Event in states.sensor.nws_alerts_alerts.attributes.Alerts %}
Attention!,Attention!,The National Weather Service Has issued a
{{states.sensor.nws_alerts_alerts.attributes.Alerts[ loop.index - 1
].Event }} in {{states.sensor.nws_alerts_alerts.attributes.Alerts[
loop.index - 1 ].AreasAffected }} {% endfor %}
action: script.announcement
- delay: "00:00:15"
- data_template:
message: >
{% for Event in states.sensor.nws_alerts_alerts.attributes.Alerts %}
Attention!,Attention!,The National Weather Service Has issued a
{{states.sensor.nws_alerts_alerts.attributes.Alerts[ loop.index - 1
].Event }} in {{states.sensor.nws_alerts_alerts.attributes.Alerts[
loop.index - 1 ].AreasAffected }} {% endfor %}
action: script.announcement
initial_state: "on"
Condition:
{% for Event in states.sensor.nws_alerts_alerts.attributes.Alerts %}
{{
((āSevereā in states.sensor.nws_alerts_alerts.attributes.Alerts[ loop.index - 1 ].Event)
or
(āTornadoā in states.sensor.nws_alerts_alerts.attributes.Alerts[ loop.index - 1 ].Event))
and
āWarningā in states.sensor.nws_alerts_alerts.attributes.Alerts[ loop.index - 1 ].Event }}
{% endfor %}
Result:
False
False
Message:
{% for Event in states.sensor.nws_alerts_alerts.attributes.Alerts %}
Attention!,Attention!,The National Weather Service Has issued a {{states.sensor.nws_alerts_alerts.attributes.Alerts[ loop.index - 1 ].Event }} in {{states.sensor.nws_alerts_alerts.attributes.Alerts[ loop.index - 1 ].AreasAffected }}
{% endfor %}
Result:
Attention!,Attention!,The National Weather Service Has issued a Flood Warning in Angelina, TX; Polk, TX; Trinity, TX
If I tried to use the Description, Iād have to find a way to split it and grab just the instructions or maybe the whereā¦
Well, I wasnāt sure this was going to work, but it did!!
alias: NWS Update Event ID Variable
description: ""
triggers:
- entity_id:
- sensor.nws_alerts_alerts
trigger: state
actions:
- repeat:
count: "{{ state_attr('sensor.nws_alerts_alerts', 'Alerts') | length }}"
sequence:
- data:
entity_id: var.nws_alerts_event_ids
value_template: >-
{{ state_attr('sensor.nws_alerts_alerts', 'Alerts')[repeat.index -
1].ID }}
force_update: true
icon: mdi:weather-cloudy-alert
attributes:
history_1: "{{ states('var.nws_alerts_event_ids') }}"
history_2: "{{ state_attr('var.nws_alerts_event_ids', 'history_1') }}"
history_3: "{{ state_attr('var.nws_alerts_event_ids', 'history_2') }}"
history_4: "{{ state_attr('var.nws_alerts_event_ids', 'history_3') }}"
history_5: "{{ state_attr('var.nws_alerts_event_ids', 'history_4') }}"
history_6: "{{ state_attr('var.nws_alerts_event_ids', 'history_5') }}"
history_7: "{{ state_attr('var.nws_alerts_event_ids', 'history_6') }}"
history_8: "{{ state_attr('var.nws_alerts_event_ids', 'history_7') }}"
history_9: "{{ state_attr('var.nws_alerts_event_ids', 'history_8') }}"
history_10: "{{ state_attr('var.nws_alerts_event_ids', 'history_9') }}"
action: var.set
initial_state: "on"
Iām still tweaking, but this is what I have for Persistent Notifications now.
alias: NWS Notification Weather Alert
triggers:
- entity_id:
- sensor.nws_alerts_alerts
trigger: state
conditions:
- condition: template
value_template: "{{ states.sensor.nws_alerts_alerts.state | int > 0 }}"
- condition: template
value_template: "{{ trigger.to_state.state|float > trigger.from_state.state|float }}"
actions:
- repeat:
count: "{{ state_attr('sensor.nws_alerts_alerts', 'Alerts') | length }}"
sequence:
- data_template:
message: >
{% set Alert = state_attr('sensor.nws_alerts_alerts',
'Alerts')[repeat.index - 1] %}
# [{{ Alert.Event }} in {{ Alert.AreasAffected }}]({{ Alert.URL }}
"Weather.gov")
## {{ Alert.Headline }}
{{ Alert.Description }}
action: notify.persistent_notification
initial_state: "on"
mode: single
Result: