long push, short push detection with a button (connected on gpio)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
DeNB3rt
Normal user
Posts: 120
Joined: 15 Dec 2015, 14:07

long push, short push detection with a button (connected on gpio)

#1 Post by DeNB3rt » 01 Feb 2017, 15:49

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? :)
Located in Belgium, Bruges. Working on a full DIY domoticz setup with ESPEasy.

Pmn
Normal user
Posts: 2
Joined: 01 Feb 2017, 20:45

Re: long push, short push detection with a button (connected on gpio)

#2 Post by Pmn » 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


papperone
Normal user
Posts: 497
Joined: 04 Oct 2016, 23:16

Re: long push, short push detection with a button (connected on gpio)

#3 Post by papperone » 02 Feb 2017, 07:57

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!
My TINDIE Store where you can find all ESP8266 boards I manufacture --> https://www.tindie.com/stores/GiovanniCas/
My Wiki Project page with self-made PCB/devices --> https://www.letscontrolit.com/wiki/inde ... :Papperone

DeNB3rt
Normal user
Posts: 120
Joined: 15 Dec 2015, 14:07

Re: long push, short push detection with a button (connected on gpio)

#4 Post by DeNB3rt » 02 Feb 2017, 13:35

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&paramm=switchlight&idx=174&switchcmd=On
keep up the good work thx! :)
Located in Belgium, Bruges. Working on a full DIY domoticz setup with ESPEasy.

Pmn
Normal user
Posts: 2
Joined: 01 Feb 2017, 20:45

Re: long push, short push detection with a button (connected on gpio)

#5 Post by Pmn » 02 Feb 2017, 15:44

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.

Mierke
Normal user
Posts: 1
Joined: 04 Feb 2017, 12:07

Re: long push, short push detection with a button (connected on gpio)

#6 Post by Mierke » 04 Feb 2017, 12:14

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

ashfaaaa
Normal user
Posts: 4
Joined: 09 Feb 2017, 07:49

Re: long push, short push detection with a button (connected on gpio)

#7 Post by ashfaaaa » 09 Apr 2017, 07:47

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

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: long push, short push detection with a button (connected on gpio)

#8 Post by paxi » 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.

andrea
Normal user
Posts: 1
Joined: 26 May 2017, 10:22

Re: long push, short push detection with a button (connected on gpio)

#9 Post by andrea » 26 May 2017, 11:36

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!

car_killer
Normal user
Posts: 1
Joined: 28 Dec 2017, 16:13

Re: long push, short push detection with a button (connected on gpio)

#10 Post by car_killer » 28 Dec 2017, 16:19

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

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: long push, short push detection with a button (connected on gpio)

#11 Post by vader » 01 Jan 2018, 10:53

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


Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests