How to combine Sonoff ZBMINI with Zigbee smart bulb

I just bought a couple of Sonoff ZBMINI Zigbee switches. They work well for me with regular “dumb” lightbulbs. I use a Raspberry Pi 4 with Conbee II Zigbee gateway, which runs deCONZ and Home Assistant software.

Currently, I assume the ZBMINI works as follows:

  • SWITCH: connected to a light switch button, measures the position of the switch: open or closed
  • RELAY: turns the power to the lightbulb on or off
  • The SWITCH position is linked directly to the RELAY: when I change the SWITCH position, the RELAY state is toggled between on (provide current to the lightbulb) and off (do not provide current to the lightbulb)
  • After pairing the ZBMINI with my Smart Home setup (Raspberry Pi 4 with Conbee II Zigbee gateway, running Home Assistant and deCONZ), I am able to control the relay from Home Assistant.
  • I cannot seem to be able to read the SWITCH position from Home Assistant

This setup works well for regular (dumb) lightbulbs.

However, when using smart Zigbee lightbulbs (e.g. Philips Hue, IKEA TradFri), this behaviour is not desirable: when the RELAY turns off the power, the smart lightbulbs stop their function as a Zigbee router and are no longer reachable by the Smart Home platform.

In this case, I would like to use the existing physical switch as a software switch, that toggles the smart bulb in HA and does not touch the current flow.

The Shelly 1 smart switch solves this by allowing a user to configure the button as a “detached switch”, which unlinks the SWITCH and the RELAY:

  • The SWITCH acts as a detached sensor: when changing the SWITCH position, the Shelly 1 sends an MQTT message which can trigger an action in the Home Automation software (e.g. toggling the smart lightbulb). The RELAY state does not change.
  • The RELAY acts as a detached relay: its state can be changed through the Home Automation software.
  • This allows a user to use the SWITCH to toggle the smart lightbulb, or initiate other action with any connected device really.
  • The smart Zigbee lightbulb can continuously stay connected to power, allowing it to act as a Zigbee router.

Does this type of functionality exist for the Sonoff ZBMINI? If not, does anyone have any other recommendations on how to use a ZBMINI together with a smart bulb which acts as a Zigbee router?

2 Likes

Hi,

Move the “L Out” to the same connector as the “L In”. This would effectively bridge the live and have permanent power to the bulb. The Sonoff relay would still “click” when you pushed the light switch but not do anything. You would then need an automation to trigger the bulb on when the relay turns on.

Something similar to this automation that I have (used an Xiaomi Button to trigger the light)

- id: brandonlight003
  alias: Brandon's Light
  trigger:
  - platform: state
    entity_id: sensor.brandon_xiaomi_switch
    to: single
  action:
  - service: light.toggle
    entity_id: light.hue_spare_brandon

You may have to have an “on” automation and an “off” automation. Mine is just a push button so it just toggles on/off.

Simon

4 Likes

That would be one possible solution, with the disadvantage that I cannot turn off the power to the smart bulb anymore, and that I cannot turn off the light anymore when the network / HA is not available unless I screw open the light switch box.

Ideally, the switch would

  • turn the smart bulb on/off “soft” via HA when HA is available, and
  • turn the smart bulb on/off “hard” via actually providing/cutting the power with the relay when HA is not available. In other words, gracefully fall back to dumb switching when the network / central brain is not available.

When flashing a Shelly with ESPHome, this is possible. See e.g. this article:

Goal 2: Provide a fail-over mechanism that allows the switch to operate even when Home Assistant is unavailable.

3 Likes

Hello I cannot answer your question but this sonoff zbmini works out of the box with deconz?:heart_eyes:
@kasper1 i just paired one and it appears as light which is ok but the state will indeed not be updated :frowning: I will flash the sonoff bridge and use tasmota for this :slight_smile:

Pairing with deCONZ worked without issues for me. At the moment, I’m not using deCONZ anymore though. I recently transitioned to using ZHA instead of deCONZ. I like the simplified pairing and closer integration with Home Assistant of ZHA. Also it is one container less to maintain and keep up to date.

By default, ZHA recognises the ZBMINI as a light instead of a switch. This can be overridden as described here:

1 Like

Hello,

Thank’s for your topic, very interristing.
I have the same needed. I bought wifi spots, they need permanent power to work.
I had same idea, use my ZBMINI like virtual switch,
HA convert the signal On/Off to order to the wifi spot.

However I don’t imagined to conserve control if my HA fall.

But, impossible for me to appair ZBMINI on HA.
I have Raspberry Pi4 B (2GB) + Raspbee II + HA core 2021.2.3
I beegin to play this week (1st experience with all )

I tried 2 ways:
1/ container deCONZ on Add-ON section: my Raspbee II is correctly detect, but impossible to appair my switch ZBMINI.

2/ ZHA: I use patch “/dev/ttyAMA0” but I have wrong popup “Impossible to connect device ZHA”

