Page 1 of 1

Programming error or dzVents error??

Posted: Saturday 16 March 2019 9:56
by EddyG
I have a Zigbee lamp and a KlikaanKlikuit switch.
The lamp itself is called "Overloop lamp" and the switch is called "Overloop lamp slave"
I would like to have the state of both devices synchronized.
I use this script, and it works fine.

Code: Select all

return {

        active = true,
--      active = false,
        on = {
                devices = { "Overloop lamp slave", "Overloop lamp" }
        },

        execute = function(domoticz, mySwitch)
                if mySwitch.name == "Overloop lamp" then
                        if (mySwitch.state == 'On') then
                                domoticz.devices("Overloop lamp slave").switchOn().checkFirst().silent()
                        else
                                domoticz.devices("Overloop lamp slave").switchOff().checkFirst().silent()
                        end
                elseif mySwitch.name == "Overloop lamp slave" then
                        if (mySwitch.state == 'On') then
                                domoticz.devices("Overloop lamp").switchOn().checkFirst().silent()
                        else
                                domoticz.devices("Overloop lamp").switchOff().checkFirst().silent()
                        end
                end
        end
}
BUT!!! in the logging of Domoticz I see this. So the script is called more than once.
How can this be prevented / solved.

Code: Select all

2019-03-16 09:48:29.525 Status: User: Admin initiated a switch command (819/Overloop lamp/On)
2019-03-16 09:48:30.105 (RFXCOM) Lighting 2 (Overloop lamp slave)
2019-03-16 09:48:30.273 (RFXCOM) Lighting 2 (Overloop lamp slave)
2019-03-16 09:48:30.067 Status: dzVents: Info: ------ Start external script: slave overloop.lua: Device: "Overloop lamp (Zigbee)", Index: 819
2019-03-16 09:48:30.071 Status: dzVents: Info: ------ Finished slave overloop.lua
2019-03-16 09:48:30.073 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-03-16 09:48:30.239 Status: dzVents: Info: ------ Start external script: slave overloop.lua: Device: "Overloop lamp (Zigbee)", Index: 819
2019-03-16 09:48:30.243 Status: dzVents: Info: ------ Finished slave overloop.lua
2019-03-16 09:48:30.244 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-03-16 09:48:30.411 Status: dzVents: Info: ------ Start external script: slave overloop.lua: Device: "Overloop lamp (Zigbee)", Index: 819
2019-03-16 09:48:30.415 Status: dzVents: Info: ------ Finished slave overloop.lua

Re: Programming error or dzVents error??

Posted: Saturday 16 March 2019 14:34
by waaren
EddyG wrote: Saturday 16 March 2019 9:56 I have a Zigbee lamp and a KlikaanKlikuit switch.
The lamp itself is called "Overloop lamp" and the switch is called "Overloop lamp slave"

Code: Select all

2019-03-16 09:48:30.105 (RFXCOM) Lighting 2 (Overloop lamp slave)
2019-03-16 09:48:30.273 (RFXCOM) Lighting 2 (Overloop lamp slave)
Looking at these lines in the log, it looks like RFXCOM generates two events when Overloop lamp slave is switched. If that is indeed the case dzVents will trigger the script twice. No way to prevent that.

Re: Programming error or dzVents error??

Posted: Saturday 16 March 2019 16:35
by EddyG
Due to some strange reason Domoticz generated the events more then one time.
Because I clicked in Domoticz on the 'slave' button.
I restarted Domoticz and the problem is gone. Actually I had to restart Raspberry.
But I think that Domoticz was 'meshedup' and creating the problem.

What I noticed now, is that the logging in Domoticz in not in cronological order.
Just an observation.

And still there is a problem!!! Just 1 click and 3 times the script???
Not always the same problem, sometimes the script is running twice.

Code: Select all

2019-03-16 16:47:44.919 (RFXCOM) Lighting 2 (Overloop lamp slave)
2019-03-16 16:47:44.908 Status: User: Admin initiated a switch command (110/Overloop lamp slave/Off)
2019-03-16 16:47:45.259 Status: dzVents: Info: ------ Start external script: slave overloop.lua: Device: "Overloop lamp slave (RFXCOM)", Index: 110
2019-03-16 16:47:45.267 Status: dzVents: Info: ------ Finished slave overloop.lua
2019-03-16 16:47:45.979 Status: dzVents: Info: ------ Start external script: slave overloop.lua: Device: "Overloop lamp (Zigbee)", Index: 819
2019-03-16 16:47:45.983 Status: dzVents: Info: ------ Finished slave overloop.lua
2019-03-16 16:47:46.761 Status: dzVents: Info: ------ Start external script: slave overloop.lua: Device: "Overloop lamp (Zigbee)", Index: 819
2019-03-16 16:47:46.765 Status: dzVents: Info: ------ Finished slave overloop.lua

Re: Programming error or dzVents error??

Posted: Saturday 16 March 2019 17:11
by EddyG
After some more testing it looks like the .silent() is not working properly.
After that is look like a racing condition.
Because the script get called several times.
Printing the .state of the devices give no result.

As time goes by results gets different.
It now seems that zigbee2mqtt has something to do with it.
I see in the zigbee logging

Code: Select all

3/16/2019, 5:33:16 PM - info: MQTT publish: topic 'zigbee2mqtt/Lamp', payload '{"state":"OFF","device":{"ieeeAddr":"0x0$
3/16/2019, 5:33:17 PM - info: MQTT publish: topic 'zigbee2mqtt/Lamp', payload '{"state":"OFF","device":{"ieeeAddr":"0x0$
3/16/2019, 5:33:17 PM - info: MQTT publish: topic 'zigbee2mqtt/Lamp', payload '{"state":"OFF","device":{"ieeeAddr":"0x0$
3
I have to check further.

Re: Programming error or dzVents error??

Posted: Saturday 16 March 2019 17:50
by EddyG

Code: Select all

3/16/2019, 5:47:29 PM - info: Zigbee publish to device '0x00158d0002b7d689', genOnOff - on - {} - {"manufSpec":0,"disDe$
3/16/2019, 5:47:29 PM - info: MQTT publish: topic 'zigbee2mqtt/Lamp', payload '{"state":"ON","device":{"ieeeAddr":"0x00$
3/16/2019, 5:47:29 PM - info: MQTT publish: topic 'zigbee2mqtt/Lamp', payload '{"state":"ON","device":{"ieeeAddr":"0x00$
It seems that zigbee2mqtt is the problem. I am out off options where to look for the solution.
Anybody any ideas???

Re: Programming error or dzVents error??

Posted: Saturday 16 March 2019 20:48
by EddyG
It seems to be an expected behaviour from zigbee2mqtt, see https://github.com/Koenkk/zigbee2mqtt/i ... -467094619
I still think that this should be minimized to 1 message.