Automation to trigger when any change happens to entity > 0

Hello,
I have an automation that I intened to fire every time there is a lightning strick, I’m doing this by putting a trigger on a sensor that has a lightning strike count, so every time the number goes up (or goes down which would be a false positive, but I can accept that) it goes off. Problem is, It’s been happening randomly when there was no change in the count. I learning how automations and going through the traces, I came to learn that the issue is from the entity going to an “unvailable” state and then back to “0”. So the state is changing, just not how I expect it to.

My thinking is that the trigger should only happen when the state changes, but to a number greater than the previous state and ignore any changes where the value goes down, or where the value goes from “unavailable” to “0” or back.

How would I go about this?

Hi @MABeatty1978

Have a look at the documentation about automation trigger variables. You can access the value of the entity before and after it is triggered in the from and to variables. You can then compare these to see if to is one more than from.

Use a state trigger and include a not_from

not_from: unavailable

You have to add this in the YAML editor, it’s not an option in the UI. It is also not available for numeric state triggers.

Thank you

condition: template
value_template: "{{ trigger.to_state.state > trigger.from_state.state }}"
1 Like