HA automation triggered each time when device reconnects. How to avoid?

I have a simple automation in HA which flips a switch when a sensor temperature is between 10 and 30 degrees. This automation is triggered correctly when these temperatures are crossed…but was also triggered at random time instances. Looking into the logbook, I learned that my sensor device regularly becomes unavailable and triggers the automation when being reconnected. How can I avoid the automation to be triggered by a reconnecting device? Thanks!
(why my ESPHome device regularly looses connection is another investigation).


  not_from: 'unavailable'

to your trigger

1 Like

That could indeed solve the problem. As I am not so familiar, can you instruct me please? The following code gives an error. Also with “xx” and without quotes gives an error.

Sorry, numeric_state, won’t work.

Add this as condition

  - "{{ trigger.from_state.state not in ['unknown', 'unavailable'] }}"
1 Like

Magnificent, @francisp ! This code is accepted. I’ll keep you posted if this resolves my issue (and I believe it will). My device typically looses connections a few times a day (something to be investigated). Thanks!

thanks to the solution proposed by @francisp, my automation is no longer wrongly triggered. Great solution.