[SOLVED] ESPHome + Sonoff Mini

Hi all,

So, I have a wall switch (Simple rocker type) with a Sonof Mini behind it. This wall switch controls the lounge lights. I recently installed two lamps in my lounge; both connected to two son off basics.

I wanted to have an “automation” where if I toggle the wall switch (turn it on and off) within 350ms - the lamps turn on and the main lounge lights stay off.

I managed to do this by doing the following:

  1. Remove the config from ESPHome
  2. Setup a flow in NodRed (Which is connected to HA)

The flow in NodRed does this:

Switch stage changed -> did it do on and off within 350ms? - if so - turn lamps on - else toggle lounge lights

This got me the desired outcome. Then I got thinking; what happens if HA died? My wall switch would do nothing. Because I removed the config from ESPHome to turn on the relay / lights

So, this is my question

Is it possible to configure ESPHome to do the following:

“If switch status changes (off -> on -> off) within < 350mm -. ignore this.” Else turn on or off the light depending on the state of switch.

I have tried all sorts of things with if-conditions and such. But the lights “flicker” for a brief period when I toggle the switch.

This is my latest attempt:


binary_sensor:
  - platform: gpio
    pin: GPIO00
    id: reset
    internal: true
    # on_press:
    #   - light.toggle: 
    #       id: lounge_lights

  - platform: gpio
    name: 'Lounge lights switch'
    pin: GPIO04
    id: switch_1
    on_press:
        - if:
           condition:
            for:
              time: 5s #added long delays for testing
              condition:
                - binary_sensor.is_on: switch_1
           then:
              - delay: 5s
        - if:
           condition:
               - light.is_off: lounge_lights
           then:
              - light.turn_on: lounge_lights
    on_release:
        - if:
           condition:
            for:
              time: 5s
              condition:
                - binary_sensor.is_off: switch_1
           then:
              - delay: 5s
        - if:
           condition:
               - light.is_on: lounge_lights
           then:
              - light.turn_off: lounge_lights

I’m presuming the switch can be configured as a binary sensor in esphome?
If so there are presets for double click, multi click etc that you set the times for.

Thanks, I did see this too. But was not sure if the sensor is what the wall switch is connected to? I’ll dig into that and try it out.

Solved. It was multi_click I needed

binary_sensor:
  - platform: gpio
    pin: GPIO00
    id: reset
    internal: true
    on_press:
      - light.toggle: 
          id: lounge_lights

  - platform: gpio
    name: 'Lounge lights switch'
    pin: GPIO04
    id: switch_1
    on_multi_click:
    - timing:
        - OFF for at least 0.4s
        - ON for at least 0.4s
      then:
        - light.turn_on: lounge_lights
    - timing:
        - ON for at least 0.4s
        - OFF for at least 0.4s
      then:
        - light.turn_off: lounge_lights

Now when I toggle the switch the above code doesn’t run; which is what I needed. HA / NodeRed then turns the lamps on or off for me on toggle.

You could also add the click in there with the relevant timing and avoid the need for node red altogether.
All the switching logic would take place in the sonoff