ZHA: Advanced features of Sonoff ZBMINIR2

I have installed a Sonoff ZBMINIR2. I skipped the installation via the recommended eWeLink App, because I want to use it with Home Assistant.

The switch was detected with ZHA without issues. However, I only see one control: Switching it on and off. The sensor “Opening” seems not to work – I get “closed” here even when the physical switch is toggled on.

The device supports a couple of additional options. In particular, I am interested in the “detached” mode, where I can keep a smart bulb powered and use the switch as a signal to turn it on or off. This way, I want to use the physical switch together with a remote to control the bulb.

Apparently, these options are available in the eWeLink App, and also when using Zigbee2MQTT instead of ZHA. I am new to HA and have installed the ZHA integration, plus I am running HA as a docker container, so I assume I cannot use the Zigbee2MQTT add-on.

Is there a way to access the other features of my device with my existing pairing? I’m not afraid to edit some config files, if necessary.

2 Likes

Meanwhile I learned that I can run Zigbee2MQTT on Docker, too. So I will try to switch from ZHA to Z2M.

I don’t understand. I looked at the literature on this device, and I don’t see anything about “open” or “closed.” It’s just a switch. On or Off. In HA, you can certainly change those words, but it is the same information; basically just a True or False.

I’ve found ZHA plenty functional for basic switches. I’ve heard Z2M is more functional for some devices, but there’s also value in keeping the HA system less complex to maintain.

As I wrote: This device has a few additional features.

One feature is “detached mode”. Normally, it acts as a relay: Switching it on/off will control the power of the connected light. With detached mode, the light will always be powered (for a smart bulb), and the switch can trigger custom actions.

This feature is not exposed with ZHA, but it is with Z2M.

1 Like

I ended up switching from ZHA to Z2M (Zigbee2MQTT):

  • I run 3 docker containers: Home Assistant, Mosquitto, Z2M
  • My USB Dongle is now exposed to Z2M
  • All my Zigbee devices are paired with Z2M

This now exposes the features I was missing for the Sonoff ZBMINIR2, e.g. the “Detached Relay Mode”. I have enabled that and created an automation that toggles my smart light when the physical (dumb) switch is toggled.

Now I can control my light using my bedside remote, the wall switch, and/or Home Assistant. The switch no longer cuts power to the light.

2 Likes

Hi, can you also bind it with other zigbee lights?

2 Likes

what is the trigger you are using for the automation?
i have Z2M also but when i turn on the detached relay no longer detects my dumb switch

This is exactly what I want to do with my ZBMini. I gave up trying to expose my dongle to Z2M (I just couldn’t get container to link to USB) and switched to ZHA.

So I cant keep the smart bulb alive with a dumb switch using ZHA? i.e if someone turns the dumb switch off, smart bulb will still be dead?

I feel like ZHA doenst support that mode yet (?). I’ve just installed my first R2 with the same reasons and failed to see any detached mode option, such as documented here for mqtt SONOFF ZBMINIR2 control via MQTT | Zigbee2MQTT

Perhaps you could try to put them in detached mode with zigbee2mqtt and then onboard them again into ZHA. Perhaps the mode persists

@fbeyer I found a ZHA quirk was added to the dev repo 4 days ago: zha-device-handlers/zhaquirks/sonoff/zbminir2.py at 97413e3ec2e5fdbcd17239b810d573cec4d3964d · zigpy/zha-device-handlers · GitHub

It should become available if its put to main, but if you add this as a quirk (copy the python file to your system and let zha know where to find it… see below) and restart homeassistant the detach relay should become available.

zha:
  custom_quirks_path: /config/<dir_where_you_will_store_the_zbminir2.py>
1 Like

Does the detached mode work for you with the updated quirk?

In my case the state of the switch is still toggled in HA when the switch connected between S1 and S2 is used. Then sometimes the light connected to the L_out terminal stays on - other times there seems to be a loop where the toggling of the state in HA is backpropagated to the device, which in turn updates the state of the output.

