I have a scenario that i would like to get automated, and im having some issues.
I have a group.family with two persons entities. And i have a automation that does a bunch of things when the first person leaves and comes home. This works fine, however i dont “know” who left home, and who came home if that makes sense. I tried searching for forum but i could not get it to work.
There is 3 possible scenarios
We both leave home at the same time (same car)
She leaves first, i stay home
I leave first, she stays home
Same for when the first person come home (after everyone has left)
for example, we both came, google home says welcome home henrik and carina (our names).
If she come home and im away, welcome home carina
and if i come home, it greets me.
This should be easy, but i cant get it to work. I tried using template sensors, and value templates, but seems im missing something.
heres the trigger
platform: state
from: home
to: not_home
entity_id: group.familie
for:
minutes: 1
id: '1631530178979'
alias: Ny automasjon
description: ''
trigger:
- platform: state
entity_id: group.familie
to: home
for:
seconds: 30
condition: []
action:
- service: tts.cloud_say
data:
entity_id: media_player.nest_hub
message: >
{% set name = 'Henrik' if is_state('device_tracker.henrik_iphone' ,
'home') else 'Carina' %}
Velkommen hjem {{ name }}.
{{ (
'Har du hatt en fin dag?',
'Håper alt er bra',
'Jeg er glad du har kommet hjem'
)|random }}
mode: single
But i dont think that will work when we both come home
yep it works, thank you. but i need to figure out how to clean up what tts announce, now it just says device tracker names, my goal is to get random greetings based on who came home, if that makes sense. So
Welcome home, my name, random greeting
Welcome home, her name, random greeting
Welcome home, both names, randoming greeting
My example above it works, but im not familiar how to use it in your example
service: tts.cloud_say
data:
entity_id: media_player.nest_hub
message: >
Velkommen hjem
{{ states | selectattr('entity_id', 'in',
state_attr('group.familie','entity_id')) | selectattr('state','in',['home'])
| list | map(attribute='name') | join(', ') }}.
{{ (
'Har du hatt en fin dag?',
'Håper alt er bra',
'Jeg er glad du har kommet hjem'
)|random }}
just a small thing i need to fix, if we both come home, it will say welcome home carina henrik, i need to figure out how to get an “and” if we both have state home.
From the documentation:
Similarly with a device tracker, when any member of the group is home then the group is home.
So, if Carina comes home while you are away, the group state will change to home (it will trigger the automation). Later on when you come home, it will no longer triggering the automation again as there is no state change from not_home to home.