ESPHome Physical Button - Long Press action without release

You can create a template binary_sensor that follows the state of the original binary_sensor with a delay.

  - platform: gpio
    id: button
    pin: XX
    on_click: 
      - min_length: 0 s
        max_length: 1 s      
        then: // Actions for short click 
  - platform: template
    id: button_longpress
    condition:
      binary_sensor.is_on: button
    filters: 
      - delayed_on: 1 s
    on_press: 
      then: // Actions for long click - executed immediately after 1s

I use this method in many of my devices. It works like a charm.

4 Likes