Esphome wifi on disconnect as alarm trigger

Hello everybody,
My Name is Dan and new here on the forum but not new in ESPhome and Hass. For quite some time i have been building sensors and more to connect with Hass.
Now i’m ussing the weak points of the ESPhome as an alarm trigger. When multiple devices are disconnected from Wifi or when Wifi is jammed.
So i build an ESP8266 with a 136db sirene, colour led and its own powersuply.
My goal is that when the sirene is disconnected from Wifi( Jammed) or gets stolen. The sirene goes off.

The problem now is that when there is a Wifi glitch, the siren goes off. Can’t figure out what code off Yaml is best for this to fix a delay or reset wifi.

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  min_auth_mode: wpa2

# Turn on Alarm when disconnected from Wifi to avoid jamming and theft
  on_disconnect:
    - delay: 
        30s
    - switch.turn_on: 
       id: sirene  

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Alarm Fallback Hotspot"
    password: "xxxxxxxxx"

captive_portal:
    
switch:
  - platform: gpio
    pin: GPIO5
    id: sirene
    icon: mdi:volume-high
    restore_mode: RESTORE_DEFAULT_OFF
    name: Sirene
    on_turn_on: # sirine active time
      - delay: 30s
      - switch.turn_off: sirene
       
  - platform: template
    name: "Inbraak Alarm"
    id: inbraak_alarm_disabled
    icon: mdi:alarm-light-outline
    optimistic: true
    restore_mode: RESTORE_DEFAULT_OFF
    entity_category: config
    on_turn_on: 
      then:
        - light.turn_on:
            id: activity_led
            effect: pulse
            brightness: 100%
            red: 0%
            green: 0%
            blue: 100%
#        - switch.turn_on: 
#            id: sirene         
    on_turn_off: 
      then:
        - light.turn_off: activity_led
#        - switch.turn_off: 
#            id: sirene
  - platform: template
    name: "Brand Alarm"
    id: brand_alarm_disabled
    icon: mdi:fire-alert
    optimistic: true
    restore_mode: RESTORE_DEFAULT_OFF
    entity_category: config
    on_turn_on: 
      then:
        - light.turn_on:
            id: activity_led
            effect: pulse
            brightness: 100%
            red: 100%
            green: 0%
            blue: 0%
        - switch.turn_on: 
            id: sirene 
    on_turn_off: 
      then:
        - light.turn_off: activity_led
        - switch.turn_off: 
            id: sirene
  - platform: template
    name: "Rook Alarm"
    id: alarm_rook_alarm
    icon: mdi:fire-alert
    optimistic: true
    restore_mode: RESTORE_DEFAULT_OFF
    entity_category: config
    on_turn_on: 
      then:
        - light.turn_on:
            id: activity_led
            effect: pulse
            brightness: 100%
            red: 40%
            green: 30%
            blue: 10%
        - switch.turn_on: 
            id: sirene 
    on_turn_off: 
      then:
        - light.turn_off: activity_led
        - switch.turn_off: 
            id: sirene
# Configure LED
light:
  - platform: neopixelbus
    variant: WS2812
    pin: GPIO4
    num_leds: 8
    flash_transition_length: 500ms
    type: GRB
    id: activity_led
    name: "Status LED"
    restore_mode: ALWAYS_OFF #normal OFF
    effects:
      - pulse
      - pulse:
          name: "Fast Pulse"
          transition_length: 1s
          update_interval: 0.5s
          min_brightness: 0%
          max_brightness: 100%

Hass Rapberry pi 5
Wifi Ruckus zonedrirector

Well, now you have this setup: when wifi drops (can be just for a glitch) you start a sequence: 30s delay then siren goes on and nothing prevents siren to go on after set time. What you should do is to check again after 30 seconds if wifi is still disconnected and only then activate siren. So, another if…then sentence instead direct switch.turn_on.
I guess one of other options would be to create a script which contains your delay and activation of siren. Then when wifi drops you start this script (script.execute), and if wifi comes up again you cancel script execution (script.stop).

You could use something like this (untested):

on_disconnect:
  - wait_until:
      condition: 
        wifi.connected:
      timeout: 30s
  - if:
      condition:
        not:
          wifi.connected:
      then:
        - switch.turn_on: 
            id: sirene

Thnx this might be the solution before i start with lambda’s and scripting( not yet my best quality).
Other sugestion are very welcom

I tested it last night. start looked good. But after 6 hours there was a Wifi glitch en the alarm turned on.
Probebly due to a new high risk Roque.
I think that the probleem is that my Ruckus zone director detects a roque. And that is when the ESP is disconnected for some seconds from the Wifi