Solutions to deal with Smart Light / Smart Wall Switch disconnect

If you´ve ever played with smart lights Im sure you´ve encountered this.

The light, unlike ordinary lights can now turn on/off on it´s own.

That means.

  • If the light is off, but power is on. Using the power switch will turn off the power. Yet, you would expect the light to turn on.
  • If you try to send a message to the light to turn on while the power is off. It will timeout.

So. Im using zigbee2mqtt, mosquitto, node-red and homeassistent. The latter ive so far only used as a pretty GUI and done all the automation in node-red.

I got a smart wall switches to try and solve it. So far my solutions to deal with it have looked something like this in node-red.

function node

switch(msg.topic) 
{
    // Light Switch Update
    case 'zigbee2mqtt/LightSwitchBedRoom':
        context.set('LightSwitchBedState', msg.payload.state);
        const lightState = context.get('LightBedState');
        
        // Turn on both if switch turns OFF, but light was OFF
        if(lightState == 'OFF' && msg.payload.state == 'OFF') {
            return {
                topic: 'Both',
                payload: { state: 'ON' }
            }
        }
        
        break;
    
    // Light Update
    case 'zigbee2mqtt/LightBed/set':
        context.set('LightBedState', msg.payload.state);
        const switchState = context.get('LightSwitchBedState');
        
        // Turn on Switch if Light should turn on
        if(switchState == 'OFF' && msg.payload.state == 'ON') {
            return {
                topic: 'SwitchOnly',
                payload: { state: 'ON' }
            }
        }
        
        break;
}

return;

While that works it seems pretty redicolous of a solution. And there are still some disconnects. When I turn off the light switch home assistant still thinks the light is on. The 1s delay thing is also just to sync up with home assistant. Sending ON to the light is redundant because it turns on if the power goes ON. But home assistent does not get the memo and if I send it instantly it also sometimes does not.

Now I could ofc put the switch into ‘decoupled’ mode. A feature it suports to just not physically switch on/off the power. But then if my system fails for any reason whatsoever I have no way to turn on/off the lights anymore without resetting everything.


Curious if you have had this issue. How did you deal with it? Did you deal with it, or just accept it?

1 Like

The first question would be, are your switches and Lights running ESP and/or Tasmota or are they going through the internet cloud?

That logic does not float unless the relay in the switch is uncoupled from the power.

Example, a stock smart switch flips a relay that kills power to the circuit that it is controlling. So there is actually no power going to the like. The flip side of that is that if you turn the switch on but tell the light to turn off, it is still getting power, but it has flipped its internal relay off to kill power, while the switch’s relay is sending power to the circuit.

I have IKEA Tradfri lights in a few placed due to dumb light switch placement. I use a rule in Home Assistant and Tasmota that lets me long press the closest light switch to trigger the power on and power off of those lights in addition to the remote that comes with the Tradfri hub.

You may need to setup home assistant to ask all of your devices for a Last Will and Testament and to turn on/off device state persistence.

So… ZigBee is a protocol kinda like wifi. But specifically for iot stuff. Data rates are low, but power requirements are also much lower. So you can have small battery powered devices that last much longer than they would over wifi. Though you do need a hub to connect them to. Just like wifi needs an access point. Normally every vendor has their own hub you need to buy.

Zigbee2Mqtt is kind of a local open source competitor to proprietary hubs you would otherwise be forced to use with this kind of stuff. There is no cloud if you dont use the hub the box sais you need to buy. It can connect to devices from various vendors and sends the data to a mqtt broker. Also creates additional topics for home assistant discovery, if desired. Currently I have IKEA lights and switches from Xiaomi. It’s also honestly just less hassle because it’s not tied to any particular ecosystem. The list of stuff it supports is gigantic.

The xiaomi switches can do that. But I don’t want to do that, because then I cannot turn on the lights anymore at all if anything breaks. What I now do works, but it’s a bit of a grind to restore what you would expect a wall switch to do in a not so smart Home. I basically ‘fix it up’ after the fact and send additional updates.

Was just curious if there is any solutions in either home assistant or zigbee2mqtt to ‘tie’ a switch to a light and synchronize them. I did not really find anything.

You would have to use automation or scripts to do that.

o in my example, the switches actually send power to my dumb bulbs, but using a rule in tasmota on the device, it sends out a command to mqtt on the homeassistant server and then home assistant triggers the automation to allow me to long press the switch to turn off/on the smart bulb without affecting the dumb bulb that it is actually powering. I can still do a single press to turn on/off the dumb bulb. I would prefer to use multi-click but my wife did not want to have to remember how many clicks to do certain actions so the default in our house for alternate actions of a switch is long press for 1/2 seconds.

I recommend you check out DigiBlur’s YT channel for some pointers.

Automation on the device I can´t really currently do. The devices themselves run the stock firmware they came with. Can see how it´s nice to be able to do that. Not super motivated to flash every firmware on everything, but maybe i´ll give it a shot with one of the switches. Technically the best solution would be imo to disable switching on the switch unless the zigbee hub is not reachable.

