Struggling with configuring presence automation (who is leaving, coming home)

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

then the other is from not_home to home.

Try this

- alias: When home
  trigger:
    platform: state
    entity_id: group.familie
    from: "home"
    to: "not_home"
    for:
      minutes: 1

I dont follow, the trigger is fine, but i want the action card to be specific for which person that comes home.

So if i come home, annouce my name, if wife home, say her name from tts, and if we both come home, announce both

oh … misunderstood question, i thought your trigger dont work. Let have a look a data template.
try something like this

  action:
    - service: notify.xxxx
      data_template:
        title: "Test template"
        message: > 
          {{ states | selectattr('entity_id', 'in', state_attr('group.familie','entity_id')) | selectattr('state','in',['not_home']) | list | map(attribute='name') | join(', ') }}

the template will out the name of the entity_id the member of the group with state “not_home”

Will test, i did something like this


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

action:
  - service: tts.cloud_say
    data:
      entity_id: media_player.nest_hub
      message: >
          {{ states | selectattr('entity_id', 'in', state_attr('group.familie','entity_id')) | selectattr('state','in',['home']) | list | map(attribute='name') | join(', ') }}

see if that work

2 Likes

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

if it announce device name, set [ friendly_name] of device_tracker.henrik_iphone to “Hendrik”

1 Like
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 }}

yep this worked very good. thank you alot!

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.

the join statement

join(', ')

join('and ')
1 Like

Have you checked the behavior of Person Group?

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.

I understand that part, and it works fine, it just the action card i had trouble with, but it works fine now :slight_smile:

thank huu you are a lifesaver. Everything working great now. thanks again

Cheers, glad it worked.