I am having trouble understanding how to just read certain alerts. I only want to know if my county is under a Tornado warning/watch and severe thunderstorm warning. Can i have a sensor only detect these 3 items and base notifications off that?
in addition to the examples posted above by both firstof9 and myself there are examples you can use at the github repo to modify as necessary for your needs.
Thank you for this. Do you mind showing me your house announcement script? I was going to do something simple with my google mini but I would like to see what is possible first.
Sure itās pretty big but here you go:
##################################################################################################
# standard house annoucements
#
# EXAMPLE:
# play annoucement
# - service: script.house_announcement
# data:
# this_message: 'The garage door is open.'
# volume: 0.6
##################################################################################################
house_announcement:
alias: House Announcement
mode: queued
trace:
stored_traces: 20
variables:
# Available TTS: tts.piper, tts.google_cloud_say
service: tts.speak # formerally using tts.google_say
speakers: media_player.master_bedroom_home, media_player.living_room_home # default speakers to play messages on
speakers_workhrs: media_player.living_room_home
sequence:
# check if silent mode selected
- condition: template
value_template: "{% if is_state('input_boolean.night_mode','off') or priority is defined %}true{%else%}false{%endif%}"
- choose:
# Play targeted messages
- conditions:
- "{{ target is defined }}"
# - condition: template
# value_template: "{% if target is defined and 'media_player' in target %} true {% else %} false {% endif %}"
sequence:
# set the volume
- service: media_player.volume_set
data:
entity_id: "{{target}}"
volume_level: "{{volume}}"
- if:
- alias: "Speak"
condition: template
value_template: "{% if service == 'tts.speak' %}true{% else %}false{% endif %}"
then:
# play the message on google home
- service: "{{service}}"
target:
entity_id: tts.piper
data:
media_player_entity_id: "{{target}}"
# - media_player.kitchendisplay
message: "{{ this_message }}"
else:
# play the message on google home
- service: "{{service}}"
data:
entity_id: "{{target}}"
# - media_player.kitchendisplay
message: "{{ this_message }}"
# Play priority messages as they're important
- conditions:
- condition: time
after: "22:00:00"
before: "07:00:00"
- condition: template
value_template: "{{ priority }}"
sequence:
# set the volume
- service: media_player.volume_set
data:
entity_id: "{{speakers}}"
volume_level: 0.7
- if:
- alias: "Speak"
condition: template
value_template: "{% if service == 'tts.speak' %}true{% else %}false{% endif %}"
then:
# play the message on google home
- service: "{{service}}"
target:
entity_id: tts.piper
data:
media_player_entity_id: "{{speakers}}"
# - media_player.kitchendisplay
message: "{{ this_message }}"
else:
# play the message on google home
- service: "{{service}}"
data:
entity_id: "{{speakers}}"
# - media_player.kitchendisplay
message: "{{ this_message }}"
# Brpadcast to workday sepakers only
- conditions:
- condition: state
entity_id: binary_sensor.workday_sensor
state: "on"
- condition: time
before: "17:00:00"
after: "07:00:00"
sequence:
# wait until announcement devices have finished playing
- wait_template: "{{ (is_state('media_player.living_room_home','idle') or is_state('media_player.living_room_home','off') or is_state('media_player.living_room_home','unavailable')) }}"
# set the volume
- service: media_player.volume_set
data:
entity_id: "{{speakers_workhrs}}"
volume_level: "{{ volume }}"
- if:
- alias: "Speak"
condition: template
value_template: "{% if service == 'tts.speak' %}true{% else %}false{% endif %}"
then:
# play the message on google home
- service: "{{service}}"
target:
entity_id: tts.piper
data:
media_player_entity_id: "{{speakers_workhrs}}"
# - media_player.kitchendisplay
message: "{{ this_message }}"
else:
# play the message on google home
- service: "{{service}}"
data:
entity_id: "{{speakers_workhrs}}"
# - media_player.kitchendisplay
message: "{{ this_message }}"
# Lower volume after 20:00
- conditions:
- condition: time
after: "20:00:00"
sequence:
# wait until announcement devices have finished playing
- wait_template: "{{ (is_state('media_player.master_bedroom_home','idle') or is_state('media_player.master_bedroom_home','off') or is_state('media_player.master_bedroom_home','unavailable')) and (is_state('media_player.living_room_home','idle') or is_state('media_player.living_room_home','off') or is_state('media_player.living_room_home','unavailable')) }}"
# set the volume
- service: media_player.volume_set
data:
entity_id: "{{speakers}}"
volume_level: 0.5
- if:
- alias: "Speak"
condition: template
value_template: "{% if service == 'tts.speak' %}true{% else %}false{% endif %}"
then:
# play the message on google home
- service: "{{service}}"
target:
entity_id: tts.piper
data:
media_player_entity_id: "{{speakers}}"
# - media_player.kitchendisplay
message: "{{ this_message }}"
else:
# play the message on google home
- service: "{{service}}"
data:
entity_id: "{{speakers}}"
# - media_player.kitchendisplay
message: "{{ this_message }}"
default:
# wait until announcement devices have finished playing
- wait_template: "{{ (is_state('media_player.master_bedroom_home','idle') or is_state('media_player.master_bedroom_home','off') or is_state('media_player.master_bedroom_home','unavailable')) and (is_state('media_player.living_room_home','idle') or is_state('media_player.living_room_home','off') or is_state('media_player.living_room_home','unavailable')) }}"
# set the volume
- service: media_player.volume_set
data:
entity_id: "{{speakers}}"
# - media_player.kitchendisplay
volume_level: "{{ volume }}"
- if:
- alias: "Speak"
condition: template
value_template: "{% if service == 'tts.speak' %}true{% else %}false{% endif %}"
then:
# play the message on google home
- service: "{{service}}"
target:
entity_id: tts.piper
data:
media_player_entity_id: "{{speakers}}"
# - media_player.kitchendisplay
message: "{{ this_message }}"
else:
# play the message on google home
- service: "{{service}}"
data:
entity_id: "{{speakers}}"
# - media_player.kitchendisplay
message: "{{ this_message }}"
Edit: There some stuff in there that needs cleaning up, but you should be able to get the idea of it all.
I can work with this. thank you
I know I keep saying this but there are also examples at the github repo for the integration.
the two that I use are fairly compact.
So if youād like to see those then go to the repo and look under the updated packages folder there.
Hi @finity. The code works well. Thanks. My previous code was a stand-along automation. This allowed me to turn sms notifications on and off when needed. Might there be a way to do something similar within your structured package yaml?
would this work for tts using a sonos speaker. ive used this setup for other tts notifications.
continue_on_error: true
action: media_player.play_media
metadata: {}
data:
cache: false
announce: false
media_content_id: media-source://tts/cloud?message={{ announcement_message }}&language=en-IE
media_content_type: music
target:
entity_id: media_player.foyer
I donāt know. Iāve never used a URL for an announcement. I only use a URL to play an MP3.
this is an example of the service I use for my Sonos speaker TTS announcement:
service: tts.cloud_say
data:
entity_id: media_player.sonos_cloud_kitchen
message: "Some message here"
my main concern since i suck at templating to a high degree is if this syntax is right to call the script
I donāt know if thatās a templatable field or not.
Have you tried it?
not yet. iāll try a zone tonight
Iām trying to make an automation that when there is a specific warning like a tornado warning it will trigger a script. If I can get it to run a script I can do anything else I would want it too based off of that.
My issue is how to make the conditional command to read if an alert is a tornado warning, or whatever.
I went through I feel like all the comments since 545 as noted by the user running the NWS Alert and tried to as best as Iām able dissect the applicable code for me to use.
I am not a programmer, more of a network guy so this has me stumped.
When I trace the automation logic it fails at condition with the failure message:
āError: In ātemplateā condition: UndefinedError: āalertā is undefinedā
Below is my automation yaml
You didnāt define alert
so you canāt use it as a condition.
Thanks for the reply, Iām using your code from your examples, where in the code is alert defined? I wasnāt able to figure that out looking over other people code here. One thing I did notice was most people are doing a sequence, and Iām trying to just do condition then action without repeats so I wasnāt sure how to differentiate the applicable pieces of code to incorporate in my use case.
You need the repeats, use my example as is and just adjust the actions.
the reason you need the repeat part is because it looks at each alert within the repeat code to check if the alert index contains the desired phrase.
otherwise you need to do some more (more complicated) coding to check each alert individually for the phrase. Which is what I was doing initially. If you want to do it like that then by all means use my old examples but I would (and did) just do as suggested above and use the repeat code and adjust the actions as needed to run your existing script.
Iām having an issue with receiving multiple notifications (every couple minutes) for the same alerts now that the Variable component is no longer used. I saw that it was referenced in this issue but I canāt see where the solution was provided: Updated [Alternative] Automations for 5.0 Ā· Issue #87 Ā· finity69x2/nws_alerts Ā· GitHub
I also noticed your Mobile App Notification mentions script.notification_pushover_message but that script doesnāt appear to be provided anywhere (Iām not using pushover).
> alias: NWS - Family Mobile App Notifications
> description: Push notifications for family devices. (family_ios_devices)
> mode: queued
> initial_state: "on"
> max: 10
> triggers:
> - entity_id: sensor.nws_alerts
> trigger: state
> conditions: []
> actions:
> - repeat:
> sequence:
> - action: notify.family_ios_devices
> data:
> message: clear_notification
> tag: NWS_{{ repeat.item }}
> for_each: >-
> {{ trigger.from_state.attributes.Alerts | map(attribute='ID') |
> reject('in', trigger.to_state.attributes.Alerts | map(attribute='ID')) |
> list() }}
> - repeat:
> sequence:
> - action: notify.family_ios_devices
> data:
> title: "NWS: {{ repeat.item.Headline }}"
> message: |
> {{ repeat.item.Description }} {{ repeat.item.Instruction or "" }}
> data:
> notification_icon: mdi:weather-lightning-rainy
> channel: WeatherAlerts
> importance: high
> color: red
> push:
> interruption-level: time-sensitive
> tag: NWS_{{ repeat.item }}
> for_each: "{{ state_attr('sensor.nws_alerts','Alerts') }}"
I just started seeing this this morning as well with the freeze warnings we are getting.
Iāll need to do some troubleshooting to see why the old alert idās arenāt being filtered. Or actually maybe they are and itās that the NWS is screwed up today. Thatās happened before.
Right.
those are just code examples that give a framework that you will need to adjust to your specific system. I use pushover for my mobile notifications. If you use something different then youāll need to adjust that part to what you use.