Triggering an automation when an entity moves every 1 second

hi. i have a very specific need where i have an entity (a shot clock that runs in milliseconds) and i want to trigger an automation every time it passes another second. how do i do this in numeric state change?

thank you in advance!

If the value in question is the state of the entity, you just use a State trigger, not a Numeric state trigger.

thanks for that. but because the change happens in milliseconds (it’s a shot timer) it’s firing every 0.1 seconds so it’s triggering automation too often

i tried using a state change trigger with a “for “ 1 second, but i think it doesn’t work well. looking for a better solution,

You could set a template condition to throttle the execution:

condition:
    - condition: template
      value_template: "{{ this.attributes.last_triggered | default(as_datetime(0), 1) < now() - timedelta(seconds=1) }}"

Another option might be to set up a template sensor that rounds the value to the second, then trigger off the state of that sensor.

thank you so much. i will try your value template. may i know what does the last 2 parts do?

this.attributes.last_triggered | default(as_datetime(0), 1) : The datetime the automation last triggered it’s actions (with a default in case the automation has never triggered)

now() - timedelta(seconds=1) : Together these two get the datetime of 1 second ago.