How to create a trigger with every counter increment?

Hi. I’m trying to create an automation that will trigger an automation with a change in counter.


- alias: Google TV Counter
  trigger:
  - platform: numeric_state
    entity_id: counter.google_tv_counter
    above: '+0'
  condition: "{{ trigger.from_state.state | int < trigger.to_state.state | int }}"
  action:
  - delay: '00:05:00'
  - service: counter.reset
    entity_id: counter.google_tv_counter
  mode: restart

What I’d like to do is to trigger an automation every time the counter value increases. I tried several approaches, like “above: ‘0’” or “above: ‘1’”. But the problem is that the automation doesn’t restart when the value changes from the ones in the above.

I mean I’d like the automation to restart / reset whenever the counter value changes.

I tried not including above: in the trigger, but it’s giving me an error that it either needs an above or below value.

I was experimenting / guessing with the value I thought adding a + before a number would indicate an incrementation.

Like this:

- alias: Google TV Counter
  trigger:
  - platform: state
    entity_id: counter.google_tv_counter
    to:
  condition: "{{ trigger.from_state.state | int < trigger.to_state.state | int }}"

This will trigger on all state changes of the counter. It will however ignore attribute changes due to the null to: (if in future you want to trigger on all state and attribute changes for an automation, leave out the to: altogether).

Your condition then checks to see if the counter increased.

5 Likes

That was an easy fix. Thanks!

1 Like