Playing Alexa Echo Announcments, TTS Messages, or Sounds only in rooms that are occupied. BLUEPRINT

Who is this blueprint for?

  • This blueprint is for anyone that has Amazon echo devices and only wants to programmatically play Announcements, TTS messages, and sounds on those devices in which the room is occupied.

What does this blueprint do?

  • The blueprint will create a new entity group with a name that is based on your 'Room Name’1 input. This group will be named ‘group.room_name_occupancy_echos’.

    1

  • This new group will then be updated each time your selected Occupancy Sensor’s2 state changes. The contents of the new group will either contain all of your selected 'Echo Devices’3 when the occupancy sensor is ‘On’ or it will be empty when the occupancy sensor is ‘Off’. You can then use this group in other automations to play echo announcements, tts messages, or sounds only when that room is occupied.

    2

    3

  • For example, you may simply replace your echo device entity with this new group entity in any automation you are running those services. But wait, there’s more…

Unleash the Power:

  • The true power of this blueprint comes after you have created all of your room occupancy echo groups; where you can then create your own group (NOT using this blueprint) that contains the entities of all the echo groups you have created. You might assign this very powerful group a name ‘All Rooms Occupancy Echos’. This new ‘All Rooms Occupancy Echo Group’ will allow you to play Announcments, TTS messages, and sounds on any echo device in your entire house, but only in those rooms that are currently occupied. No longer will you hear six different devices ‘echoing’ (no pun intended) throughout your house from rooms that aren’t occupied.

  • The ‘All Rooms Occupancy Echos’ group is the only group I personally use in my Amazon echo announcements.

Prerequisites:

  • Must have Amazon echo device entities exposed, via the alexa media player integration for example.

  • Must have a single sensor, switch, or input_boolean setup per room that contains an echo device which will signal when that room is occupied. There are numerous ways to accomplish this. You could technically use a single motion sensor, but keep in mind most motion sensors time-out (or return to an ‘off’ status) in less than 30 seconds, which is typically too short of time to accurately reflect the correct occupancy status of a room in most scenarios.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Set Echo Group Based On Room Occupancy
  description: >
    Set an Echo Group based on a Room's Occupancy
    
    
    References:
    
    - https://www.home-assistant.io/integrations/group/
    
    
    Example name to give an automation created by this blueprint:
    
    - Set Living Room Occupancy Echo Group
    
    
    Who is this blueprint for?
    
    - This blueprint is for anyone that has Amazon echo devices and only wants to programmatically
    play Announcements, TTS messages, and sounds on those devices in which the room is occupied.
    
    
    What does this blueprint do?
    
    - The blueprint will create a new entity group with a name that is based on your 'Room Name' input.
    This group will be named 'group.room_name_occupancy_echos'.
      
    - This new group will then be updated each time
    your selected Occupancy Sensor's state changes.  The contents of the new group will either contain all
    of your selected 'Echo Devices' when the occupancy sensor is 'On' or it will be empty when the
    occupancy sensor is 'Off'.  You can then use this group in other automations to play echo announcements,
    tts messages, or sounds only when that room is occupied.
      
    - For example, you may simply replace your echo device entity with this new group entity in any
    automation you are running those services. But wait, there's more...
    
    
    Unleash the Power:
    
    - The true power of this blueprint comes after you have created all of your room occupancy echo groups;
    where you can then create your own group (NOT using this blueprint) that contains the entities of all
    the echo groups you have created.  You might assign this very powerful group a name 'All Rooms Occupancy Echos'.
    This new 'All Rooms Occupancy Echo Group' will allow you to play Announcments, TTS messages, and sounds on
    any echo device in your entire house, but only in those rooms that are currently occupied.  No longer will you hear
    six different devices 'echoing' (no pun intended) throughout your house from rooms that aren't occupied.
      
    - The 'All Rooms Occupancy Echos' group is the only group I personally use in my Amazon echo announcements.
    
    
    Prerequisites:
    
    - Must have Amazon echo device entities exposed, via the [alexa media player]
    (https://github.com/custom-components/alexa_media_player/wiki) integration for example.
      
    - Must have a single sensor, switch, or input_boolean setup per room that contains an echo device which
    will signal when that room is occupied.  There are numerous ways to accomplish this.  You could technically
    use a single motion sensor, but keep in mind most motion sensors time-out (or return to an 'off' status)
    in less than 30 seconds, which is typically too short of time to accurately reflect the correct occupancy
    status of a room in most scenerios.
    
    
    Removal:
    
    - Deleting an automation created by this blueprint will automatically remove that occupancy group on the next
    home assistant startup.
      
  domain: automation
  input:
    room_name:
      name: Room Name
      description: >
        Example: Living Room
    occupancy_sensor:
      name: Room Occupancy Sensor
      description: >
        Select a single sensor used to determine if the room is occupied. Either use one sensor or a 
        single group containing multiple sensors.
      selector:
        entity:
          #domain: binary_sensor
    echo_devices:
      name: Echo Devices
      description: Select the echo device(s) for this room.  Multiple echos seperated by comma.
      selector:
        entity:
          #domain: media_player

trigger:
  - platform: state
    entity_id: !input occupancy_sensor
  - platform: homeassistant
    event: start

variables:
  # Make inputs available as a script level variable
  sensor_var: !input occupancy_sensor
  devices_var: !input echo_devices
  room_name_var: !input room_name

action:
  - service: group.set
    data:
      object_id: "{{ room_name_var | lower | replace(' ','_') }}_occupancy_echos"
      name: "{{ room_name_var | title }} Occupancy Echos"
      entities: |
        {% if is_state(sensor_var, 'on') %}
          {{ devices_var }}
        {% else %}
          []
        {% endif %}
mode: single
1 Like

Smart, thank you!
Is working with lights, also.

1 Like

Hi - just stumbled across this and its fantastic exactly the use case I’ve been struggling with. Sorry for the what must be very basic question but I’m still finding my way in Home Assistant - once you’ve used the blueprint how do you create this master group of groups I’m at that stage and have no idea how to do it?
Thanks
Andy

Great question. You will need to add a new group in your config using YAML. Unfortunately, the new way of creating groups as a helper from the UI does not support creating a group from other “Old Style” groups. Take some time and read the ‘Old style groups’ section located near the bottom of the page here —> Group - Home Assistant. You will need to be comfortable creating the new group using YAML by adding those groups created by the blueprint as entities to this new “MASTER” group. Hope this helps.

Thanks - unfortunately YAML is very much something I’m trying to learn and having read that I think I get the theory but have no idea on the practice of actually how to do that and after a couple of weeks trying I am going to say its beyond me - thanks for the blueprint though I’m definitely going to keep it and maybe down the road I’ll have figured things out enough to make it work

No worries. If you already got to the point where the blueprint automation created your initial “groups”, send me those group entity id’s and I’ll write the YAML for you.