This is my approach for playing announcements in home speakers whenever a family member arrives home.
There is a field to leave a message to a family member.
This creates a persistant_notification that will be spoken and dismissed when a certain person arrives.
I’ve also created a google agenda for each family member in hass. Basically if there is an active event for this person, it will be announced when this person arrives. It gives the flexibility I want to implement things like garbage collection reminders and household chores.
Finally, the tts announcement code:
- id: tts_familia alias: Anunciar família trigger: platform: state entity_id: person.alexandre, person.najla, person.gabriela to: home for: minutes: 1 condition: condition: time after: 08:00:00 before: '21:00:00' action: - service: media_player.volume_set data: entity_id: media_player.som_ambiente volume_level: '0.5' - wait_template: '{{ not(is_state(''media_player.som_ambiente'', ''playing'')) }}' timeout: 00:03:00 continue_on_timeout: 'false' - service: tts.google_say data_template: entity_id: media_player.som_ambiente message: > Olá {{ trigger.to_state.attributes.friendly_name }}, são {{now().strftime('%H:%M')}}. {%- for entity_id in states.group.familia.attributes.entity_id -%} {% set parts = entity_id.split('.') %} {% if ((as_timestamp(now()) - (as_timestamp(states[parts[0]][parts[1]].last_changed))))/60> 5 %} {{ states[parts[0]][parts[1]].name }} {{ states[parts[0]][parts[1]].state.replace('not_home','está fora').replace('home','chegou') }} há {{ relative_time(states[parts[0]][parts[1]].last_changed).replace('day','dia').replace('hour','hora').replace('minute','minuto').replace('second','segundo')}}. {%- endif -%} {%- endfor %} A temperatura está em {{ states('sensor.yr_temperature') | round(0) }} graus. {% for notifs in states.persistent_notification -%} {%if trigger.to_state.attributes.friendly_name == notifs.attributes.title -%} {{ notifs.attributes.message }} {%- endif %} {%- endfor -%} {% for cal_events in states.calendar -%} {%if 'hass_' + trigger.to_state.attributes.friendly_name.lower() in cal_events.attributes.friendly_name-%} {%if cal_events.state == 'on' -%} {{ cal_events.attributes.message }} {%- endif %} {%- endif %} {%- endfor -%}
It also say the whereabouts of other family members, and the external temperature.
ToDo:
- Announcements queue: currently when two family members arrive together, only one get announcements. I thought the action to wait the speaker status “not playing” would fix that, but unfortunately is not working.
- Deal with multiple active events in calendar
- When saying the whereabouts of the family, combine the status for people that left or arrived together.
- Identify other useful info to include in the announcements message.