Help with automation coming home/leaving home

I have two automations.
One for coming home:

- id: erster_kommt_nach_hause
  alias: Erste Person kommt nach Zuhause
  initial_state: on
  trigger:
  - platform: state
    entity_id: group.alle_personen
    to: 'home'
  action:
  - .....

And one for leaving home:

- id: letzter_verlasst_zuhause
  alias: Letzte Person verlässt Zuhause
  initial_state: on
  trigger:
  - platform: state
    entity_id: group.alle_personen
    from: 'home'
  action:
  - .....

This is working.

But if I drive and touch the border of the home zone, this automation are triggering. First the coming home automation and shortly after the leaving home automation.
Is there a way that this automations only trigger, if I am at least one minute inside/outside this zone?

1 Like
  trigger:
  - platform: state
    entity_id: group.alle_personen
    to: 'home'
    for: 
      minutes: 1

Thanks @tom_l for your answer.
This would only work for the coming home automation.
This don‘t work for the leaving home automation.
The option for requires to: state
Also the automation would trigger every time I’m touching the border of the zone +1 minute.

- condition: template
       value_template: >
           {{ (as_timestamp(now()) - as_timestamp(states.group.alle_personen.last_changed)) > 60 }}

Add this condition to both automations. Trigger will only take place when the status of ‘group.alle_personen’ has not changed in the last 60 seconds

2 Likes

Thank you @haaghala.
Can you also please tell me, how this condition must look like if I have the following trigger?

  trigger:
  - platform: state
    entity_id:
      - person.1
      - person.2
      - person.3
    to: 'home'
  trigger:
  - platform: state
    entity_id:
      - person.1
      - person.2
      - person.3
    to: 'home'
  condition:
  - condition: template
    value_template: >
      {{ (as_timestamp(now()) - as_timestamp(states.group.alle_personen.last_changed)) > 60 }}
  action:
  ...etc

Thanks again @tom_l. But this triggers if the group change the state, not the single person.

No it doesn’t. it triggers on the individual people:

  trigger:
  - platform: state
    entity_id:
      - person.1
      - person.2
      - person.3

The condition is on the group.

Why did you change from the group trigger?

Will this work, if person.1 is at home and person.2 is coming home?

Group change will only detect when the first person of the group comes home. Do you need to trigger for every single person coming home?

Yes please.

Why not to use zones? I have this:

alias: "Otwórz bramę gdy samochód wjeżdża do strefy Brzezie"
initial_state: true
trigger:
  platform: zone
  entity_id: device_tracker.opel
  zone: zone.brzezie
  # Event is either enter or leave
  event: enter # or "leave"
action:
  service: switch.turn_on
  data_template:
    entity_id: switch.gate

Because that would still suffer from the boundary problem in the original post.

Try this:

trigger:
  - platform: state
    entity_id:
      - person.1
      - person.2
      - person.3
    to: 'home'
condition:
  - condition: template
    value_template: "{{ (as_timestamp(now()) - as_timestamp(trigger.from_state.last_changed)) > 60 }}"
action:
1 Like

Dota player? :wink:

1 Like