Rules Example for new feature doubleklick and longpress

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Cino2424
Normal user
Posts: 17
Joined: 30 Sep 2018, 16:35

Rules Example for new feature doubleklick and longpress

#1 Post by Cino2424 » 04 Dec 2018, 19:03

Hello

I see the new longpress and doublecklick option for switches. I have a Sonoff Touch and 3 Lamps with espeasy in my livingroom.

In my bedroom I also have to Sonoff Touch. One is directly conntected to the lamp and with the other Sonoff Touch I controll the lamp too over rules.

Code: Select all

on touch#switch do
  if [touch#switch]=1
   gpio,12,1
sendToHTTP 192.168.0.61,80,/control?cmd=GPIO,12,1 
 SendToHTTP 192.168.0.51,8080,/json.htm?type=param=switchlight&command&idx=118&switchcmd=On
else
   gpio,12,0
sendToHTTP 192.168.0.61,80,/control?cmd=GPIO,12,0  
SendToHTTP 192.168.0.51,8080,/json.htm?type=param=switchlight&command&idx=118&switchcmd=Off

  endif
 endon 
So, how can I use the new longpress and doubleklick in rules to switch on 3 different lights.

Like shortklick Lamp 1 doubleklick lamp 2 longpress lamp 3.


Thank you very much for answer

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

Re: Rules Example for new feature doubleklick and longpress

#2 Post by grovkillen » 04 Dec 2018, 20:07

Code: Select all

on touch#switch=3 do
 //Double click
EndOn
on touch#switch=11 do
 //Long press from state 0-->1
endon
on touch#switch=10 do
 //Long press from state 1-->0
endon
[code]
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:

megamarco83
Normal user
Posts: 230
Joined: 13 Apr 2017, 23:09

Re: Rules Example for new feature doubleklick and longpress

#3 Post by megamarco83 » 05 Dec 2018, 00:31

thanks so much for explanation!!!
there is a documentation that explain this function ?
where we can be aware about that usage? :D
thanks

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

Re: Rules Example for new feature doubleklick and longpress

#4 Post by grovkillen » 05 Dec 2018, 06:57

megamarco83 wrote: 05 Dec 2018, 00:31 thanks so much for explanation!!!
there is a documentation that explain this function ?
where we can be aware about that usage? :D
thanks
I'm currently converting all documentation from wiki to RTD (read the docs) which will allow for versioning and easier maintenance of documentation. This is already online but not yet fully converted.
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:

megamarco83
Normal user
Posts: 230
Joined: 13 Apr 2017, 23:09

Re: Rules Example for new feature doubleklick and longpress

#5 Post by megamarco83 » 05 Dec 2018, 07:36

Thanls for explaining
I see that clicking inside the switch task on '?' button but i dot see in the read the doc web page the usage of new function long and short press, i'm wrong?
is it this one:
https://espeasy.readthedocs.io/en/lates ... witch-page
?

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

Re: Rules Example for new feature doubleklick and longpress

#6 Post by grovkillen » 05 Dec 2018, 09:02

No it's not yet published... it's on a PR on GitHub. I only added it two days ago :)
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:

Cino2424
Normal user
Posts: 17
Joined: 30 Sep 2018, 16:35

Re: Rules Example for new feature doubleklick and longpress

#7 Post by Cino2424 » 06 Dec 2018, 09:21

It doesnt worked for me. But I think thats a Problem of my Sonoff touch. It is a Push button active high.

fraeggle
Normal user
Posts: 21
Joined: 20 Nov 2017, 20:12

Re: Rules Example for new feature doubleklick and longpress

#8 Post by fraeggle » 17 Dec 2018, 08:45

Hi
i do have the same issue as Cino2424. Looking at mqtt at the same time i can see that first a 1 and then (if i am Lucky) a 3 is send on doubleclick. I think ther should be a function, if i use this features, sending of the "new" state must be delayed. Otherwise i get a "normal" toggle AND a doubleclick, or a normal and a longpress state...........
so in this case always two events are send...

Regards Peter

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

Re: Rules Example for new feature doubleklick and longpress

#9 Post by grovkillen » 17 Dec 2018, 13:22

Activated the slow button checkbox?
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:

fraeggle
Normal user
Posts: 21
Joined: 20 Nov 2017, 20:12

Re: Rules Example for new feature doubleklick and longpress

#10 Post by fraeggle » 17 Dec 2018, 19:51

Hi.
With slow Button activated doesnt make any difference.

Following Rules for testing activ:

on io4#io4=1 do
if [io14#io14]=0
GPIO,14,1
else
GPIO,14,0
endon

on IO4#io4=3 do
if [io12#io12]=0
GPIO,12,1
else
GPIO,12,0
endon

on IO4#io4=11 do
if [io13#io13]=0
GPIO,13,1
else
GPIO,13,0
endon

-----> short press io4 toggles io14
-----> long press io4 toggles io14 AND io 13
-----> double press io4 something interesting: toggles io12 AND io14 BUT io14 only toggled once, not as expected twice (ex. first press io14 on, second press io14 off)

in all Cases status in MQTT:
-----> short press io4 ---- Status in Broker short 1 when released 0
-----> long press io4 ---- Status in Broker 1 then 11 when released 0
-----> double press io4 ----- Status in Broker 1-0-3-0
it would be nice if only the "end" Status 1,3,11,10 would be shortly send, because 0 AFTER "Button Action" is ok and correct. (don't know if explained in the right words... English is not my mother language ;-) ).

JCFoxy
New user
Posts: 1
Joined: 19 Apr 2019, 08:09

Re: Rules Example for new feature doubleklick and longpress

#11 Post by JCFoxy » 19 Apr 2019, 08:14

Hi Forum,

I found the same problem, that espeasy sends 1 or 0 in addition to the doubleclick 3 and longpress 10 or 11.

Are there any news about how to solve it?

Thanks for the great Job you did with espeasy!

Foxy

megamarco83
Normal user
Posts: 230
Joined: 13 Apr 2017, 23:09

Re: Rules Example for new feature doubleklick and longpress

#12 Post by megamarco83 » 19 Apr 2019, 09:21

yes also with my rules same issue. if i want to have a longpress (state=10) esp activate first a shortpress and then a longress.

this is not good because if i want to trigger longpress (longpress) esp active before shorpress and then longpress

Code: Select all

on B_DOWN#state=0 do 
  Publish domoticz/in,{"command":"setuservariable","idx":7,"value":"SHORTPRESS"}
endon

on B_DOWN#state=10 do 
  Publish domoticz/in,{"command":"setuservariable","idx":7,"value":"LONGPRESS"}
endon

tpuhe
New user
Posts: 4
Joined: 28 Oct 2019, 11:15

Re: Rules Example for new feature doubleklick and longpress

#13 Post by tpuhe » 29 Oct 2019, 15:16


Jethro
New user
Posts: 1
Joined: 16 May 2020, 13:26

Re: Rules Example for new feature doubleklick and longpress

#14 Post by Jethro » 16 May 2020, 13:30

Hi All,

I've had the same issue - I'd like three separate MQTT events for single, double and long - however the standard behaviour will, as described above, will always immediately send the =1 event on initial stage change, with the double=3/long=11 (in my case) events.

I have a solution that has worked for me - using a rule and timer. Essentially, I've disabled the switch directly being sent to the controller and handled this with the rule. The 'single' event isn't sent until 1 second has passed to be sure it's not actually a double or long event (in which case the time is stopped).

It may not work for all your use cases, but for for controlling 3 lights etc it should work fine for (though you'll need to manage the toggling of state elsewhere - this solution just splits the three events).

Rules:

Code: Select all

on Switch1#switch1=1 do
 timerSet,1,1
EndOn

On Rules#Timer=1 do
 Publish sometopic/switch1,single
 timerSet,1,0
endon

on Switch1#switch1=3 do
 Publish sometopic/switch1,double
 timerSet,1,0
EndOn

on Switch1#switch1=11 do
 Publish sometopic/switch1,long
 timerSet,1,0
endon
Obviously you'll need to amend based on your switch names/values, MQTT topics and if you're using other timers. If you don't want MQTT I'm sure other actions/rules could be worked into this.

Hope this is helpful for someone!

megamarco83
Normal user
Posts: 230
Joined: 13 Apr 2017, 23:09

Re: Rules Example for new feature doubleklick and longpress

#15 Post by megamarco83 » 16 May 2020, 19:25

Jethro wrote: 16 May 2020, 13:30
Obviously you'll need to amend based on your switch names/values, MQTT topics and if you're using other timers. If you don't want MQTT I'm sure other actions/rules could be worked into this.

Hope this is helpful for someone!
hi, thanks for sharing, i tested using monitor to save tasks on devices webpage, but it now works :(

Code: Select all

on System#Boot do
monitor,pcf,73 
monitor,pcf,74
monitor,pcf,76
monitor,pcf,77
monitor,pcf,78
endon

on pcf#74=0 do
timerSet,1,1

endon

On Rules#Timer=1 do
//single press
   Publish cmnd/tasmota_156/power2,'2' // tasmota toggle  pcf0 relay2
 timerSet,1,0
endon

on pcf#74=3 do
 //double press
   Publish cmnd/tasmota_156/power3,'2' // tasmota toggle  pcf0 relay3
 timerSet,1,0
EndOn

on pcf#74=11 do
 //long press
   Publish cmnd/tasmota_156/power4,'2' // tasmota toggle  pcf0 relay4
 timerSet,1,0
EndOn
but it not work :(

attached the log
can someone help?
thanks


single press:
1291085: EVENT: PCF#74=0
1291128: ACT : timerSet,1,1
1291129: Command: timerSet
1291484: EVENT: PCF#74=1
1292368: WD : Uptime 22 ConnectFailures 0 FreeMem 18720 WiFiStatus 3
1292812: EVENT: Rules#Timer=1
1292845: ACT : Publish cmnd/tasmota_156/power2,'2'
1292847: Command: Publish
1292882: ACT : timerSet,1,0
1292883: Command: timerSet


doublepress:
1330284: EVENT: PCF#74=0
1330311: ACT : timerSet,1,1
1330312: Command: timerSet
1330684: EVENT: PCF#74=1
1330984: EVENT: PCF#74=0
1331009: ACT : timerSet,1,1
1331010: Command: timerSet
1331284: EVENT: PCF#74=1
1332812: EVENT: Rules#Timer=1
1332841: ACT : Publish cmnd/tasmota_156/power2,'2'
1332842: Command: Publish
1332878: ACT : timerSet,1,0
1332879: Command: timerSet


longpress:
1352367: WD : Uptime 23 ConnectFailures 0 FreeMem 16048 WiFiStatus 3
1353940: EVENT: PCF#74=0
1353990: ACT : timerSet,1,1
1353990: Command: timerSet
1355812: EVENT: Rules#Timer=1
1355840: ACT : Publish cmnd/tasmota_156/power2,'2'
1355842: Command: Publish
1355880: ACT : timerSet,1,0
1355881: Command: timerSet
1359540: EVENT: PCF#74=1

BuddhaZen
Normal user
Posts: 13
Joined: 07 Apr 2018, 14:23

Re: Rules Example for new feature doubleklick and longpress

#16 Post by BuddhaZen » 24 Aug 2022, 18:21

Interesting .... It's already the middle of 2022, but the problem with the button is still there :D

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests