Severe Weather Alerts from the US National Weather Service

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?

I have an example posted here.

2 Likes

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.

2 Likes

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.

2 Likes

I can work with this. thank you

1 Like

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.