#Issue with trigger zone.home and number of people

29 messages · Page 1 of 1 (latest)

fast willow
#

Hello,

I want to make an automation with “zone.home” as trigger, to know if someone is home or not.

The problem is that “zone.home” doesn't seem to return the number of people at home, but the name of the people present.

For example, here's the Yaml code for one of the integrations.

description: “”
trigger:
  - platform: state
    entity_id:
      - zone.home
    from: 1 or 2
    to: “0”
condition: []
action:
  - metadata: {}
    data:
      code: “1901”
    target:
      device_id: 93e83aa7c1271b24047d4ee392fc5e70
    action: alarm_control_panel.alarm_arm_away
  - metadata: {}
    data: {}
    target:
      floor_id:
        - rez_de_chaussee
        - floor_01
    action: light.turn_off
mode: single

On my dashboard, the badge with “zone.home” shows me the number of people present.

pastel warrenBOT
#

@fast willow To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

fast willow
#

Issue with trigger zone.home and number of people

kind spade
#

from: 1 or 2

Not sure where you got that from but that's not valid syntax

surreal dove
#

I have a good idea where...

#

the 1 or 2 is not a number. This must be a number.
"0" is not a number, but HA might cheat and make it a number for you. It should be a number.

oops

kind spade
#

this is a state trigger, everything must be string, not number

surreal dove
#

Wjhy does this work?

condition: 
  - condition: numeric_state
    entity_id: zone.home
    above: 0
kind spade
#

numeric_state => numbers
state => strings

surreal dove
#

The state of a zone is a number, which represents the number of persons that are currently in a zone.

#

I actually don't know, but these things te;; me it's a number.

kind spade
#

it's a string of a number 😂

#

all states are always strings in HA

surreal dove
#

ok. it has to be string because it's a state, and HA doesn't care and just fixes it wherever it is used.

kind spade
#

from: "1" is what the visual editor creates if you put 1 in the from box.
from: 1 might be accepted by some internal casting, not positive

surreal dove
#

I get it

kind spade
#

if you're using attributes you can get tripped up, since attributes might not be strings, and 1 != "1"

surreal dove
#

ok

kind spade
#

anyway, back to the OP, try:

from:
  - "1"
  - "2" 

instead

#

or you can use numeric_state trigger instead, and go with below: 1

fast willow
#

It's OK like this ?

alias: Home Leaving
description: ""
trigger:
  - platform: state
    entity_id: zone.home
condition:
  - condition: numeric_state
    entity_id: zone.home
    below: 1
action:
  - metadata: {}
    data:
      code: "1901"
    target:
      device_id: 93e83aa7c1271b24047d4ee392fc5e70
    action: alarm_control_panel.alarm_arm_away
  - metadata: {}
    data: {}
    target:
      floor_id:
        - rez_de_chaussee
        - etage_01
    action: light.turn_off
mode: single
kind spade
#

looks ok.
slightly less than optimal as you could have just used a numeric_state trigger, and no conditions. but I think that works

fast willow
#

It's work

#

How i use only numeric state trigger ?

kind spade
#
trigger:
  - platform: numeric_state
    entity_id: zone.home
    below: 1
condition: []
action:
  ...
fast willow
#

It's look like OK, HA doesen't show me error message.
But the annoying thing about automation is that you can't run a test on the trigger to see if the code is correct.
With conditions, however, you can.

kind spade
#

You can test it via developer-tools/states

#

if you go there and force zone.home to 0, it will trigger the automation