Some zigbee devices (Sonoff ZB Mini and possibly Tuya) read input from a switch and set the state of a relay automatically, i.e. the switch and relay are coupled on the device. They also allow the relay state to be read and controlled remotely.
When connected to a smart lightbulb these turn off power to the bulb when switched, meaning the bulb goes offline and its setting can’t be changed directly. This blueprint decouples the switch and relay. The relay output is controlled by a toggle/input_boolean helper, and the output can be directly routed to the smart lightbulb.
The bulb remains powered even when the physical switch is toggled
The bulb can be isolated using a software switch in HA
The switch can still control the output of the bulb
If the automation is disabled the switch reverts to directly controlling power to the bulb.
Due to the delay of going through an automation the lights flicker when the physical switch is toggled.
blueprint:
name: Decouple Sonoff ZBMini
description: v1.0.0 Separate the switch input and the relay output of a Sonoff zbMini device.
domain: automation
author: Stephen Turner
input:
zbMini:
name: ZBMini device
description: The device to be decoupled
selector:
entity:
filter:
- domain: switch
isolator:
name: Virtual isolator
description: An input_boolean helper device, the state of this will control the output relay
selector:
entity:
filter:
domain: input_boolean
controlled_light:
name: Switched target lights
description: One or more light entities, The switch connected to the ZBMini will toggle these
selector:
target:
entity:
domain: light
trigger:
- platform: state
entity_id:
- !input isolator
- !input zbMini
condition:
- condition: or
conditions:
- condition: and
conditions:
- condition: state
entity_id: !input isolator
state: "off"
- condition: state
entity_id: !input zbMini
state: "on"
- condition: and
conditions:
- condition: state
entity_id: !input isolator
state: "on"
- condition: state
entity_id: !input zbMini
state: "off"
action:
- service: switch.toggle
data: {}
target:
entity_id: !input zbMini
- service: light.toggle
data: {}
target:
!input controlled_light
mode: single
I don’t know as I don’t have the same config, give it a try and let us know what you find. The blueprint itself is pretty simple so you should be able to alter it to suit your needs.
OK, got it working. Fault was, as usual, between the seat and the monitor.
Very useful blueprint. Thank you.
Not using the Sonoff switch but the Tuya (Moes) one instead. Would be wise update the description of blueprint accordingly.
I have update suggestion as well:
currently, it switches the bulb ON its last known brightness state. It would be nice if I could override brightness and set it to any value (precentage) when switching ON. I personally need 100% as I’m using wall switches as “reset” if needed and seems that users expect wall switches+bulb work in usual manner.
Hell yeah, it would be great if i can get to make this work. Does this work with a Sonoff ZBMINI-L? So without a neutral? Im a newbie with HA and switches so any help on these and how to connect would be much appreciated. I already disconnected my ZBMINI-L because the combination of a smart light swith with smart lights didn’t work because of the cut off power to the lights. This would stop this, right?
@jeroenva1981
Test it out if it works for you or not. Takes just a couple of minutes. I could not see any limitations as all it does is switch the relay back ON and sets the binary helper either ON or OFF. Also, please note: if you can not switch your bulb off any more then you have to switch binary helper manually once. This fixes it.
@macintoshee Yes, it came to me at an odd time. The switch should appear to keep working as it did before, however instead of the switch turning off power to the smartbulb, it keeps power on going and tells the smartbulb to turn off.
Thanks so much for this. I managed to get this working on the sonoff ZBMINI L2 (No neutral wire ZigBee version). When smart bulb is on and I hit the physical light switch the smart bulb turns off but is still powered and can be controlled via HA or Google Voice commends etc. However if the smart bulb is off and I hit the physical light switch this does not turn on the bulb.
Also after 4 or 5 tries it stops working all of a sudden until I toggle the isolator which kills power to the smart bulb.
so if I turn the physical switch off the sonoff gets no power and won’t do anything until someone flicks the switch again. I assume I need to re wire it in some way. and did you manage to ever get the smart bulb to turn on via the physical switch? I’ve currently got it wired to an extractor fan, but my initial plan was to put them in light switches so that can both use physical and ha based switches to turn it on/off and not get the issue where someone turns the switch off and have to turn it on again physically to use it again
Hi Stephen, I have similar switches (the L2 with no neutral) and have been considering making a similar automation. Currently I only employ these with dumb lights. If I see it correctly what you do here is toggle the state of both the light and the switch if the state of the switch is not the same as the state of the virtual isolator. Two questions for you:
1: Do you see any delay in the commands? One would expect the light to flash briefly after you switch it off with the physical switch, if there is a delay between the light powering up when the zbmini switches on, and the command to switch it off being processed. This of course depends on the configuration of the light, most notably the ‘start-up behavior’ setting. I have my lights set to ‘On’ as power up behavior, so I can always switch them with the physical switch if the communication with the HA instance is not working.
2: If I see it correctly, your automation will toggle the zbMini back from ‘on’ to ‘off’ if I switch it on with the physical switch while the virtual switch is set to ‘off’ (first AND condition satisfied). That seems at odds with the goal to keep the bulb powered at all times and still being able to control the bulb with the physical switch. Am I reading it wrong?
Yes, there is a slight delay I’d say it’s somewhere around 50ms.
When I switch off the light it briefly turns off completely then comes back on before fading to zero over 500ms or so, I think that fade is software controlled. There is also a double click as the relay switches off then on again. I don’t see a flash as I switch it on, the bulb is in the off state but is powered from the relay, switching it on briefly disconnects the bulb, then the bulb fades in after the relay has double clicked.
If you have a power on behaviour that turns the bulb on when power is first applied then you might not be able to turn it off. The brief disconnect might be triggering this behaviour.
The virtual switch is what I’ve called the Isolator (off is isolated, on is connected). The aim is that this disconnects the bulb when the isolator is off and leaves it powered when the isolator is on. This is independent of you switching the physical switch.
However, due to the same delay there is a brief flash of power to the bulb whenever the physical switch connected to the relay is toggled.
Of course disconnect the circuit at the junction box if you plan to work on the wiring. The virtual ‘isolator’ isn’t 100%.
I think you are reading it right, just the goal changes to keep the bulb mostly off is the isolator is off.