Page 1 of 1

Zigbee script problem.

Posted: Friday 17 September 2021 11:31
by EddyG
I have this simple script for a master slave setup.

Code: Select all

local MASTER = 'Switch MASTER'
local SLAVE1 = 'Lamp SLAVE1'
local SLAVE2 = 'Lamp SLAVE2'

return {
    active = true,
--  active = false,

    on = { devices = { MASTER, SLAVE1, SLAVE2 }
    },

    logging = {
--      level = domoticz.LOG_INFO,
        level = domoticz.LOG_DEBUG,
    },

    execute = function(dz, device, triggerInfo)
        if device.name == MASTER then
            if device.state == 'On' then
                dz.devices(SLAVE1).switchOn().silent()
                dz.devices(SLAVE2).switchOn().silent()
            else
                dz.devices(SLAVE1).switchOff().silent()
                dz.devices(SLAVE2).switchOff().silent()
            end
        else
            if dz.devices(SLAVE1).state == 'On' or dz.devices(SLAVE2).state == 'On' then
                dz.devices(MASTER).switchOn().silent()
            else
                dz.devices(MASTER).switchOff().silent()
            end
        end
    end
}
The script functions almost good.
The problem is with zigbee. Both SLAVE1 and SLAVE2 are this bulb https://www.zigbee2mqtt.io/devices/LED1 ... Fled1835c6
SLAVE1 behaves normal with 1 zigbee message, but SLAVE2 send 1 second later a second message, and of course on that second message the 'silent()' does not apply and that triggers an unwanted script activation.
The script also has an strange (and unwanted) side effect that every third click on MASTER is NOT processed by Domoticz.
So what am I doing wrong? What could be better? Who has a better Master/Slave script. How can I prevent the second zigbee message?

Re: Zigbee script problem.

Posted: Friday 17 September 2021 11:39
by EddyG
Oeps, found the solution for the unwanted side effect. I put .checkFirst() in every activation line.
Do not understand why it solved it, but it did the trick.
That solved the side effect, but the second Zigbee message problem remains.

Re: Zigbee script problem.

Posted: Friday 17 September 2021 11:42
by waltervl
You know that you can work with Zigbee Groups in Zigbee2mqtt, which is much faster and easier than letting Domoticz switching on/off separate devices?
https://github.com/stas-demydiuk/domoti ... ps-support

Re: Zigbee script problem.

Posted: Friday 17 September 2021 13:06
by EddyG
I tried binding but this device (My master) does not support that https://www.zigbee2mqtt.io/devices/TS00 ... uya-ts0002
I tried groups but the problem is that I already have a binding of two times this switch https://www.zigbee2mqtt.io/devices/E1743.html to each of the slaves. This is because I want to be sure I can switch on the light near my bed independent of Domoticz and zigbee.
That combi did not work well with groups, so I switched to scripting.
That brings me back to the remaining questions.
How can I prevent the second message from zigbee2mqtt?
Why and how does .checkFirst() solve my initial problem?

Re: Zigbee script problem.

Posted: Friday 17 September 2021 15:04
by waltervl
Check your MQTT messages to see what is triggering this, could be a MQTT loop.
Are SLAVE1 and 2 only switched on and off by this script or also by another?

Re: Zigbee script problem.

Posted: Friday 17 September 2021 17:01
by EddyG
Like I wrote only 1 of the 2 SLAVES is sending a second (same) message to MQTT.
There is only 1 script for this MASTER and 2 SLAVES.
I will check if lastUpdate might be of help to filter out the second messages.
Remains the fact that I have to include .checkFirst() to make the script work as intended, that still is a mystery.