Trigger for Automation when nobody is home

Hi folks,

I am trying to wrap my head around this and I am stuck :slight_smile:

What I want to achieve:
When nobody is home for 10 mins several actions should fire. I know how to to that for individuals but I don’t know how to program a smart trigger that only fires when all members of the family have left home.

The logic I have in mind is this:

If all members of group “Family” have left the house for 10 minutes and have left the “nearby zone” then:

  • activate this
  • do that

How do I do that?

trigger:
  - platform: state
    entity_id: zone.nearby_zone
    to: 0
    for:
      minutes: 10
1 Like

Thanks @finity,

I used your input to write following:

I am checking after couple of minutes if we left the nearby and home zone before the activation of camera surveillance is triggered.

alias: Camera - activate when nobody is home
description: Arm the camera
trigger:
  - platform: state
    entity_id: zone.home
    to: "0"
condition: []
action:
  - delay:
      hours: 0
      minutes: 12
      seconds: 0
      milliseconds: 0
  - condition: state
    entity_id: zone.home
    state: "0"
    for:
      hours: 0
      minutes: 10
      seconds: 0
  - condition: state
    entity_id: zone.in_der_nahe
    state: "0"
    for:
      hours: 0
      minutes: 5
      seconds: 0
  - service: alarm_control_panel.alarm_arm_away
    data: {}
    target:
      entity_id: alarm_control_panel.blink_home
  - service: notify.mobile_app_iphone
    data:
      message: "Main entrance camera active since nobody is at home"
      title: "Camera active"
mode: single
1 Like

Depending on what you consider nearby this could mean the alarm does not go on when you leave.
If nearby zone could be a stop at the local store then you could be nearby and thus the alarm does not activate as you leave.
I understand that you don’t want the alarm to turn on when it’s unnecessary but these conditions you add here could mean the alarm does not turn on at all when it should.

yes, that is my situation here (shop nearby), however I wanted to prevent the alarm to go on/off to often since its battery driven.
Do you have any other suggestion to narrow the risk (like you also described it well) down?

You need to think about this if this fits your setup.
I assumed your home zone is inside the nearby zone and when you leave nearby zone going home you enter home zone without coming to an area not defined in home or nearby zone.

This will look at the for just as finity suggested in the first place and then if you are in nearby zone wait up to 20 minutes to see if you leave nearby zone (this could be increased if you need).
If you leave nearby zone it makes sure you did not go back home.
If you left home zone and nearby zone in less than 10 minutes you get to the else part, that is activate alarm.

alias: Camera - activate when nobody is home
description: Arm the camera
trigger:
  - platform: state
    entity_id: zone.home
    to: "0"
    for:
      minutes: 10
condition: []
action:
  - if:
      - condition: numeric_state
        entity_id: zone.in_der_nahe
        above: 0
    then:
      - wait_for_trigger:
          - platform: state
            entity_id:
              - zone.in_der_nahe
            to: "0"
        continue_on_timeout: false
        timeout:
          minutes: 20
      - condition: state
        entity_id: zone.home
        state: "0"
      - service: alarm_control_panel.alarm_arm_away
        data: {}
        target:
          entity_id: alarm_control_panel.blink_home
      - service: notify.mobile_app_iphone
        data:
          message: Main entrance camera active since nobody is at home
          title: Camera active
    else:
      - service: alarm_control_panel.alarm_arm_away
        data: {}
        target:
          entity_id: alarm_control_panel.blink_home
      - service: notify.mobile_app_iphone
        data:
          message: Main entrance camera active since nobody is at home
          title: Camera active
mode: single

Holy s* :slight_smile:

Thanks much. Will test this and provide feedback. I’ll get the logic and this should work. My home zone is also inside nearby zone.

I don’t have a nearby zone. But one thing I didn’t think about, when you are home, are you also nearby?
What does the nearby also 1 since you are within it or are you only considered home?

When I am home I am inside the nearby zone (physically). However, if I check the state in HA, then I am only home (state = 1), but not nearby (state = 0). Does this require any code/logic change?

No. This is what I thought

1 Like