Keeping a wall switch and a plug in sync
Posted: Monday 04 June 2018 13:51
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:
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
}