Some ideas ?

4h later…I connected my device !!
Stupid error, the patch was /dev/ttyS0
I found answer on Raspberry documentation: https://www.raspberrypi.org/documentation/configuration/uart.md

Now I have to connect my wifi spots…other adventure

I am in the same boat - has there been any progress on this? meaning is it possible to flash ESP home to the ZBMINI? Other I might consider going for the MINI instead for smart bulbs…

No progress on this. I recommend a wifi relay which is flashable with Esphome (Sonoff Mini or Shelly 1) instead of the ZBMINI for steering smart bulbs.

did you see a difference in response time between the zbmini and the wifi mini? so far I have steered clear of wifi devices for lighting :wink:

I don’t really notice a difference. It depends a lot on your wifi signal quality, traffic and interference from other wifi devices, I guess.

Does Sonoff mini has this feature if you flash it with esphome?

I haven’t tried it yet, but I would assume it is possible.

Using some of the code from https://www.esphome-devices.com/devices/Shelly-1#detached-switch-mode adapted to the different GPIO pins on the Sonoff Mini https://www.esphome-devices.com/devices/Sonoff-Mini-Relay/

Sweet thx for that info, if you try it first pls let us know, I just bought sonoff mini, waiting for it to arrive:)

Note that unfortunately the zbminis can only bind to one zigbee group. That means that if you want to have them attached to multiple groups for a room, floor, or whole home, you have to pick one, and then manually trigger the device in other automations. Combined with the difficulty in fitting them in North American switch boxes (doable, but tricky!), I’d say if you’re using smart bulbs to use a guard like these to keep the switches on, with an easy “override” if needed. Then, stick on a Zigbee switch or button to control the lights.

I don’t have a Sonoff Mini, but I do have a Shelly 1. I successfully accomplished what I wanted, below is the ESPHome config in case anyone wants to reuse:

substitutions:
  device_name: "Switch Light Kitchen"

esphome:
  name: shelly1-kitchen
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pass
  manual_ip:
    static_ip: 192.168.0.123
    gateway: 192.168.0.1
    subnet: 255.255.255.0


  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "shelly1 kitchen hotspot"
    password: !secret hotspot_pass

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

# Enable OTA updates
ota:

# Enable Web server (optional).
web_server:
  port: 80

# Text sensors with general information.
text_sensor:
  - platform: wifi_info
    ip_address:
      name: ${device_name} IP

# Sensors with general information.
sensor:
  # Uptime sensor.
  - platform: uptime
    name: ${device_name} Uptime

  # WiFi Signal sensor.
  - platform: wifi_signal
    name: ${device_name} WiFi Signal
    update_interval: 60s

# Shelly 1 detached switch config with fallback in case of wifi or api fail

switch:
  - platform: gpio
    name: ${device_name}
    pin: GPIO4
    id: shelly_relay
    # after reboot, keep the relay off. this prevents light turning on after a power outage
    restore_mode: ALWAYS_OFF

binary_sensor:
  - platform: gpio
    name: ${device_name} Input
    pin:
      number: GPIO5
    # small delay to prevent debouncing
    filters:
      - delayed_on_off: 50ms
    # config for state change of input button
    on_state:
        then:
          - if:
              condition:
                and:
                  - wifi.connected:
                  - api.connected:
                  - switch.is_on: shelly_relay
              # toggle smart light if wifi and api are connected and relay is on
              then:
                - homeassistant.service:
                    service: light.toggle
                    data:
                      entity_id: light.kitchen
              # else, toggle relay
              else:
                - switch.toggle: shelly_relay
    id: button

1 Like

@kasper1 was the flashing process easy? Did you do it via GitHub - yaourdt/mgos-to-tasmota: A minimal firmware for OTA (over the air) flashing Tasmota, HAA, or ESPurna from Mongoose OS or compatible firmware types. ?

Hi, I exactly used the OTA tasmota flashing process you linked to. Steps I followed:

  1. flash standard tasmota OTA: GitHub - yaourdt/mgos-to-tasmota: A minimal firmware for OTA (over the air) flashing Tasmota, HAA, or ESPurna from Mongoose OS or compatible firmware types.
  2. using the tasmota webUI, do a firmware upgrade to tasmota-minimal with OTA URL: http://ota.tasmota.com/tasmota/release/tasmota-minimal.bin.gz : Upgrading - Tasmota
  3. using the tasmota webUI, go to the console and type SetOption78 1 , then restart the device
  4. using the tasmota webUI, do a firmware upgrade from tasmota minimal to ESPHome, using file upload of the firmware.bin file generated from the ESPHome YAML configuration using ESPHome command-line tool: Migrating from Sonoff Tasmota — ESPHome

Hi, did you manage to replicate this with a Sonoff Mini? They seem to be a lot cheaper than Shelly 1 :grimacing:

@alloy Not yet, didn’t have free time to do it