Sonoff mini and Zigbee Bulb

I have a sonoff mini controlling a zigbee bulb. Since I don’t want to cut the main to the bulb by the relay, I was looking for alternative ways, while still having the possibility to control the main in case of wifi or ha failure.

I thought to use a momentary button instead a switch connected to the sonoff, then configure 2 different actions:

  • double_click: toggle the relay
  • single click: generate an event used in automations to toggle the zigbee bulb

I’m very new to ESPHome, and the only way I figured out is:

  - platform: gpio
    name: ${device_name}_button
      number: GPIO04
      inverted: true
    id: button_1
    - timing:
        - ON for at most 1s
        - OFF for at most 0.5s
        - ON for at most 1s
        - OFF for at least 0.2s
        - switch.toggle: relay_1
    - timing:
        - ON for at most 1s
        - OFF for at least 0.5s
        - homeassistant.event:
            event: esphome.sonoff_click

Then in Home Assistant I can create an automation triggered by esphome.sonoff_click and checking the device_id. So far so good… but I dont like it :slight_smile:

Is there a way to create a device specific event, like a virtual sensor or switch toggled by the click and managed in HA?

Just realize if those are NOT Sengled Zigbee bulbs - doing this (toggling bulb power at the switch) may mess up your Zigbee mesh. I get that you don’t intend to do that in normal operation and why you’re tryin gto design around it. But… They’re not designed to be powered off - at ALL. So you need to put in extra consideration into your design.

If you insist in the configuration - you may want to consider a bulb that does NOT act as a Zigbee repeater (Only one I know of off hand is Sengled)

All this work it’s just because I dont want to cut the main in a normal situation. But I want to be able to use my lights in an emergency situation, like a failure of zigbee adapter, or the router. I cannot accept to lose the control of the lights in my house if something goes wrong in the network infrastructure.
In a normal situation I will never cut off the main to the bulbs (ikea zigbee bulbs btw), but if this happens I could use a long press to operate the relay in the mini and I will be able to turn on and off the light even without zigbee or HA or wifi.