Should this work ?

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Dave21w
Posts: 361
Joined: Sunday 29 November 2015 21:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: UK
Contact:

Should this work ?

Post by Dave21w »

I'm cheating here and have used MS Copilot to write this in the hope I can learn from the code it shows me. I want to sync two physical zigbee light switches, only one has actual wiring to the lamp the other just gets power. Both switches have an LED in them so they can be found in the dark so they need to be in sync. Presently I have created 2 dummy toggle switches in Domoticz for testing purposes, I see no errors in the log but they do not interact with each other in anyway.

return {
active = true,
on = {
devices = { 'Switch1', 'Switch2' }
},
execute = function(domoticz, device)
local switch1 = domoticz.devices('Switch1')
local switch2 = domoticz.devices('Switch2')

if (device.id == switch1.id) then
switch2.switch(device.state)
else
switch1.switch(device.state)
end
end
}


Thanks
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Should this work ?

Post by waltervl »

No, this will not work. There is no command .switch(). Do not trust AI for dzvents as there are not enough good samples to scan. Better check the wiki https://www.domoticz.com/wiki/DzVents:_ ... _scripting
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Dave21w
Posts: 361
Joined: Sunday 29 November 2015 21:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: UK
Contact:

Re: Should this work ?

Post by Dave21w »

Well, I did read the wiki but still couldn't get anything to work my self so I went back to the AI and told it what happened when it didn't work and it's second attempt works just fine. I'm not trying to be lazy but now I have something that works I can learn from it myself as well. Just in case anyone wants to take a look this is what it wrote.
Attachments
Switch Sync.jpg
Switch Sync.jpg (77.35 KiB) Viewed 490 times
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Should this work ?

Post by waltervl »

You might want to play with quietOn/Off() or silent() to get rid of the debounce stuff.

quietOn(), quietOff() ==>> status in domoticz will change but command is not send to physically attached device. Subsequent events are triggered.
silent() ==>> status in domoticz will change and command is send to physically attached device. Subsequent events are not triggered
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: Bing [Bot] and 1 guest