Enable Alarm on 0 people home, not triggering when it hits 0

So I have zone with 2 persons in it, each person has a Unifi Device Tracker. This seems to work great, when I leave the house the Zone changes from 2 to 1. When my wife also leaves it changes from 1 to 0.

The log shows “Home changed to 0”

My automation works if triggered manually but not automatically.

Trigger conditions:

platform: state
entity_id:

  • zone.home
    for:
    hours: 0
    minutes: 0
    seconds: 0
    attribute: persons
    to: “0”

and same for when the zone changes to 1 or 2:

platform: state
entity_id:

  • zone.home
    from: “0”

I feel ashamed asking for help on such a simple matter while I’ve done crazy hard things in HA before :confused:

Any clue in the right direction would greatly help me.

First please repost your yaml using the preformatted code tool YAML is very picky about spacing and indents so we need to see how you did that. The preformat tool preserves that sowne can tell what’s going on.

Did you run a trace on the automation. What does it say?

Beside the code formatting (as mentioned in the previous post)…

What’s the “for:” for?
Why using attribute “persons”? Isn’t it the state you are interested in?

1 Like

Hi, I made the automation in the editor mode, so the yaml indentation is ok.

When I run it manually it works and the trace shows fine. It never fires automatically so I don’t know how to trace that.

That is a good point, let me try without the attribute.

I understand that may he the case but the fact of the matter is it’s near impossible to read on a mobile device. Please go back and reformat the post

Then we can read your trigger which should look something more like this

description: "absolute basic zone automation"
mode: single
trigger:
  - platform: numeric_state
    entity_id:
      - zone.home
    above: 0
condition: []

That said you have a numeric state that waits for 0?

And I the second one you have a trigger from 0?

This is the entire Yaml, without the pincode offc.

alias: Alarm on when away
description: ""
trigger:
  - platform: state
    entity_id:
      - zone.home
    for:
      hours: 0
      minutes: 0
      seconds: 0
    to: "0"
    attribute: persons
condition: []
action:
  - service: alarm_control_panel.alarm_arm_away
    metadata: {}
    data:
      code: "****"
    target:
      entity_id: alarm_control_panel.alarmo
mode: single

I have removed the persons attribute, per suggestion from @ToHi and will test when I get home now

You don’t need to be home to test it.
Just open the developer tools and set yourself as home, then not_home again.

2 Likes

Neat, learned something extra.

Can confirm this now works with the persons attribute removed!

Much appreciated for all the help!

If it still does not work in the actual test (not the dev test), I found that in my instance, I needed to add a short delay, like 30 seconds, for my ‘away from home’ setting to work. However, I’m using mine based on tracking MAC/IP addresses from my router, so that could be the reason as well, since it needed time to age out of the table.

In general, having a little bit of a delay might help in case the person’s tracking device goes in and out of range quickly.