Page 1 of 1

Push button dzvents script goes double when turning off

Posted: Friday 11 January 2019 22:44
by jantjegroen00
I have a zwave button which i have added to domoticz.
In another page i found a script to toggle another light when pushing the button.

Code: Select all

return {

   on = { devices = { "XButton" }},        -- Name of your button
               
   execute = function(dz, item )
        if item.state == "Click" then
            dz.devices("Yeelight").toggleSwitch()    -- Name of your Yeelight
        end
   end
}
This works but everything I switch using Dzvents scripts (i tried other scripts that use if and else to check if the light is on) when turning the light or wall plug of it switches double. This causes the light to turn of but it's still on in domoticz because domoticz receives the command 2 times.
The light itself cannot respond that fast so the light itself is off, but the in domoticz it is still on. The next time i press the button nothing happens because the light in domoticz will be switches off so i have to press 2 times to switch the light on.

2019-01-11 21:42:50.374 (Z-Wave) Light/Switch (Stalamp Woonkamer)
2019-01-11 21:42:50.429 (Z-Wave) Light/Switch (Stalamp Woonkamer)
2019-01-11 21:42:50.720 (P1 Smart Meter) P1 Smart Meter (Stroom)
2019-01-11 21:42:50.721 (P1 Smart Meter) General/Voltage (Voltage L1)
2019-01-11 21:42:50.237 Status: dzVents: Info: Handling events for: "Knop", value: "On"
2019-01-11 21:42:50.237 Status: dzVents: Info: ------ Start internal script: test: Device: "Knop (Z-Wave)", Index: 947
2019-01-11 21:42:50.238 Status: dzVents: Info: ------ Finished test
2019-01-11 21:42:50.328 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua

It's for the " Stalamp Woonkamer".
Does anybody has this same problem or can help me with this?

Regards.

Re: Push button dzvents script goes double when turning off

Posted: Saturday 12 January 2019 12:08
by waaren
jantjegroen00 wrote: Friday 11 January 2019 22:44 I have a zwave button which i have added to domoticz.
The light itself is off, but the in domoticz it is still on. The next time i press the button nothing happens because the light in domoticz will be switches off so i have to press 2 times to switch the light on.
Sorry, I find it hard to understand what actually happens based on this post. Can you please describe step by step what is happening from button to domoticz to dzVents to light ? Maybe by getting a "better picture" on the sequence of events someone can come up with a workaround or solution. Thx

Re: Push button dzvents script goes double when turning off

Posted: Sunday 13 January 2019 15:20
by jantjegroen00
Oke, i have a Dzvents script that toggles a light switch (Stalamp Woonkamer) whenever i press my z-wave button.

Step1: Push Z-wave button
Step2: Script is triggered (if light is on, turn it off, if light is off turn it on)
Step3: light is turned on or off.

However most times I have to press the z-wave button 2 times because as you can see in the logs

2019-01-11 21:42:50.374 (Z-Wave) Light/Switch (Stalamp Woonkamer)
2019-01-11 21:42:50.429 (Z-Wave) Light/Switch (Stalamp Woonkamer)

Sometimes the script sends 2 command to the light switch.
This happens so fast that the light itself does not have time to respond, but domoticz does.
So if the light is switched off, domoticz get's 2 commands and switches it back on in the dashboard.
However the light itself is still off.

So the next time I push the button Domoticz checks the light (In Domoticz it's on but the light is off) it switches it off because domoticz thinks it's on.
So nothing happens when i look at the light.
Now domoticz and the light are both off and when i press the button again the light turns on.
Once again the script triggers 2 events marking the light off in domoticz but the light itself is on.

Hopefully it's better understandable now.

Re: Push button dzvents script goes double when turning off

Posted: Thursday 17 January 2019 1:08
by waaren
jantjegroen00 wrote: Sunday 13 January 2019 15:20 2019-01-11 21:42:50.374 (Z-Wave) Light/Switch (Stalamp Woonkamer)
2019-01-11 21:42:50.429 (Z-Wave) Light/Switch (Stalamp Woonkamer)
This is output from domoticz but not directly from the script.
Sometimes the script sends 2 command to the light switch.
This can only happen when triggered twice or when you have two toggle commands in your script. What I see in the log you posted is that the script is only triggered once. Can you share the script here or add some relevant domoticz.log statements to it and post that part of the script that shows what happens when pressing the button ?

Re: Push button dzvents script goes double when turning off

Posted: Monday 21 January 2019 9:18
by jantjegroen00
The script is in the original post.

Code: Select all

-- Check the wiki at
-- http://www.domoticz.com/wiki/%27dzVents%27:_next_generation_LUA_scripting
return {

	-- 'active' controls if this entire script is considered or not
	active = true, -- set to false to disable this script

	on = {
		devices = {
			'Knop' -- device name
		},
	},

	-- actual event code
	-- in case of a timer event or security event, device == nil
	execute = function(domoticz, switch)

    if(switch.state == 'On') then
        if (domoticz.devices('Koffie').state == 'Off') then    
    			    domoticz.devices('Koffie').switchOn()
    	else	    domoticz.devices('Koffie').switchOff()
    	end
    	            
    end
   
end
}
Log

2019-01-11 21:42:50.374 (Z-Wave) Light/Switch (Stalamp Woonkamer)
2019-01-11 21:42:50.429 (Z-Wave) Light/Switch (Stalamp Woonkamer)
2019-01-11 21:42:50.720 (P1 Smart Meter) P1 Smart Meter (Stroom)
2019-01-11 21:42:50.721 (P1 Smart Meter) General/Voltage (Voltage L1)
2019-01-11 21:42:50.237 Status: dzVents: Info: Handling events for: "Knop", value: "On"
2019-01-11 21:42:50.237 Status: dzVents: Info: ------ Start internal script: test: Device: "Knop (Z-Wave)", Index: 947
2019-01-11 21:42:50.238 Status: dzVents: Info: ------ Finished test
2019-01-11 21:42:50.328 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua

Re: Push button dzvents script goes double when turning off

Posted: Monday 21 January 2019 10:48
by waaren
jantjegroen00 wrote: Monday 21 January 2019 9:18 The script is in the original post.
Sorry but I don't see anything in this script that reacts on "Stalamp Woonkamer" or switches this device.
The script start when "Knop" is pushed or released and switches a device "Koffie"