ZBMINIR2 detach relay mode

Blueprint to manage SONOFF ZBMINIR2 option “Detach relay mode” .

That means the states of external switch and relay are separated and associated lights never run out of power.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: ZBMINIR2 detached relay mode
  description: Configure ZBMINIR2 to toggle light without turn off the switch.
  domain: automation
  source_url: https://github.com/alexsotoaguilera/homeassistant/tree/main/blueprints/automation/alexsotoaguilera/ZBMINIR2-detached-relay-mode.yaml
  author: Alex Soto Aguilera
  homeassistant:
    min_version: 2022.4.0

  input:
    zbminir2_device:
      name: ZBMINIR2 device
      description: ZBMINIR2 device, ensure to activate "Detach relay mode"
      selector:
        device:
          filter:
            manufacturer: SONOFF
            model: Zigbee smart switch
          multiple: false

    controlled_light:
      name: Toggle target lights
      description: The switch will toggle these lights.
      selector:
        entity:
          filter:
            domain: light
          multiple: true

triggers:
  - domain: mqtt
    device_id: !input "zbminir2_device"
    type: action
    subtype: toggle
    trigger: device

variables:
  zbminir2_device: !input "zbminir2_device"
  zbminir2_switch: "{{ device_entities(zbminir2_device)[0] }}"

actions:
  - choose:
      - conditions:
          - alias: "ZBMINIR2 switch is OFF"
            condition: template
            value_template: "{{ states(zbminir2_switch) == 'off' }}"
        sequence:
          - service: switch.turn_on
            data:
              entity_id: "{{ zbminir2_switch }}"
      - conditions:
          - alias: "ZBMINIR2 switch is ON"
            condition: template
            value_template: "{{ states(zbminir2_switch) == 'on' }}"
        sequence:
          - action: light.toggle
            metadata: {}
            data: {}
            target:
              entity_id: !input "controlled_light"

mode: single

Changelog

  • October 27, 2024: Initial release
  • October 31, 2024: Renamed and added source_url
  • January 20, 2025: Renamed model to fix filter
7 Likes

Oh if the relay is OFF it will turn ON - that is a smart move!

that solves if the power outages occurs and the relay is configured to start OFF.

1 Like

I am new to HA, using HA OS, imported blueprint, added Sonoff ZbminiR2 via Z2M, enabled detach mode, but under device, it shows no matching device found. Please help.

Fixed, you can reimport the blueprint and test it.

Am I getting this right - ZBMINIR2 in detached mode must go through HA automation to do something and it cannot be directly bound to a smart light via z2mqtt with the physical switch triggering it?

Tried this but my ZBMINIR2 switches are not detected when i want to select a ZBMINIR2 device that is in Detach relay mode. so i cannot use this?

Deice info:



ZBMINIR2
by SONOFF
Connected via Texas Instruments CC2652
Zigbee info
IEEE: 1c:c0:89:ff:fe:fb:2c:5f
Nwk: 0xc662
Device Type: Router
LQI: 87
RSSI: Unknown
Last seen: 2025-04-20T10:41:28
Power source: Mains
Quirk: zigpy.quirks.v2.CustomDeviceV2

1 Like

that solves if the power outages occurs and the relay is configured to start OFF.

Why not use Power-on behavior Toggle instead of off?

In detached mode relay and button are separated. Each time zbminir2 receives a pulsation it sends a “toggle” event. Then you must create an automatization to turn on the light. Advantage is you can do events with this pulsation.

2 Likes

You can change this in configuration. I am using zb2mqtt and not ZHA

1 Like

Feature Request for this Blueprint: Simple, Doble and Long Click for ZBMINIR2 with different actions for each one.

Thanks @lynks for sharing the blueprint.
Based on this I’ve created my first own blueprint.

As the ZBMINIR2 doesn’t support double click natively, I tried to create a workaround by counting the number of running automations.
The automation is triggered by the same click trigger but the light (or switch) is just toggled if the second automation is triggered during 2 seconds.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: ZBMINIR2 Double-Click
  description: Toggles light on double click without turn off the switch of ZBMINIR2. Detached Relay has to be enabled
  domain: automation
  author: Christian Herkenhoff
  input:
    zbminir2_device:
      name: ZBMINIR2 device
      description: ZBMINIR2 device, ensure to activate "Detach relay mode"
      selector:
        device:
          filter:
            - manufacturer: SONOFF
              model: Zigbee smart switch
          multiple: false
    target:
      name: Toggle target lights or switches
      description: Double click will toggle the lights or switches
      selector:
        entity:
          filter:
            - domain:
                - light
                - switch
          multiple: true

# Allow multiple executions in parallel, up to 2 at the same time
mode: parallel
max: 2

# Trigger on MQTT device button press
triggers:
  - domain: mqtt
    device_id: !input zbminir2_device
    type: action
    subtype: toggle
    trigger: device

condition: []

action:
  # Check if this is the first active instance
  - if:
      - condition: template
        alias: Second execution of automation
        value_template: "{{ this.attributes.current == 1 }}"
    then:
      # Toggle the light only if this is the second execution
      # Only toggle if list is not empty
      - action: homeassistant.toggle
        target:
          entity_id: !input target
    else:
      # On first execution, wait 2 seconds
      - delay:
          seconds: 2
1 Like

Note:

  • IEEE Address (zbminir2_ieee): This is required to filter zha_event for the correct device. You can find it in:
    • Home Assistant UI: Settings > Devices & Services > ZHA > Your Device > Zigbee Info > IEEE.
  • Entity Selection: You now select the switch entity directly (instead of relying on device_entities()).

Same for me :frowning:

Safed the Day!
Thanks a lot for this fine blueprint !!!

firstly, huge thanks for posting…this just works…and works really well

But I don’t know how it works as there is no exposed sensor in MQTT or Z2M showing the state of the detached swtiche so I don’t know how this works.

Now some might be very happy to just accept it works. and that will happen Im sure, but Im really scratching my head how this is possible when I can’t see any sensor states changing when detached mode is activated and the physical switch is toggled

Am I missing something really stupid here?

The trick is that the blueprint never looks at a classic sensor like sensor.xxx_action, so you won’t see any state change there.​

In the YAML you’ll see the trigger section:

text

triggers:
  - domain: mqtt
    device_id: !input "zbminir2_device"
    type: action
    subtype: toggle
    trigger: device

That means Home Assistant uses a device trigger coming from Z2M (type: action, subtype: toggle) instead of an entity state.​

When you flip the physical switch in detached mode, Zigbee2MQTT sends an action: "toggle" event for that device over MQTT, and HA catches it as a device trigger. There’s no exposed sensor.xxx_action entity changing state, just an internal event that fires the automation.​

Then in actions: the blueprint checks the current state of the ZBMINIR2 switch entity and either turns the relay on or toggles the target light:

text

zbminir2_switch: "{{ device_entities(zbminir2_device)[0] }}"

and uses that entity only to decide what to do, not as the trigger itself.​

So yes – you’re not missing a sensor, it’s just that everything is happening via device/MQTT actions under the hood instead of a visible HA sensor state.

1 Like

ill probably have to read this about 5 times to make sense of it…as I dont understand how there can be no sensor data transferred anywhere. Even in Z2M itself nothing seems to be showing any sort of state change regardless of how it is labelled

Does this mean it can ONLY be done with a blueprint or could it be done with a stadard automation in some way as well?

It doesn’t have to be a blueprint at all – the blueprint is just a reusable template for an automation.

Under the hood this is “only” a normal automation with:

  • a device trigger of type action / toggle for the ZBMINIR2 device (coming from Z2M), and
  • whatever actions you want to run when that trigger fires.

So yes, you can absolutely do it as a standard automation: just create a new automation, choose your ZBMINIR2 as the trigger device, pick the action / toggle trigger, and then add the same actions that the blueprint uses. The blueprint just makes it easier to reuse the same logic for many devices, but it’s not the only way.

1 Like

thanks for explaining…makes much more sense now…