Definitely this. Or get a Switch that you can flash with tasmota and just setup that one switch to do all of what you need to do… or are we talking about multiple switch with lights in multiple locations?

2 rooms are 1 switch and 1 light each. 1 room is 3 switches that are supposed to switch on/off 2 lights, but it´s really also only one switch that I would need to worry about there too. I have not (yet) installed them in that room. But I intend to only wire up the switch that really turns on/off the lights to the lights and the other two are just gonna toggle that one switch and not be connected to anything. Just need to figure out which switch it is that is connected to the lights directly.


But I do not think the switches I have are suppored by tasmota (Xiaomi WS-EUK01).


Most of the things the guy in the video talked about I already knew about. Except that you can pick what specific device you want a new device to pair with specifically. I also did a bit of a “Aqara dance” with those switches. I brought the hub to the switch, because I can´t exactly do it the other way around and they would not pair otherwise. Thankfully I do not really have a big enough place to have to worry much about how efficient my zigbee network turns out because of it.

Here is a list of all supported switches.

Yeah i do not see your swithes there.
I am partial to the Treatlife switched due to the feel and and build quality for the price. I despise the Martin Jerry switches. They are hella cheap in price but you pay for what you get and they feel so hollow. Also their relays are hella loud and delayed.

I had not watched the new video but I linked it because I thought it may be relevant. Look through his catalog of videos. He has a lot of different setups and tutorials. You may find what you are looking for there as he has worked with Zigbee an Z-Wave and BT hubs and controlled automations and actions via MQTT (without tasmota). Also his discord is very active and a lot of the maintainers of these things live there. We are a super helpful bunch.

Thank you for sharing such useful and relevant information! Really smart lamps help save electricity, which is very cool considering the rise in the price of all goods. I ordered my smart lamps at Vont Smart Bulb Color - Vont /, and now I am thinking about which electrical circuit scheme would suit me, and you gave me a great idea. I will certainly use this information and write later what I did. Thank you!

Sure…

Btw, don´t buy the switches I bought. I bought switches without a neutral wire because the dumb switches I had where connected without one and I did not think much further than buying switches that connect exactly the same way. Seems like if you show those no-neutral smart switches to an electrician hes confused af that that works at all and thats not without reason. Its a bit of a hack that comes with weird limitations. Wether or not it works at all depends on what you hook up to it. Your switch now needs a consumer for it to function, while it would not with a neutral wire. I have one that frequently malfunctions and I gotta replace. Because appearently the lamp it´s connected to needs to have a certain amount of idle power draw for the switch to work. So… no neutral smart switches, probably a bad idea if you can at all avoid it.

These are a safety hazard and will more than likely cause a fire or burn up in the future.

Don’t think it’s that bad those are toy sized electronics not an oven. The smart switch might use 1w at most. Either way with the wrong pairing it’s possible you end up damaging your light over time, it’s possible the light flickers when it’s ‘off’ and it’s possible it just constantly stops working like it did for me. I’m not gonna replace the once that work fine. Pretty expensive to do that. But I also would not buy them again.

I got the one switch with neutral wire now to replace the one without. That now works perfectly fine and does not disconnect anymore. I did put it into decoupled mode and clicking it once will switch on/off the light, not by turning on/off the power but by sending a signal to mqtt and then I send a toogle command to the light. If the system fails Im just gonna have to reset the switch to be able to use the light. I’ve now accepted that as it just makes for a more useable solution that does not do weird cr4p.

I also found a way to deal with my 3 wall switches in the hallway. They are also connected to a 2 smart lights. I put a shelly plus 1 in front of all of them and configured it in a similar fashion. As in decouple the shelly switch. When I press the physical light switches the shelly still sends that the state was changed, but it won’t toggle the power to light. Then I can turn on/off the light in software.

This is how that would look like, except I have 3 switches in between not only two.

I did not find any good zigbee alternatives. Things like the sonoff zbmini do not have a decoupled mode, so it would not help in my case. The shelly devices are very good and easy to use though. Their cloud is completely optional, it has integrated mqtt support, a rest api, direct integration for home assistant and many more. If you get one of these now I’d recommend against the very popular shelly 1, get one of their “gen 2” devices instead. They cost almost the same, but have some more features. As in the shelly plus 1 (direct replacement for shelly 1) can do https, mqtt with ssl, has a temperature sensor and temperature protection mechanism, you can use mqtt and cloud at the same time (if you care you had to choose with the gen1 devices).

Although my impression is that the shelly devices are more trustworthy than many wifi smart appliances. I still went ahead and created an IoT network (vlan) now for good measure. It now cannot reach my other network (except the mqtt server), cannot get to the gateway’s gui and it can’t get on the internet (just need to toggle off that rule if I need to do a device update).

Now I can buy all the chinese wifi IoT devices with questionable security without becoming a botnet. :sweat_smile:

1 Like

Shelly devices can be flashed with tasmota. If you don’t want to chance it, I would just tasmotize it.