Problem with automation (Not Home)

Hi,

I have a problem with automation. It does not trigger, as expected. I am wondering what is wrong. I suppose the problem is in the “not_home” part of the automation, and perhaps when I move to work, the “not_home” does not trigger as supposed. But I’m not sure. Thanks for the support

alias: "[TV PLUG] Turn off TV plug when no one is home for 5 minutes"
description: ""
triggers:
  - entity_id:
      - person.martyna
      - person.przemek
    to: not_home
    trigger: state
    for:
      hours: 0
      minutes: 5
      seconds: 0
conditions:
  - condition: state
    entity_id: person.przemek
    state: not_home
  - condition: state
    entity_id: person.martyna
    state: not_home
  - condition: state
    entity_id: input_boolean.guest_mode
    state: "off"
actions:
  - target:
      entity_id: switch.tv_plug
    action: switch.turn_off
    data: {}
mode: restart

Hi Pe,

First question, why are you asking the same question twice? Once as a trigger, another as a condition?

Second, if you look at the state of zone.home, when it shows 0, there are 0 people home and when it the state is 2, there are 2 people home.
Therefore look for 0 as the state of zone.home for 5min and turn your switch off.

Also this might be part of the problem…
Automations #1: trigger only fires when it changes from not true to true.

He is not.
The first section is the trigger and the next one is the condition.
martyna might be the trigger, but the trigger sektion do not check przemek, because it just needs to be triggered.
The condition section will then check if both martyna and przemek is away.

2 Likes

What device trackers have you set up for the persons?
Remember that to use just the tracking in the companion apps, then you need external access to your HA.
The trackers in the companion app is based on either WiFi or GPS coordinates and nearly always WiFi is the first on to triggered, since GPS can not be that precise without having many false positives.
The problem with the WiFi trigger is that when the trigger is occurring, then it is because the connection to the WiFi have been lost, but that also means that it can’t use WiFi to send the info back to the server about being away.
An alternative way, like VPN, NabuCasa account, portforwarding or other means are necessary.

Would be easier to create the group of people and then use state of group as trigger, without any need for condition. I use this logic for several of my presence based automations and it works perfectly

  - id: "auto_arm_alarm"
    alias: Auto Arm Alarm
    initial_state: true
    trigger:
      - platform: state
        entity_id:
          - group.family
        from: "home"
        to: "not_home"
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.alarm_notifications

yes, correct. you are right. it will simplify but do not think it will solve the issue

companion apps, with external access to HA - nabu casa. And we can both out of home (eg. in other locations - our workplaces) but still it does not go off. I observe when we are both “Away”, so not in a specific location (as a specific workplace), it seem to work. but it makes no sense to me:)

The problem is tht, besides home, a person entity can have multiple states. So if you are in a zone named Work, the state is not what you mentioned in the trigger. It is better to test from: home because then it does not matter where to.

But as stated above, for last person leaving home or first person coming home, test the state of zone.home for from: 0 or to: 0 and you won’t have to name any person individually. Only one trigger required, and no extra conditions needed.

1 Like

Hi,

I tried to change the automation to what you suggested, or at least i think so, but I still have the same issue. Perhaps, I did something wrong. I appreciate any support, thanks

alias: "[TV PLUG] Turn off TV plug when no one is home for 5 minutes"
description: ""
triggers:
  - entity_id:
      - zone.home
    attribute: persons
    to: "0"
    trigger: state
    for:
      hours: 0
      minutes: 5
      seconds: 0
conditions:
  - condition: state
    entity_id: input_boolean.guest_mode
    state: "off"
actions:
  - target:
      entity_id: switch.tv_plug
    action: switch.turn_off
    data: {}
mode: restart

Remove this entire line. The persons attribute holds persons names. You should test the state, which is a number of people.

1 Like