Shelly 1pm light automation

Hello community,
I am completely new to the topic of Home Assistant. So if I’m forgetting any important information, please let me know.

For a few days now, I have had the problem that my Shelly switches trigger the automation for the light on their own. The Shelly 1 pm mini is running in detached mode and switches the light via the following automation:

alias: Smart light
description:
triggers:

alias: Smart Lichtschalter - EG - Arbeitszimmer
description: >-
  Shelly 1pm hinter der Lichtschalter neben der Tür im Arbeitszimmer. Wird im
  detached mode zur Steuerung der Deckenleuchte verwendet.
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.lichtschalter_eg_arbeitszimmer_input_0_input
conditions: []
actions:
  - action: light.toggle
    metadata: {}
    data: {}
    target:
      entity_id: light.deckenleuchte_eg_arbeitszimmer
mode: single

The logbook shows that the Shelly is temporarily unavailable. After it is available again, the light switches.
My guess: The automation switches on every status change and not just on and off. Shortly before this happens, the router does a channel scan and sets the channels for the WLAN. So the Shelly briefly has no wifi and therefore switches the light?
How can this be avoided? Unfortunately I could not find a suitable entry.

triggers:
  - trigger: state
    entity_id:
      - binary_sensor.lichtschalter_eg_arbeitszimmer_input_0_input
    from:
      - 'on'   # this is OR logic
      - 'off'
    to:
      - 'on' 
      - 'off'

Or:

triggers:
  - trigger: state
    entity_id:
      - binary_sensor.lichtschalter_eg_arbeitszimmer_input_0_input
    not_from:
      - unknown
      - unavailable
    not_to:
      - unknown
      - unavailable

So from on or off and to on or off.

Or not from and not to an unknown or unavailable state.

many thanks for the quick help! will try it out straight away and report if it works :slight_smile: