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.
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?
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.
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.
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
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
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:
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.
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.