Page 1 of 1
short and long press button mqtt
Posted: 23 Oct 2017, 17:22
by jokketech
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
Re: short and long press button mqtt
Posted: 23 Oct 2017, 18:43
by grovkillen
Sorry, a typo on the wiki.
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
Re: short and long press button mqtt
Posted: 22 Nov 2017, 23:18
by kociubin
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
Re: short and long press button mqtt
Posted: 23 Nov 2017, 11:47
by toffel969
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 ?
Re: short and long press button mqtt
Posted: 23 Nov 2017, 16:23
by vader
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.
Re: short and long press button mqtt
Posted: 23 Nov 2017, 21:15
by grovkillen
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!
Re: short and long press button mqtt
Posted: 24 Nov 2017, 16:50
by kociubin
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.
Re: short and long press button mqtt
Posted: 24 Nov 2017, 17:12
by papperone
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!
Re: short and long press button mqtt
Posted: 24 Nov 2017, 17:49
by toffel969
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)