Page 1 of 1

Keeping a wall switch and a plug in sync

Posted: Monday 04 June 2018 13:51
by rrozema
You've got a wall switch and a plug that you want to keep in sync. If the wall switch is switched, you want the plug to follow with it and vice versa, if the plug gets switched, you want the wall switch to follow the plug.

Here's a script that I use to do this. Just replace the device names with your device names and the 2 switches should follow each other's lead. It doesn't really matter which switch is called master and which is called slave, I just needed the variable names to be clearly distinguishable:

Code: Select all

local MASTER = 'Keuken: Aanrecht'
local SLAVE = 'Keuken: S3'

return {
	on = {
		devices = {
			MASTER,
			SLAVE
		}
	},
    execute = function(domoticz, device, triggerInfo)
        if (domoticz.EVENT_TYPE_TIMER == triggerInfo.type) then
            domoticz.log( 'timer event: '..tostring(triggerInfo.trigger)..'.', domoticz.LOG_INFO)

        elseif (domoticz.EVENT_TYPE_DEVICE == triggerInfo.type) then
            if (device.name == MASTER) then
                if (device.state ~= domoticz.devices(SLAVE).state) then
                    domoticz.devices(SLAVE).setState(device.state).silent()
                end
            elseif (device.name == SLAVE) then
                if (device.state ~= domoticz.devices(MASTER).state) then
                    domoticz.devices(MASTER).setState(device.state).silent()
                end
            end
        end
    end
}

Re: Keeping a wall switch and a plug in sync

Posted: Sunday 08 July 2018 19:27
by rrozema
Please note that in this process only 1 switch is actually connected by wire to the light. The 2nd switch controls the 1st switch (that is connected by wire) via z-wave. The 2nd switch is NOT wired to the light at all. i.e. the 2nd switch only has a blue and brown wire, and no black wire!

This script was written with neo coolcam's touch switches in mind: I've replace a single channel normal switch with a 2 channel neo coolcam touch switch. Only one of the L1 and L2 terminals has a black wire in it, that is the switch that controls the original light. The other switch I use to trigger the above script to control a plug in the room. This way I can both switch the ceiling light (the original light) using the left touch pad and another light/fan or whatever I plug into the plug using the right touch pad.

Re: Keeping a wall switch and a plug in sync

Posted: Saturday 13 April 2019 22:29
by dizzeenl
Thanks a lot, works like a charm!

Re: Keeping a wall switch and a plug in sync

Posted: Wednesday 13 May 2020 20:06
by andrevanderlei
Hello...

Sorry to bump your nice script. I am trying to get master/slave solution for 2 (single) wall switches (neo cool cam). It works when I use it with the app or dashboard, when I use the buttons (physical) on the wall switch they don't change together.

I also tried the master/slave solution provided by domoticz. (didn't work)
I also tried to use the JSON commands on and off within the switch itself. (didn't work)

I hope you can tell me if I'm missing something. I used the exact same script and only changed the switch names.

Re: Keeping a wall switch and a plug in sync

Posted: Thursday 14 May 2020 20:14
by rrozema
The master/slave settings in domoticz will not do what you expect of it. It serves another purpose.

I have replaced the script you use by a more generic version. It is called auto-onoff. Im typing from my phone so can't give you the URL. If you search for auto-onoff you should find it easily.

Looking at your description the new version will however most likely have the exact same problem. What exactly that problem is I am not sure of. What type of switches are you using zwave or wifi?

If you press the physical switch, does the switch icon in domoticz change state?

Re: Keeping a wall switch and a plug in sync

Posted: Saturday 13 January 2024 18:42
by FriedlNetDZ
Works like a charme, thank you very much!!
That's exactly what I was looking for.
Can someone give me a hint if there is a script for more than two switches?

Re: Keeping a wall switch and a plug in sync

Posted: Saturday 13 January 2024 18:48
by willemd
FriedlNetDZ wrote: Saturday 13 January 2024 18:42 Works like a charme, thank you very much!!
That's exactly what I was looking for.
Can someone give me a hint if there is a script for more than two switches?
something like this?
Maybe not exactly what you are looking for but could be used for inspiration .....