How to X seconds until delay on_press automation is triggered?

I have a simple binary_sensor that sends an on/off mqtt event with delays.

binary_sensor:
  - platform: gpio
    name: "Window water level too high GPIO21"
    device_class: MOISTURE
    pin: 
      number: GPIO21
      inverted: true
      mode:
        input: true
        pullup: true
    filters:
      - delayed_off: 1s
      - delayed_on: 15s
    on_press: 
      then:
        ######################################################
        # Must be turned on before setting frequency & level
        ######################################################
        - output.turn_on: buzzer
        ######################################################
        # Frequency sets the wave size
        ######################################################
        - output.ledc.set_frequency:
            id: buzzer
            frequency: "1000Hz"
        ######################################################
        # level sets the %age time the PWM is on
        ######################################################
        - output.set_level:
            id: buzzer
            level: "90%"
    on_release: 
      then:
        - output.turn_off: buzzer

The problem I have is that I want the buzzer to follow the same delay logic but I can not understand how to do this since the delay property in automation just waits and always continues.

Is this possible? I would like the buzzer to work without any external interaction.

Thanks!

I don’t understand. The way you have the automation now, the buzzer follows the switch state, so it has the same delays already?

I have to say, this was my mistake and you are right.

I was listening all day to how “the buzzer was beeping in the basement” but no, it was another thing, I think the washing machine beeps in a similar tone…? I just saw the logs in home assistant and the device never was in a wet state.

I am sorry, I will kick myself out. 🚶‍♂️

1 Like