It seems that the state of the switch is mapped to the output state - even if in detached mode. In HA there is a ‘sonoff_zbminir2_opening’ attribute which probably should be used for the switch state instead.

When I have time I’ll have a look into the event payload fired when detached mode is enabled.

I updated to the next 2024.12b4 version that already includes the quirk (no need to manually add it), and indeed the detached mode doesn’t work right for me either.

With an external switch in “edge” mode, when I press it I see the switch entity going back and forth (so I can’t create an automation out of it or the light bulb will flicker on and off) and the relay of the zbminir2 doesn’t always stay on (it sometimes turns off, I can’t figure out why).

Looking at some comments on z2m it seems that in detached mode the module sends “toggle” events instead of “on” and “off”, I don’t know if that is what causes ZHA to get confused?

Ideally, I’d prefer to have 2 entities for the device, one for the switch state and one for the relay state. They would be synchronized in attached mode, but could work independently in detached mode. No idea if that’s technically possible, though.

I have the same situation with 2024.12. Detach relay + switch in edge trigger, sometimes it turns off the light and sometimes it doesn’t.
I agree that it would be ideal to have two identities, one for the switch state and one for the relay state.

What does turbo mode do?

The turbo mode improves the signal strength. You should only use it if you’ve got any problems with the range, so you don’t add up additional noise to your environment.

So happy to find this thread! I have one normal light bulb and the ZBMINIR works perfectly in relais mode and I love the fallback functionality in case it doesn’t have connection, but couldn’t get it working with the smart bulb. Maximum two or three times and it switched back to relais mode, most likely due to the triggering via ZHA. Good to know it’s not a config error.

I just installed two of these and have it working with detached mode and controlling smart bulbs. Most important thing is getting your sensor ID for the action. The automation is looking for any state change from the action sensor which is the toggling of your physical switch on the wall. Here is a yaml example of an automation and the MQTT settings used:

alias: Lighting - Turn On/Off Primary Bathroom Shower
description: ""
triggers:
  - entity_id:
      - sensor.sonoff_relay_switch_2_primary_shower_action
    trigger: state
    to: null
    from: null
conditions: []
actions:
  - choose:
      - conditions:
          - condition: device
            type: is_off
            device_id: 8c4358a1b165a06eed9838b37936dc7e
            entity_id: d5f3a65d41488e0aed0cc34140f6cc47
            domain: light
        sequence:
          - type: turn_on
            device_id: 8c4358a1b165a06eed9838b37936dc7e
            entity_id: d5f3a65d41488e0aed0cc34140f6cc47
            domain: light
        alias: Turn On
      - conditions:
          - condition: device
            type: is_on
            device_id: 8c4358a1b165a06eed9838b37936dc7e
            entity_id: d5f3a65d41488e0aed0cc34140f6cc47
            domain: light
        sequence:
          - type: turn_off
            device_id: 8c4358a1b165a06eed9838b37936dc7e
            entity_id: d5f3a65d41488e0aed0cc34140f6cc47
            domain: light
        alias: Turn Off
    enabled: true
mode: single
![Screenshot 2024-12-07 at 3.33.09 PM|405x500](upload://zcz43fCJ7pfpjRYCUbYgtllP1Td.png)


Did you manage to do this in ZHA?
As far as I understand the advanced features only work as expected with Z2M, not with ZHA (also your screenshot is showing more options than in my ZHA instance with Core 2024.12.1)

E.g.: With ZHA The detached relay mode is not working (behaviour as described by others in this thread.

If you made this work in ZHA, please tell us how

Ahh i missed that bit, this is Z2M, apologies!

I did have to modify my triggers to only be triggered if an action is “toggle” not just any state. When it was “any state” they would randomly turn on.

There is a matching bug, it seems like the problem is already identified.

1 Like

Hi,
I bought the ZBMINI L2 just for the “DETACH” mode.
I cannot use the Z2M because my Raspberry PI3B+ is no longer sufficient to run Z2M.
It just keeps looping.

I am therefore obliged to stay on ZHA.

When do you think this can be resolved?

THANKS