Page 1 of 1

If button pressed more than 7 seconds do something else

Posted: Tuesday 04 October 2016 23:17
by saffal
Hello! I want code the button for doorbell. If I pressed the button for more than 7 seconds the gate will open. And than i pressed the button less than 7 seconds doorbell was ring. Can you help me? :D BTW. Sorry for my english ;)

If button pressed more than 7 seconds do something else

Posted: Wednesday 05 October 2016 0:03
by mvzut
Hi Saffal, welcome to the forum!

This sounds easier than it is. Most (pulse) switches using wireless communication (either Z-wave, 433 MHz ,...) work with single events: if you press them they send a message. They don't send a message when you stop pressing them, at least not for Z-wave or the 433 MHz protocols that I'm aware of. So there's no way to determine how long you pressed them.

The only feasible options I see are:
-Connecting your doorbell switch directly to your Domoticz system (e.g. on a GPIO input assuming it's a Raspberry Pi). You can then create some kind of script that runs in the background, which constantly polls the status, and sends the required commands to Domoticz.
-Programming this functionality into an ESP-8266 (e.g. Nodemcu) connected to your doorbell switch, which then wirelessly sends the required commands to Domoticz via the JSON interface.

Anyhow, I think it's not going to be a plug-and-play solution, unless I'm missing some clever alternative solution myself.

Re: If button pressed more than 7 seconds do something else

Posted: Wednesday 05 October 2016 8:48
by Egregius
If the button is connected as extra input of a Qubino Dimmer, or a Fibaro binary sensor, or... It would stay on as long as the button is pressed.
But then, how to detect that the button is pressed for 2 seconds? Events are triggered upon start of something. Then you should retrieve the history of the switch after 7 seconds to determine if it was continuesly pushed.
Must be possible, but not easy to do.
Also, you want your gate opened like this?

Re: If button pressed more than 7 seconds do something else

Posted: Wednesday 05 October 2016 9:35
by booster
Egregius wrote:If the button is connected as extra input of a Qubino Dimmer, or a Fibaro binary sensor, or... It would stay on as long as the button is pressed.
But then, how to detect that the button is pressed for 2 seconds? Events are triggered upon start of something. Then you should retrieve the history of the switch after 7 seconds to determine if it was continuesly pushed.
Must be possible, but not easy to do.
Also, you want your gate opened like this?
That last part might work with a virtual switch:
if doorbell is pressed, switch on virtual switch on for 7 seconds
when virtual switch switches off, and doorbell is on, open your gate.
if doorbell is off, switch virtual switch off

(I know..it only checks of doorbell status is on after precisely 7 seconds, so pressing again exactly after 7 seconds could be considered unwanted;))

Re: If button pressed more than 7 seconds do something else

Posted: Wednesday 05 October 2016 16:03
by mvzut
booster wrote: That last part might work with a virtual switch:
if doorbell is pressed, switch on virtual switch on for 7 seconds
when virtual switch switches off, and doorbell is on, open your gate.
if doorbell is off, switch virtual switch off
Nice idea, although I believe that in the ['Virtual switch '] = "On FOR x" statement in Lua, x is measured in minutes. But I also remember that in ['Virtual switch '] = "Off AFTER x", the x is measured in seconds. So you could build it up from an "On" plus an "Off AFTER 7" command.