short and long press button mqtt

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
jokketech
New user
Posts: 1
Joined: 23 Oct 2017, 17:13

short and long press button mqtt

#1 Post by jokketech » 23 Oct 2017, 17:22

Code: Select all

on button1#state=1 do
timerset 1,1
endon

on rules#timer=1 do
 if [button1#state]=0
  Publish /esp01/button1/state,short
 else
  Publish /esp01/button1/state,long
 endif
endon
button is a pushbutton on gpio14, normal switch, internal pullup.

Its not working :-( cant see the messages on mqtt. Anyone got an idea of what is wrong?

Thx

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: short and long press button mqtt

#2 Post by grovkillen » 23 Oct 2017, 18:43

Sorry, a typo on the wiki.

Code: Select all

timerSet,1,1
Correct code:

Code: Select all

on Button#State=1 do
  timerSet,1,1
endon

on rules#timer=1 do
 if [Button#State]=0
  //Action if button is short pressed
 else
  //Action if button is still pressed
 endif
endon
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

kociubin
Normal user
Posts: 11
Joined: 09 Nov 2017, 02:48

Re: short and long press button mqtt

#3 Post by kociubin » 22 Nov 2017, 23:18

I was hoping to do something like the code below instead (wanted to avoid having to wait 1 second for the first action to fire), but it doesn't work. Action1 is never triggered. Any idea how to work around this?

Code: Select all

on Button#State=1 do
 delay,300
 if [Button#State]=0
  //Action1 if button is short pressed
 else
  //Action2 if button is still pressed
 endif
endon

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: short and long press button mqtt

#4 Post by toffel969 » 23 Nov 2017, 11:47

kociubin wrote: 22 Nov 2017, 23:18 I was hoping to do something like the code below instead (wanted to avoid having to wait 1 second for the first action to fire), but it doesn't work. Action1 is never triggered. Any idea how to work around this?

Code: Select all

on Button#State=1 do
 delay,300
 if [Button#State]=0
  //Action1 if button is short pressed
 else
  //Action2 if button is still pressed
 endif
endon
What is the message delay setting under advanced tab ?
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

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

Re: short and long press button mqtt

#5 Post by vader » 23 Nov 2017, 16:23

kociubin wrote: 22 Nov 2017, 23:18 I was hoping to do something like the code below instead (wanted to avoid having to wait 1 second for the first action to fire), but it doesn't work. Action1 is never triggered. Any idea how to work around this?

Code: Select all

on Button#State=1 do
[b][color=#FF0000] delay,300[/color][/b]
 if [Button#State]=0
  //Action1 if button is short pressed
 else
  //Action2 if button is still pressed
 endif
endon
This rule example in the wiki is from me and works like a charm. You don't have to wait 1 sec for an action. Switch delay is normally 0 and remove your delay of 300!

@grovkillen: It should make no difference if you type 'timerSet,1,1' or 'timerSet 1 1'. Check out 'GPIO,12,1' and 'GPIO 12 1'. Both set GPIO 12 to 1! The parser interprets 'space' and 'comma' as a separator.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: short and long press button mqtt

#6 Post by grovkillen » 23 Nov 2017, 21:15

vader wrote: 23 Nov 2017, 16:23
kociubin wrote: 22 Nov 2017, 23:18 I was hoping to do something like the code below instead (wanted to avoid having to wait 1 second for the first action to fire), but it doesn't work. Action1 is never triggered. Any idea how to work around this?

Code: Select all

on Button#State=1 do
[b][color=#FF0000] delay,300[/color][/b]
 if [Button#State]=0
  //Action1 if button is short pressed
 else
  //Action2 if button is still pressed
 endif
endon
This rule example in the wiki is from me and works like a charm. You don't have to wait 1 sec for an action. Switch delay is normally 0 and remove your delay of 300!

@grovkillen: It should make no difference if you type 'timerSet,1,1' or 'timerSet 1 1'. Check out 'GPIO,12,1' and 'GPIO 12 1'. Both set GPIO 12 to 1! The parser interprets 'space' and 'comma' as a separator.
Thanks for pointing that out! 8-)
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

kociubin
Normal user
Posts: 11
Joined: 09 Nov 2017, 02:48

Re: short and long press button mqtt

#7 Post by kociubin » 24 Nov 2017, 16:50

vader wrote: 23 Nov 2017, 16:23
This rule example in the wiki is from me and works like a charm. You don't have to wait 1 sec for an action. Switch delay is normally 0 and remove your delay of 300!

@grovkillen: It should make no difference if you type 'timerSet,1,1' or 'timerSet 1 1'. Check out 'GPIO,12,1' and 'GPIO 12 1'. Both set GPIO 12 to 1! The parser interprets 'space' and 'comma' as a separator.

I appreciate the response but my experience conflicts with your statement. I implemented your rule with a timerSet but I measure about 1 second minimum delay (which is not acceptable given my use case). This makes sense because "timerSet 1,1" creates a timer that fires in 1 second.

If you have any ideas on how to reduce the delay to around 200ms that would be great. BTW, I tried "timerSet,1,0.2" but that doesn't work.

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

Re: short and long press button mqtt

#8 Post by papperone » 24 Nov 2017, 17:12

kociubin wrote: 24 Nov 2017, 16:50
vader wrote: 23 Nov 2017, 16:23
This rule example in the wiki is from me and works like a charm. You don't have to wait 1 sec for an action. Switch delay is normally 0 and remove your delay of 300!

@grovkillen: It should make no difference if you type 'timerSet,1,1' or 'timerSet 1 1'. Check out 'GPIO,12,1' and 'GPIO 12 1'. Both set GPIO 12 to 1! The parser interprets 'space' and 'comma' as a separator.

I appreciate the response but my experience conflicts with your statement. I implemented your rule with a timerSet but I measure about 1 second minimum delay (which is not acceptable given my use case). This makes sense because "timerSet 1,1" creates a timer that fires in 1 second.

If you have any ideas on how to reduce the delay to around 200ms that would be great. BTW, I tried "timerSet,1,0.2" but that doesn't work.
As grovkillen already pointed out please lower the "Message Delay" value in the advanced tab, by default is 1000ms (1 sec.) but I normally use 100ms (0.1sec) and it works like a charm!
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

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: short and long press button mqtt

#9 Post by toffel969 » 24 Nov 2017, 17:49

To make it clear we are talking about 3 different delays here.:
1 delay in rules
2 delay of devices
3 general message delay (advanced tab)
The TO Needs to remove 1 from rules. 2 of the switch must be 0. 3 is advised to 100msec( I can confirm papperones positive experience)
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

Post Reply

Who is online

Users browsing this forum: No registered users and 81 guests