Page 1 of 1
long push, short push detection with a button (connected on gpio)
Posted: 01 Feb 2017, 15:49
by DeNB3rt
Hi ESPEasy guy's
A question, did anybody try to distinguish the difference between a long and short push on a button, connected to a gpio on the ESP?
This could be interesting to build one normal on/off switch at the entrance of your house.
When
short push on the button > normal on/off lighting in the entrance.
Long push is to disable all lights in your house when leaving.
Anybody?
Re: long push, short push detection with a button (connected on gpio)
Posted: 01 Feb 2017, 20:57
by Pmn
Hi,
Yes, I got that working by using the rules section.
Let the button start a timer-rule. (where you can specify your long-push time)
Code: Select all
On Switch#Switch1=1.00 do
timerSet,1,2 (where 2 is the long push time in seconds)
endon
On Rules#Timer=1 do
if [Switch#Switch1]=1.00
gpio,15,1
else
gpio,16,1
endif
endon
Re: long push, short push detection with a button (connected on gpio)
Posted: 02 Feb 2017, 07:57
by papperone
It can work but it's not really a long press, if you press, release, and then press it again within 2 seconds it will trigger the "long press" and it shoudln't...
I think you shoudl reset the timer if the switch is released in order to make it work properly!
Re: long push, short push detection with a button (connected on gpio)
Posted: 02 Feb 2017, 13:35
by DeNB3rt
ok, cool, so this is possible. thanks!
Did not have a look yet to the 'rules'.
I think I could add a 'turn off all lights' virtual button in domoticz,
and add a SendToHTTP in the rules? right?
e.g.
Code: Select all
SendToHTTP 192.168.0.243,8080,/json.htm?type=command¶mm=switchlight&idx=174&switchcmd=On
keep up the good work thx!
Re: long push, short push detection with a button (connected on gpio)
Posted: 02 Feb 2017, 15:44
by Pmn
papperone wrote:It can work but it's not really a long press, if you press, release, and then press it again within 2 seconds it will trigger the "long press" and it shoudln't...
I think you shoudl reset the timer if the switch is released in order to make it work properly!
You're right. Thanks for the addition.
Re: long push, short push detection with a button (connected on gpio)
Posted: 04 Feb 2017, 12:14
by Mierke
Hi, i'm using this rules to control 4 lights with 2 pushbuttons.
on s2#S do
TaskValueSet 9,1,[tv#tv]+1
TaskValueSet 9,2,[salon#salon]+1
timerSet,1,1
timerSet,2,2
endon
on s1#S do
TaskValueSet 9,3,[keuken#keuken]+1
TaskValueSet 9,4,[eetplaats#eetplaats]+1
timerSet,3,1
timerSet,4,2
endon
on sw2#S=1 do
TaskValueSet 9,1,[Dummy#switch1]-1
if [salon#salon] > 0
gpio,14,0
pwm,14,0
else
gpio,14,1
endif
endon
on sw1#S=1 do
TaskValueSet 9,3,[Dummy#switch3]-1
if [eetplaats#eetplaats] > 0
gpio,2,0
pwm,2,0
else
gpio,2,1
endif
endon
On Rules#Timer=2 do
TaskValueSet 9,1,0
TaskValueSet 9,2,0
endon
On Rules#Timer=4 do
TaskValueSet 9,3,0
TaskValueSet 9,4,0
endon
On Rules#Timer=1 do
if [Dummy#switch1] = 1
gpio,13,1
else
gpio,13,0
pwm,13,0
endif
endon
On Rules#Timer=3 do
if [Dummy#switch3] = 1
gpio,0,1
else
gpio,0,0
pwm,0,0
endif
endon
<> Task Device Name Port IDX/Variable GPIO Values
Edit 1 Temperature - DS18b20 Garage 28-b1-a6-3b-5-0-0-68 65 GPIO-16 Temperature garage:24.63
Edit 2 Switch input keuken GPIO-0 keuken: 0
Edit 3 Switch input eetplaats GPIO-2 eetplaats: 0
Edit 4 Switch input tv GPIO-13 tv: 0
Edit 5 Switch input salon GPIO-14 salon: 0
Edit 6 Switch input s1 GPIO-12 S: 1
Edit 7 Switch input s2 GPIO-15 S: 1
Edit 8
Edit 9 Dummy Device Dummy switch1:0.00
switch2:0.00
switch3:0.00
switch4:0.00
Edit 10 Switch input sw1 GPIO-12 S: 0
Edit 11 Switch input sw2 GPIO-15 S: 0
Edit 12
Re: long push, short push detection with a button (connected on gpio)
Posted: 09 Apr 2017, 07:47
by ashfaaaa
hello, i'm making a switchboard with 4 channel mains relay module with 4 buttons. I want when one of the buttons long pressed to turn ON/OFF all 4 relays. anyway I can do this?... I'm kind of new to espeasy so far I managed to get this rules to work 4 channel relay to on/off how can I use one this button to control all channel?
rules
Code: Select all
on button1#button1 do
if [relay1#relay1] =0
GPIO,16,1
else
GPIO,16,0
endif
endon
on button2#button2 do
if [relay2#relay2] =0
GPIO,14,1
else
GPIO,14,0
endif
endon
on button3#button3 do
if [relay3#relay3] =0
GPIO,13,1
else
GPIO,13,0
endif
endon
on button4#button4 do
if [relay4#relay4] =0
GPIO,2,1
else
GPIO,2,0
endif
endon
Someone, Please Help me
thank you
Re: long push, short push detection with a button (connected on gpio)
Posted: 09 Apr 2017, 21:18
by paxi
Here is a snippet of working "production" code as example:
Code: Select all
on Button#Button do
if [Button#Button]=1
TimerSet 3,5
TaskValueSet 2,4,1
PWM 13,0
else
TimerSet 3,0
TaskValueSet 2,4,0
endif
endon
on Rules#Timer=3 do
if [State#Reboot]=1
Reboot
endif
endon
Button# is configured as normal switch (important!), TaskValueSet stores to dummy device/value State#Reboot.
I use the same gpio in another switch device (configured as pushbutton) for the "normal" switching.
Re: long push, short push detection with a button (connected on gpio)
Posted: 26 May 2017, 11:36
by andrea
paxi wrote: ↑09 Apr 2017, 21:18
Here is a snippet of working "production" code as example:
Code: Select all
on Button#Button do
if [Button#Button]=1
TimerSet 3,5
TaskValueSet 2,4,1
PWM 13,0
else
TimerSet 3,0
TaskValueSet 2,4,0
endif
endon
on Rules#Timer=3 do
if [State#Reboot]=1
Reboot
endif
endon
Button# is configured as normal switch (important!), TaskValueSet stores to dummy device/value State#Reboot.
I use the same gpio in another switch device (configured as pushbutton) for the "normal" switching.
Hi, can you explain how you set the "normal" switch for the short push? What rule do you use?
if I create a new switch with the same gpio the short push rule is activated after the long push too.
thanks!
Re: long push, short push detection with a button (connected on gpio)
Posted: 28 Dec 2017, 16:19
by car_killer
HI
i wondering how to use this long and short press option on my esp 8266 and easyesp
i have two relays and diffent GPIo's
and one buttom
i like to maka as following
on short press i like to change the state of relay 1 - if is OFF i like change to ON and opposit
on long press i like to change the state of relay 2 - if is OFF i like change to ON and opposit
the best willbe option tongle - but this option is missing on esp
finally wilbe two bottoms in differnt places to make the change on relays - but this wilbe next step..
regards
Re: long push, short push detection with a button (connected on gpio)
Posted: 01 Jan 2018, 10:53
by vader
Use my rule in the wiki and you can press the button as long as you want....
Pmn wrote: ↑01 Feb 2017, 20:57
Hi,
Yes, I got that working by using the rules section.
Let the button start a timer-rule. (where you can specify your long-push time)
Code: Select all
On Switch#Switch1=1.00 do
timerSet,1,2 (where 2 is the long push time in seconds)
endon
On Rules#Timer=1 do
if [Switch#Switch1]=1.00
gpio,15,1
else
gpio,16,1
endif
endon