Onvis Switch HS2 triggering automation when reconnected

Hi,
I have an Onvis HS2 button, it is connected via Thread using the Homekit integration.

This HS2 has five programmable buttons. Each button is triggering an automation. This is how I’ve set the trigger:

alias: Play/Pauze muziek Praktijkruimte
description: Play/Pauze muziek Praktijkruimte
triggers:
  - alias: Onvis HS2 - Knop 2 wordt ingedrukt
    trigger: event
    event_type: state_changed
    enabled: true
    event_data:
      entity_id: event.onvis_hs2_fde927_stateless_programmable_switch_2
conditions: []
actions:

This works fine. However, since thread is a wireless protocol, on some occasions it gets disconnected. When reconnected, this automation is triggered as well. Which is very annoying when it happens.

How can I redefine the trigger, so it only triggers the automation when a button is actually pressed?

You have to use not_from as conditions with the state unavailable and unknown.

Thanks!

I have updated it now to:

  - trigger: state
    alias: Onvis HS2 - Knop 4 wordt ingedrukt
    entity_id:
      - event.onvis_hs2_fde927_stateless_programmable_switch_2
    enabled: true
    not_from:
      - unknown
      - unavailable
    not_to:
      - unknown
      - unavailable

Let’s see if this holds up.