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.