Zigbee script problem.

Xiaomi, Ikea TRÅDFRI, Philips Hue and more.

Moderator: leecollings

Post Reply
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Zigbee script problem.

Post 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?
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Zigbee script problem.

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

Re: Zigbee script problem.

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Zigbee script problem.

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

Re: Zigbee script problem.

Post 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?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Zigbee script problem.

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest