I would like to generate a counter that counts up when I enter a zone. How do I do that? thank you for your help
To be clear, you want to know how many times youâve entered a zone and not how many people are in that zone?
- Create an
input_number
helper. - Create an automation to increment that
input_number
whenever you enter that zone.
âŚis that enough or would you like the yaml for this?
edit: typos
Hello, yes, I would like to know exactly how often I enter a zone, I am still a beginner, I would be happy to help with Yaml, thank you very much.
no worries. Itâs getting late here now so will do this tomorrow morning for you
Instead of an input number, thereâs also a counter.
Also see this post. Just use a zone instead of a sensor.
To do periodic counting, use the history stats platform.
Yes, of course, a counter is much better!
A small remark:
If someone is interested in THIS functionality - only a âzone.homeâ currently provides a number of persons in that zone.
Other zones (active, passive) - do provide this info only if:
- no âniceâ friendly names specified for these zones;
- or these friendly names are same as zonesâ entity_ids;
- or zonesâ entity_ids are made (slugified) from âniceâ friendly names.
There are open issues in core for a long time.
I tried it, is the yaml code correct?
If so, I would like to use the history stats to track how often I was there and the start, end and duration.
description: ââ
mode: single
trigger:
- platform: zone
entity_id: person.alex_peter
zone: zone.evogym
event: enter
condition:
action: - service: counter.increment
metadata: {}
data: {}
target:
entity_id: counter.counter_evogym
alias: Counter Evo Gym
That looks OK, yes. âŚwas just writing it for you when I saw this!
Yes, it works. If I now want the counter to start after 30 minutes staying starts counting, how do I solve this? I canât find anything under these conditions
to be clear, do you only want it to count if you are there for longer than 30 minutes (so if you leave before 30 minutes, it doesnât count)?
Yes exactly
what would also be cool how long i spend in a zone, i tried with this yaml code. but it doesnât work. what am I doing wrong?
- platform: history_stats
name: how long alex stay home
entity_id: person.alex_peter
state: zone.home
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
Probably:
state: "Home"
Check the state of person.alex_peter
in history stats or under the dev tools. Itâs that value you must use.
Thanks, thatâs it, I simulated being away, but the time is counted even though my cell phone is turned off. Is there something still wrong?
If you were home and your phone turned off, it will keep counting. Thatâs just how it is. If you do that regularly then youâll need to write some custom logic to check the last updated time and have some kind of timeout logic to stop counting if itâs been too long. Probably something like a SQL sensor or some template sensor.
Thanks it works at home, how about other zones? It doesnât seem to be working! I canât find any stats for other zones under Devtools. It doesnât work with state: âzone.alex_arbeitâ or state: âalex_arbeitâ either.
OK, to trigger only after being there for 30 mins, replace this:
trigger:
- platform: zone
entity_id: person.alex_peter
zone: zone.evogym
event: enter
with this:
trigger:
- platform: state
entity_id: person.alex_peter
to: evogym
for:
minutes: 30
The same answer as before:
Look at the actual state values. The field youâre using is state
. It doesnât take a zone
entity. Look at the name you gave to that zone where youâve configured your zones â that should be the value for your person
when within that zone.