Hello, how do I make a counter when someone enters a zone?

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 :slight_smile:

1 Like

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.

1 Like

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

  • platform: zone
    entity_id: person.alex_peter
    zone: zone.evogym
    event: enter
  • service: counter.increment
    metadata: {}
    data: {}
    entity_id: counter.counter_evogym
    alias: Counter Evo Gym


That looks OK, yes. …was just writing it for you when I saw this!

1 Like

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() }}"


state: "Home"

Check the state of person.alex_peter in history stats or under the dev tools. It’s that value you must use.

1 Like

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.

1 Like

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:

  - platform: zone
    entity_id: person.alex_peter
    zone: zone.evogym
    event: enter

with this:

  - platform: state
    entity_id: person.alex_peter
    to: evogym
      minutes: 30
1 Like

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.

Hello, I just don’t understand. what do you mean? I gave the name Alex_arbeit. but it does not work. zone.alex_arbeit doesn’t work either. Thanks for the support