How best to deal with entities that occasionally go "unavailable" when using them in automations?

I have some automations that trigger based on the state of an entity. The problem occurs when for a brief moment that entity goes “unavailable” and then returns back to its previous state. The issue with this is that when returning to previous state it causes the automation to trigger again.

The ideal solution would be for the integration to have more stability, but it’s a third-party integration, and the functionality works fine - it’s just brief moments where HA doesn’t see the entity.

The only way around this i can think of, is to create a binary sensor that would only change based on supported states changing. (In my case it would be from disarmed to armed home/away) and ignoring any changes where the state becomes unavailable.

Any other ideas i’m not thinking of?

Maybe just add a from: to your trigger?

Thanks, that definitely seems an obvious workaround! I’d originally had the trigger based on device, so i’ve swapped that to state and we’ll see how they perform overnight.

you could create a template condition and use yjis as the value:

value_template: '{{ trigger.from_state.state != "unavailable" }}'

if the state was previously unavailable then the automation actions won’t run.