Page 1 of 1

Hold button detection script

Posted: Saturday 01 September 2018 21:07
by Antikillerbm
Hi everyone
I have aqara switch button (wireless) that can transmit only single presses. If I hold it pressed - the switch in domoticz also still turned on
But i need to detect this long presses for several seconds and, as bonus, detect also short presses if the button is released shortly.
I have tried to make it with the blockly, but it works slowly and unstable.
May it possible to do with dzvents/LUA?
Actually I haven't knowleges to make any script with dzvents.

Re: Hold button detection script

Posted: Monday 10 September 2018 21:13
by waaren
Antikillerbm wrote: Saturday 01 September 2018 21:07 I have aqara switch button (wireless) that can transmit only single presses. If I hold it pressed - the switch in domoticz also still turned on
But i need to detect this long presses for several seconds and, as bonus, detect also short presses if the button is released shortly.
Not fully tested because I do not own such a switch but with an emulated push button it seems to do the job. Please test and report your findings.
Thx

Code: Select all

return {
    on         = { devices     = { "Hold button"           }},

    logging    = { level       =   domoticz.LOG_DEBUG, 
                   marker      =   "Hold button detection"        },   

    data       = { lastState   = { initial = "Off"         }},

    execute = function(dz,triggerObject)
        if triggerObject.state == "On" then
            dz.log(triggerObject.name .. " switched On",dz.log_DEBUG)
        elseif triggerObject.state == "Off" and dz.data.lastState == "On" then
            dz.log( triggerObject.name .. " switched Off."  .. " It was switched on " .. 
                    triggerObject.lastUpdate.millisecondsAgo .. " milli-Seconds ago.",dz.log_DEBUG)
        end
        dz.data.lastState = triggerObject.state
    end
}

Re: Hold button detection script

Posted: Wednesday 26 December 2018 20:42
by Antikillerbm
Earlier, I did without this script but now Im realy need it.
Finally I tested it, but it worsk too slowly
When I pushing the button fast several times (with 200-500ms pause) script can get summary time of several clicks and decides that is one long click.
Also im tried to delete logging but it doesnt help.