How to keep track (or count) events?

I’ve seen people showing it on the forum but I’m not sure how they do it, eg:

  • Number of times (today) the cat has went to its litter box (with vibration sensor) + resetting the counter (if you cleaned it)
  • Triggering an automation only once per day (e.g. in the morning, play the late evening news when the occupancy sensor has seen you come into the living room, I’ve tried time boxing but sometimes the automation re-triggers when movement is done during the timebox and the news already ended)

Anyone willing to point me in the right direction?

Thanks much guys!

You could try using the Historical Stats Sensor:

I use it to track how long i have been @ work.
But you can also check how often there has been a change to a specific state in a given timeframe

1 Like

You could also use the Counter component.

How would you use it? Like this?

  • Automation checks counter, if 0, start playing
  • Set counter to 1

Another automation that sets the counter back to 0 at midnight?

Well, for the first scenario in your OP I think the History Statistics Sensor would be easier to use.

For the second scenario, you could use a counter, but an Input Boolean would probably make more sense:

input_boolean:
  played_news:
    initial: false
automation:
  - alias: Play news
    trigger:
      # Occupancy sensor trigger goes here
    condition:
      condition: state
      entity_id: input_boolean.played_news
      state: 'off'
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.played_news
      - # Play news service goes here
  - alias: Reset played news
    trigger:
      platform: time
      at: "00:00:00"
    action:
      service: input_boolean.turn_off
      entity_id: input_boolean.played_news
1 Like

Fair enough, for now I used the counter and just incrementing it when news starts playing with the conditional that the counter is 0, and resetting the counter at midnight.

Basically exactly the same as the boolean would do, if I come across a situation where true/false is needed I’ll use the input boolean platform :slight_smile: thanks!