How to configure multi-click on Esphome


Prerequisites:

To configure mutli-click on Esphome in boneIO ESP you’d need to find binary_sensor part of your config. Let’s say you want to control light1, light2, light3.

light:
  - platform: binary
    name: 'Light 01'
    output: out_01
    id: light_01
  - platform: binary
    name: 'Light 02'
    output: out_02
    id: light_02
  - platform: binary
    name: 'Light 03'
    output: out_03
    id: light_03

Let’s configure IN_01 of boneIO ESP 32x10:

Standard configuration looks like this:

binary_sensor:
  - platform: gpio
    name: 'IN_01'
    id: in_01
    pin:
      pcf8574: pcf_inputs_1to14
      number: 0
      mode:
        input: true
      inverted: true
    on_press:
      then:
        - light.toggle: light_01

Let’s remove on_press option

binary_sensor:
  - platform: gpio
    name: 'IN_01'
    id: in_01
    pin:
      pcf8574: pcf_inputs_1to14
      number: 0
      mode:
        input: true
      inverted: true

Final configuration

Now let’s add on_multi_click action.

binary_sensor:
  - platform: gpio
    name: 'IN_01'
    id: in_01
    pin:
      pcf8574: pcf_inputs_1to14
      number: 0
      mode:
        input: true
      inverted: true
    on_multi_click:
      - timing: # double click
          - ON for at most 1s
          - OFF for at most 0.5s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - light.toggle: light_02
          - logger.log: 'Double Click'
      - timing: # single click
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          - light.toggle: light_01
          - logger.log: 'Single Click'
      - timing: # long click
          - ON for at least 1.4s
        then:
          - light.toggle: light_03
          - logger.log: 'Long Click'

Ok. It’s ready, now just upload new firmware to your device. You might need to adapt timings for your wall switches to work best for you.