I have one push button and try to run different external scripts depending on number of pushes within 2 seconds.
If I push once, only the script for single pressed should be executed. If I push twice, only the script for double pressed should be executed.
Unfortunately, I have no clue how realize that with DzVents.
Differentiate once or twice pressing a switch
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Differentiate once or twice pressing a switch
Assuming this is not a push-button capable of making the distinction between single or double push itself (like the Xiaomi push-button)saik wrote: ↑Sunday 11 November 2018 10:47 I have one push button and try to run different external scripts depending on number of pushes within 2 seconds.
If I push once, only the script for single pressed should be executed. If I push twice, only the script for double pressed should be executed.
Unfortunately, I have no clue how realize that with DzVents.
My personal preference would be to combine the two scripts into one script with an if / else block. But if they really have to stay separated, you need an activation script and two user variables, dummy switches or two different callbacks from an domoticz.openURL call. Implementation below is with two uservariables and a helper script.
Activation script
Code: Select all
--[[ -- doublePush
This script requires two domoticz uservariables (integer type) set to 0
]]--
local buttonName = "doublePush" -- Name of your trigger button
local singlePush = "scriptName1" -- Names of your uservariables (type integer and set to 0)
local doublePush = "scriptName2"
return {
on = { devices = { buttonName }},
logging = { level = domoticz.LOG_DEBUG ,
marker = "doublePush"},
data = { lastState = { initial = "" }},
execute = function(dz, item )
singlePush = dz.variables(singlePush)
doublePush = dz.variables(doublePush)
delaySeconds = 2
if item.state == "On" and dz.data.lastState == "On" and item.lastUpdate.secondsAgo <= delaySeconds then
singlePush.cancelQueuedCommands()
doublePush.set(1)
dz.data.lastState = ""
elseif item.state == "On" then
dz.data.lastState = "On"
singlePush.set(1).afterSec(delaySeconds + 2) -- Maybe + 1 also works but to stay at the safe side
else
dz.data.lastState = item.state
end
end
}
Code: Select all
-- doublePush_script1
local singlePush = "scriptName1" -- Names of your uservariables (type integer and set to 0)
return {
on = { variables = { singlePush }},
logging = { level = domoticz.LOG_DEBUG ,
marker = "doublePush_script1"},
execute = function(dz)
dz.log("Script 1 is executing",dz.LOG_DEBUG)
end
}
Code: Select all
-- doublePush_script2
local doublePush = "scriptName2" -- Names of your uservariables (type integer and set to 0)
return {
on = { variables = {doublePush }},
logging = { level = domoticz.LOG_DEBUG ,
marker = "doublePush_script2"},
execute = function(dz)
dz.log("Script 2 is executing",dz.LOG_DEBUG)
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest