Page 1 of 1

Synchronize switches

Posted: Monday 08 March 2021 19:08
by snarf71
Hey,

I have a script that sync's 2 switches, works fine but after 1 or 2 weeks the switches bigins to flicker (on/off) very fast.
I have to reboot the pi to stop the flickering.

Does someone have a solution or other script?

Code: Select all

commandArray = {}

-- variabeles
local Switch1 = 'Firstfloor'
local Switch2 = 'Secondfloor'

-- sync switches
for deviceName,deviceValue in pairs(devicechanged) do
    if (deviceName == Switch1) then
        if (deviceValue ~= otherdevices[Switch2]) then
            commandArray[Switch2] = deviceValue
        end
    elseif (deviceName == Switch2) then
        if (deviceValue ~= otherdevices[Switch1]) then
            commandArray[Switch1] = deviceValue
        end
    end
end

return commandArray

Re: Synchronize switches

Posted: Monday 08 March 2021 22:30
by waltervl
Do not use the elseif but again a normal if while checking the devices.
Although not sure it is really the solution. This kind of sync is asking for trouble: the update of 1 switch will trigger the update of another. Which can trigger the first switch again if domoticz is not changing the device list fast enough.

Re: Synchronize switches

Posted: Monday 08 March 2021 22:47
by snarf71
waltervl wrote: Monday 08 March 2021 22:30 Do not use the elseif but again a normal if while checking the devices.
Although not sure it is really the solution. This kind of sync is asking for trouble: the update of 1 switch will trigger the update of another. Which can trigger the first switch again if domoticz is not changing the device list fast enough.
Thanks Walter, I'm going to give it a try. Do you know another solution to sync devices?

Re: Synchronize switches

Posted: Tuesday 09 March 2021 0:17
by waaren
waltervl wrote: Monday 08 March 2021 22:30 Do not use the elseif but again a normal if while checking the devices.
Although not sure it is really the solution. This kind of sync is asking for trouble: the update of 1 switch will trigger the update of another. Which can trigger the first switch again if domoticz is not changing the device list fast enough.
Sorry but I fail to see the logic of this answer. Maybe I overlook something but I don't see how changing the elseif to an if would help here.

Re: Synchronize switches

Posted: Tuesday 09 March 2021 0:21
by waaren
snarf71 wrote: Monday 08 March 2021 19:08 Does someone have a solution or other script?
use the NOTRIGGER option like in below example.

Code: Select all

commandArray = {}

hotel = 
{   -- master      slave
    Firstfloor = 'Secondfloor',
    Secondfloor = 'Firstfloor',
}
 
for device, value in pairs(devicechanged) do
    if hotel[device] then 
        print('Hotel: State of device ' .. device .. ' changed. Updating ' .. hotel[device] .. ' to ' .. value  )
        commandArray[ hotel[device] ] = value .. ' NOTRIGGER' 
    end
end

return commandArray

Re: Synchronize switches

Posted: Tuesday 09 March 2021 1:00
by waltervl
Thank you @waaren, could not find the logic myself too.