How to combine Sonoff ZBMINI with Zigbee smart bulb

I dont know if i messed up something but here is what i have so far:

substitutions:
  device_name: kitchen_sonoff_mini
  device_friendly_name: Kitchen Sonoff Mini Switch
  device_ip: 192.168.5.13
  light_id: light.kitchen_lights
  button_gpio: GPIO00
  led_status_gpio: GPIO13
  relay_gpio: GPIO12
  
esphome:
  name: ${device_name}
  platform: ESP8266
  board: esp01_1m # esp8285

# Enable logging
logger:

# Enable Web server
web_server:
  port: 80

# Enable Home Assistant API
api:
#  password: "!secret api_password"
#  reboot_timeout: 15min / 0s

# Enable Over The Air update
ota:
#  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  #reboot_timeout: 0s # Disable reboots for when Home Assistant is offline for an extended time.
  manual_ip:
    static_ip: ${device_ip}
    gateway: 192.168.5.1
    subnet: 255.255.255.0
  #domain: .localdomain

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Kitchen-Sonoff-Mini"
    password: !secret ap_password

captive_portal:

# the web_server & sensor components can be removed without affecting core functionaility.

#time:
#  - platform: homeassistant
#    id: homeassistant_time

sensor:
# Extra sensor to keep track of uptime
  - platform: uptime
    name: ${device_name} Uptime Sensor
    filters:
      - lambda: return x / 3600;
    unit_of_measurement: "hours"
    accuracy_decimals: 2

# Extra sensor for WiFi signal
  - platform: wifi_signal
    name: ${device_name} Wifi Signal Strength
    update_interval: 900s

#######################################
# Device specific Config Begins Below #
######################################

binary_sensor:
  # the lines below define the reset button
  - platform: gpio
    pin: $button_gpio
    id: ${device_name}_button
    internal: true
    filters:
      - invert:
      - delayed_off: 10ms
    on_press:
      - switch.toggle: 
          id: relay_1
          
  # the lines below toggle the main relay on command
  - platform: gpio
    name: ${device_name}_status
    pin: GPIO04
    id: switch_1
    on_state:
      - script.execute: hass_light_toggle
    #on_press:
    #  then:
    #    - switch.toggle:
    #        id: relay_1
    #on_release:
    #  then:
    #    - switch.toggle:
    #        id: relay_1
switch:
  - platform: gpio
    name: ${device_friendly_name} 
    icon: "mdi: lightbulb_outline"
    pin: $relay_gpio
    id: relay_1
    restore_mode: restore_default_off #ALWAYS_ON

status_led:
  pin:
    number: $led_status_gpio
    inverted: true

output:
  - platform: esp8266_pwm
    id: blue_led
    pin: $led_status_gpio
    inverted: true

light:
  # the 4 lines below define the Blue LED light on Sonoff Mini, to expose in HomeAssistant remove line "internal: true"
  - platform: monochromatic
    name: ${device_name}_blueled
    output: blue_led
    internal: true # hides the Blue LED from HomeAssistant

script:
  - id: hass_light_toggle
    then:
      if:
        condition:
          api.connected:
        then:
          - if:
              condition:
                switch.is_off: relay_1
              then:
                # Turn the relay back on and turn on the light.
                - switch.turn_on: relay_1

                - homeassistant.service:
                    service: light.turn_on
                    data:
                      entity_id: $light_id
              else:
                # Have Home Assistant toggle the light.
                - homeassistant.service:
                    service: light.toggle
                    data:
                      entity_id: $light_id
        else:
          # When HA is unavailable, toggle the relay.
          - switch.toggle: relay_1
1 Like

Has anyone been able to flash the Sonoff ZBMINI?

Where do you find updated firmware ?

I dont think there is an alternative HW. I went with shellies in the end although I would have preferred a zigbee device but sadly I could find one that would allow for esphome etc. to flash to the device

I purchased the ZBMINI hoping to use a zigbee device with ESPHome for a smart bulb. Just like the OP, I wanted to configure a fallback in case HA couldn’t be reached. Oh well, probably going to grab a few of the newer Shelly Plus 1PMs now

ESPHome etc only works with ESP-based devices, that is WiFi only. You won’t find Zigbee devices that work with EspHome.

hey, would this work for the no-neutral version of this relay?

Variation on this topic - I’m adding the zbMinis to the HUE BRIDGE and then have Hue added to HA. My goal is similar - i want light control to work even if HA is down (clearly it won’t work if the Hue network is down, but I mess around much less with that one). I know this is a year old but i will update soon if this works well and if the zbmini button switch presses are exposed to HA via Hue Bridge Integration.

For those who don’t like the click: I contacted SONOFF support if they would be open to add the “detach relais” feature like Shelly it has… or if they even are open to create a new, smaller product without the relais. So… if you’re interested in that, please write to the SONOFF support as well to create some more requests about that and raise the awareness. Thanks!

4 Likes

@MatthiasLohr Did you get a response?

Would an OTA update from Sonoff be possible?

I dont think OTA is possible. Since this topic is almost two years old … does anybody know of new devices that allow a detached mode and are zigbee based? (i want to get rid of my shellies and ideally the zigbee device would support binding :-))

1 Like

I’ve done this with an automation in HA that toggles the power back when the switch is flicked and gives a helper with the switch position to control the smart bulb. The only downside is that if you toggle the physical switch the light flashes on or off while HA reasserts the desired state. If HA is offline or the automation is disabled the switch just works as a normal dumb switch.

  1. Create two toggle helpers (Settings > Devices & Services > Helpers > Create Helper > Toggle), I named these “MyLight Isolator” and “MyLight Position”, the ZBMini itself I’ve named “MyLight ZBMini”. I put all three on a dashboard while I was debugging.

  2. Create an automation, I’ve called it “MyLight decouple switch and relay”. Add a “State” trigger and add the “MyLight Isolator” and “MyLight ZBMini” entities.

  3. We need to run the actions if the ZBMini doesn’t match the Isolator state, this would be a great use for an XOR condition but we don’t have one. Add an “Or” condition, then add two “And” conditions to it. Then add the Device “MyLight ZBMini” is “On” and the State “MyLight Isolator” is “Off” to one. Then add the same to the other “And” condition but swap over the On and Off. i.e. (ZBMini is On AND Isolator is Off) OR (ZBMini is Off AND Isolator is On)

  4. Next we add actions to toggle the Device “MyLight ZBMini” and call the service “Input Boolean: Toggle” on “MyLight Position”. The first undoes the change in state of the physical device, i.e. the hardwired change in state on the device itself. The second just flips the helper, because it isn’t undoing anything it keeps track of the state the user is requesting.

Now you just trigger your own automation off “MyLight Position” to control the smart bulb. Or flick the “MyLight Isolator” switch to control the power. The “MyLight Position” also changes state when “MyLight Isolator” is changed so you might want to check the bulb is switched on before trying to set its state.

1 Like

This is kind of neat, and probably a good solution to use the mechanism inside HA to mimic the detached mode.

… since we are not likely getting this “detached mode” firmware update from Sonoff for its ZBMINI.

I found only one solution for this. Some ZBMINI had CC2652. It can be flushed with PTVO firmware. Then it will have detached mode and binding to bulb. But unfortunately, Sonoff using different chips and it hard to find ZBMINI with CC2652.

I’ve now created a blueprint for this:

1 Like

Did you get any response from Sonoff support in the end?

1 Like