Synchronize switches

Moderator: leecollings

Post Reply
snarf71
Posts: 2
Joined: Monday 08 March 2021 18:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Synchronize switches

Post 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
User avatar
waltervl
Posts: 5910
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Synchronize switches

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
snarf71
Posts: 2
Joined: Monday 08 March 2021 18:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Synchronize switches

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Synchronize switches

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Synchronize switches

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waltervl
Posts: 5910
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Synchronize switches

Post by waltervl »

Thank you @waaren, could not find the logic myself too.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest