Home/away automation when the last one leave

Hi,

im struggeling with geolocation / zones in automation. I want to shut off some entities when the last one leaves the house.

How do i set the triggers?

The zones and persons are available. But i have no idea how i tell HA to start when both persons away.

Thanks for your assictance.

Here’s how I do it. This works for two people but if you have more, just keep adding entities as triggers/conditions. There is probably a more elegant way to handle multiple people, but this works and I’ve never had a problem. The key for the “last person” is the triggers have to be conditioned with every person/device tracker you want to monitor to be NOT home.

  - id: disable_alarm_away
    alias: 'Disable Alarm Away'
    trigger:
      - platform: zone
        entity_id:
          - person.b
          - person.r
        zone: zone.home
        event: enter
    condition:
      - condition: state
        entity_id: alarm_control_panel.ha_alarm
        state:
          - 'arming'
          - 'armed_away'
    action:
      - service: alarm_control_panel.alarm_disarm
        data:
          entity_id: alarm_control_panel.ha_alarm
          code: !secret alarm_code
      - service: alarm_control_panel.alarm_disarm
        data:
          entity_id:
            - alarm_control_panel.aarlo_m
            - alarm_control_panel.aarlo_o
  - id: enable_alarm_away
    alias: 'Enable Alarm Away'
    trigger:
      - platform: zone
        entity_id:
          - person.b
          - person.r
        zone: zone.home
        event: leave
    condition:
      - condition: state
        entity_id: alarm_control_panel.ha_alarm
        state: 'disarmed'
      - condition: not
        conditions:
          - condition: state
            entity_id: person.b
            state: home
      - condition: not
        conditions:
          - condition: state
            entity_id: person.r
            state: home
    action:
      - service: alarm_control_panel.alarm_arm_away
        data:
          entity_id: alarm_control_panel.ha_alarm
          code: !secret alarm_code
      - service: alarm_control_panel.alarm_arm_away
        data:
          entity_id:
            - alarm_control_panel.aarlo_m
            - alarm_control_panel.aarlo_o
2 Likes

You need to figure out a bulletproof way of determining when each individual is away from the home. There are some ways to do it regarding using the person’s cell phone but it is more reliable with android than iphone and that is not bulletproof (can’t get iphone location when it is asleep, person might leave the phone at home). Figure out a way of determiing for sure for each person, when they are not home. Once you have that as a person entioty in home assistant (you add people manually to start with, then that is altered by what I was specifying before). Then , you can make a group helper in homs assistant that you would use in your automation (if true etc). A group helper returns true if all items in the group are of the same value (home or away, on or off, etc.). It’s not the perfect answer for you but that is reality as far as I see it, hope that helps you get started. I’ve been looking for some kind of foolproof GPS gizmo to put on my and my wifes keychain to resolve the issue myself but have yet to even find anything (as we NEVER leave the home without our keys)!

I’ve been using these two automations and two iPhones for nearly 5 years. Never had a problem with the GPS tracking, except because our house/neighborhood was so new that GPS reporting was a little off until more WiFi access points were around us to provide better triangulation. These are probably two of my more robust automations. We take our keys with us because they’re on the same ring as the car keys, but I can’t tell you the last time I actually used a key to enter my house, except when we were building the house and just moved and I hadn’t yet setup HA again. I have automations based on the alarm status and when it is armed, the garage door locks up, when it is disarmed, the garage door unlocks and we walk right in.

Thanks, we also uses iPhones an the HA Companion App. After using squirtbrnrs script i see you only have to use comma seperation in the visuell editor. :wink:

Some things can be so easy if you know how.

2 Likes

The zone.home state is a value indicating the number of people in that zone. If you want to trigger an automation to run when the last person leaves, try:

trigger:
  - platform: state
    entity_id:
      - zone.home
    to: "0"

If you want to trigger something when the first person comes home, try:

trigger:
  - platform: state
    entity_id:
      - zone.home
    from: "0"

One of the advantages to this is that you don’t have to remember to add entities if you add people to the zone.

22 Likes

I stand corrected and still have a lot to learn!

Hi there,

i tried like pkscout suggested an it works fine.

Thanks a lot

Just to add more options, you can use numeric_state as well:

  - alias: ha_home_mode
    id: ha_home_mode
    trigger:
      - platform: numeric_state
        entity_id: zone.home
        above: 0
    action:


  - alias: ha_away_mode
    id: ha_away_mode
    trigger:
      - platform: numeric_state
        entity_id: zone.home
        below: 1
    action:

7 Likes

this is exactly what i needed, thank you! i made a template using same thought process.

      - name: "Home Empty"       
        state: >
          {{ is_state('zone.home', '0')
           }} 
1 Like

Here’s how I do it.

- alias: "ComfoAir Q350 away"
  mode: single
  trigger:
    platform: zone
    entity_id:
      - person.1
      - person.2
      - person.3
      - person.4
    zone: zone.home
    event: leave
  condition:
    - condition: and
      conditions:
        - condition: state
          entity_id:
            - person.1
            - person.2
            - person.3
            - person.4
          state: not_home
  action:
    - service: script.turn_on
      target:
        entity_id: script.ComfoAir_Q350_away

Hey all,

Reading this post and trying to get automations to work based on the home zone and not having luck.

They work when I trigger the automation, but they do not work when I actually leave my home.

Any ideas?

Example:

alias: Alarm Arm Away
description: Arm the alarm
trigger:
  - platform: numeric_state
    entity_id:
      - zone.home
    attribute: persons
    below: 1
action:
  - service: alarm_control_panel.alarm_arm_away
    metadata: {}
    data: {}
    target:
      entity_id: alarm_control_panel.aqara_hub_m2_712e_security_system
mode: single

What happens is the automation doesn’t actually trigger, but the app shows me as “not_home”.

Any help appreciated!

remove the attribute line, you need to test the state itself. The person attribute holds names.

For cases like these it is always wise to check the developer tools and look at the state and the attributes.

Thank you I will try this when I leave the house:

alias: Alarm Arm Away
description: Arm the alarm
trigger:
  - platform: numeric_state
    entity_id:
      - zone.home
    below: 1
action:
  - service: alarm_control_panel.alarm_arm_away
    metadata: {}
    data: {}
    target:
      entity_id: alarm_control_panel.aqara_hub_m2_712e_security_system
mode: single