For my Home Zone I see people entering/exiting with an integer (0 for everyone out, 1+ for someone back) and it works as expected, but I have a passive zone which does not seem to want to change from 0 ever…
Does anyone know how to resolve this?
For my Home Zone I see people entering/exiting with an integer (0 for everyone out, 1+ for someone back) and it works as expected, but I have a passive zone which does not seem to want to change from 0 ever…
Does anyone know how to resolve this?
Passive zones are not part of the zone detection
Really? What’s the point in them then?
It says that they don’t appear in the UI (which is absolutely needed for massive zones) but surely a zone needs to detect else it’s useless?!
I’m still confused - I want to use it in an automation?
I want an automation when somebody exits the passive zone? I don’t see how the zone can trigger anything without tracking people?
Right, but are you tracking it on the person based on the persons state? How are you currently counting people in zones?
If your person has gps coords, then a simple zone trigger will work.
trigger:
- platform: zone
entity_id: person.vaderag
zone: zone.my_passive_zone
event: leave
Okay, I think I’m with you
On all my other zones I’ve used a change of state of the zone itself, but to use the passive zone I need to base it on the person…
(I’m using Node Red but logic)
Ah, I’m not familiar with node red. I believe you’re going to have to make a template sensor in order to utilize the node-red zone triggers.
Also, this post eludes to there being a zone node and that seems to be what I would expect the zone trigger to be.
Yeah - I think I can figure it out - I actually didn’t know about that Zone node so that’s handy, but I don’t think it’s that useful with passive zones because…
The problem with the way that passive zones appear to need to be handled is that it can only be based on a single user
What I would like to do is base it on the zone being empty or 1+ people (which is why I was using the zone or the person)
Unless I’m missing something then I think this will need to be
Person 1 leaves zone
Check if person 2 is in the zone
If not, check if person 3 is in the zone
etc
I can’t even check the state of the zone after person 1 leaves since it doesn’t track the people in there
This is really simple with a non-passive zone, but I can’t have this zone on my map as it’s massive!
you can make a template sensor that counts people in passive zones.
template:
- sensor:
- name: Passive Zone Count
state: >
{%- set zone = 'zone.my_city' %}
{%- set radius = state_attr(zone, 'radius') / 1000 %}
{%- set ns = namespace(count=0) %}
{%- for person in states.person if person.attributes.latitude is defined and person.attributes.longitude is defined %}
{%- set ns.count = ns.count + 0 if distance(zone, person.entity_id) > radius else 1 %}
{%- endfor %}
{{- ns.count }}
Ooh… this looks promising - will have a look at this!
Question - why do you need to set a radius? The zone itself has the radius inbuilt does it not?
it does, you’re not reading the code correctly. It takes the configured radius and converts it from m to km. All you need to change is your zone
takes the configured radius and divides by 1000 because there’s 1000 meters in a kilometer.
Ah yes - my bad!
Awesome - will try this tomorrow
So I just set this up - I only seem to be getting one person tracked inside it (even though I have two devices tracked at home right now)
Is there any way I can ‘test’ movement from my phones? (or even see who it is tracking?)
It ignores people who don’t have lat and lon attributes. I.e. needs to have a gps device tracker attached to the person
And you’re sure they are inside the zone? The calc is simple. It’s just gps position - gps position > radius.
put this in the template editor
{%- set zone = 'zone.my_city' %}
{%- set radius = state_attr(zone, 'radius') / 1000 %}
{%- set ns = namespace(count=0) %}
{%- for person in states.person if person.attributes.latitude is defined and person.attributes.longitude is defined %}
{{ person.name }} {{ distance(zone, person.entity_id) }} < {{ radius }}
{%- set ns.count = ns.count + 0 if distance(zone, person.entity_id) < radius else 1 %}
{%- endfor %}
{{- ns.count }}
and post the output
Yes, both are within the zone
Output is (I changed the values):
Result Type: String
Person1 0.0021350000000000005 < 24.0
Person2 0.005698 < 24.00
alright, then it should be working and the count at the bottom will be correct.
I’m not seeing a count in the template editor (should I be?)
Also, is the result type String not an issue (or is that also related to the template editor…)?
The sensor is only giving me 1 still
EDIT: I think I might see the issue - the else is 1 rather than + 1
So should be:
{%- set ns.count = ns.count + 0 if distance(zone, person.entity_id) < radius else ns.count + 1 %}
Am I right?