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.

3 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.

29 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:

9 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

Hi all,

I’m having a bit of bother with this… well, I think I am… let me try to explain.

first here is my automation

- id: '1744057021494'
  alias: Open Blind after sunrise and 10am if nobody home
  description: ''
  triggers:
  - trigger: sun
    event: sunrise
    offset: 00:30:00
    id: sunrise
  - trigger: time
    at: '10:00:00'
    id: 10am
  conditions:
  - condition: trigger
    id:
    - sunrise
    - 10am
  - condition: numeric_state
    entity_id: zone.home
    below: 1
    attribute: persons
  actions:
  - action: esphome.blind_stair_control_servo
    data:
      level: -12
  mode: single

My problem is that there are two of us in the house, but zone.home only shows a numerical value of 1 even if both of us are home, also if either one of us leave then is shoes a value of 0. Am I missing something?

what I want to achieve is if both of us are out then the blind will open as long as it is after 10am and after sunrise, Ideally I’d like it to be triggered at 10am, 30 mins after sunrise and when the last person leaves the house (just in case we have forgotten to open the blind). is this possible? or would I be better making 3 different automations?

thank you for your help and time

Robin

Remove ā€˜attribute: persons’ from your automation.

If that still doesn’t fix it, you need to figure out why your zone is only reporting 1 person. What device trackers are you using?

Perfect thank you! a small important detail that I overlooked, I only had one person set up which is why it only counted one. sorted that and it’s all working perfectly.

thanks :slight_smile:

1 Like

using the ā€œbelow: 1ā€ count will only work if you do not have any kiosk or in my case kids ipads. I had forgotten about this and could not get it to trigger, then looked at my zone.home stats and saw 2 of them.

we use a kiosk mode tablet on the wall and kids ipads so they can go hog wild on playing with their color light bulbs and ceiling fan… so those devices never leave the house.

No. Just create a separate HA user for these devices and make sure there’s no associated device trackers for that user

true… that can be done.
But I’ve got young kids and they love the challenge of misplacing devices. Yeah, I could use Find my iPhone/iPad for apple devices instead of HA.

lots of ways to skin this cat