Count how many times an entity has been turned on?

I have an RFID reader connected to my Home Assistant.
Now I want to count how many times a tag ID has been used.
I have the following entities in Home Assistant:
But I don’t know how I can do that.
Can someone help me with that please ?
Kind regards,
Bart Engelen

Use this:

Use a count sensor type on the valid tag binary sensor.

There’s an example at the bottom of the page for the time period to count over.

The history stats sensor platform is limited by the number of days of history that your Home Assistant setup is set to record (the default is 10). If you want to record the number of times a tag is used beyond your history limit, you could use the counter platform. With that, you would create an automation to increase the counter by one each time one of those sensors changes state (also probably the valid tag sensor).

History stats is easier if you don’t think you’ll go beyond your history limit.

1 Like

Thanks I have done this now but how can I extract the tag ID’s from this ?
Now I see how many times the RFID reader has been used. I use the binary_sensor.terrein7_valid_tag and binary_sensor.terrein8_valid_tag
I want to see who has used the RFID readers.

Is that also possible ?

Hi Tediore et al - I’ve just started playing with the counter and statistics sensor and something unusual is happening.

My database size is 14 days, via the following config:

  db_url: !secret recorder_db_url
  purge_keep_days: 14
      - sensor.icloud3_event_log

I’ve got a binary sensor that goes to ‘on’ when my washing machine starts. I thought it might be interesting to keep a count of how many times it was used in total (easy, via an automation and counter.increment) and how many times in the last 7 days, using the statistics sensor.

Here’s the config for the statistics sensor:

- platform: statistics
  name: "Washing machine cycles (last 7 days)"
  entity_id: binary_sensor.washing_machine
  state_characteristic: count_on
    days: 7

Pretty simple, but the numbers just don’t add up! Right now the sensor is reporting 9 when it’s actually 15, which is what I counted manually when looking at the HA logbook view for the source binary sensor over the last 7 days.

Any idea what could be causing this? I’m on the very latest version of HA (2022.10.5).


Ha - shortly after my post I found this post re using the History Stats sensor, which works as expected.

Strange that the statistics sensor isn’t working though?