I want to run a script when I get new mail. So I want it to run when my unread counter goes from 0 to 1, or from 1 to 2. But not when I read a mail and it goes back from 2 to 1.
However, I cannot figure out how to get the previous value to compare against. This is my current (partial) attempt:
- alias: "New mail"
trigger:
platform: template
value_template: '{{ states.sensor.emailcount.state | int > old_count??? }}'
Anyone coming across should also probably look at the option here:
an approach using an automation condition comparing trigger.to_state.state with the triggering entities previous state trigger.from_state.state (thus avoiding the need for an extra binary sensor).