I thought this would be evaluated every time the sensor changed, but it only triggers on the brief occasions that the sensor goes unavailable.
And now, while typing this, I’ve realised that round(0) is the wrong thing anyway as 0.5 would be rounded to 1, arrgghhh, this should be easy and I just can’t see it.
The template will be evaluated every time the sensor’s state changes, but your comparison is between the sensor’s state and a fixed value of “0”. Once the state value is over 0 the template is “true” and the automation will not trigger again until the template evaluates to “false” and then changes to “true” again.
This will only trigger when the sensor’s value changes to a whole number, but if the price change changes from 0.99 to 1.01 it would not trigger. The “to” state has to be exactly 1 (or 2,3,4…).
EDIT: Removed my proposed method because Petro’s below is so much better
Ok, lets go with a normal state trigger and condition. This checks the previous state and ceilings it to the next highest whole number. If the after state is above, it will continue the automation.
trigger:
- platform: state
entity_id: sensor.elec_cost_today
variables:
continue: >
{{ trigger | default(none) is not none and trigger.to_state is defined and trigger.from_state is defined }}
before: >
{{ trigger.from_state.state | float(0) if continue else 0 }}
after: >
{{ trigger.to_state.state | float(0) if continue else 0 }}
above: >
{{ after >= before | round(0, 'ceil') }}
condition:
- condition: template
value_template: "{{ continue and above }}"
action:
...
It might work as long as you don’t mind that it will trigger on decrement as well as increment… also you will need to guard against triggering on restart by setting an availability in the template sensor and a default for the “int”.