Keeping a wall switch and a plug in sync

Moderator: leecollings

Post Reply
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Keeping a wall switch and a plug in sync

Post 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
}
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Keeping a wall switch and a plug in sync

Post 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.
dizzeenl
Posts: 31
Joined: Wednesday 14 November 2018 23:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Dordrecht
Contact:

Re: Keeping a wall switch and a plug in sync

Post by dizzeenl »

Thanks a lot, works like a charm!
andrevanderlei
Posts: 1
Joined: Sunday 18 August 2019 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Keeping a wall switch and a plug in sync

Post 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.
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Keeping a wall switch and a plug in sync

Post 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?
FriedlNetDZ
Posts: 3
Joined: Wednesday 03 January 2024 8:15
Target OS: Linux
Domoticz version: 2024.1
Contact:

Re: Keeping a wall switch and a plug in sync

Post 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?
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Keeping a wall switch and a plug in sync

Post 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 .....
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest