longpress action without first have the shortpress action

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
megamarco83
Normal user
Posts: 168
Joined: 13 Apr 2017, 23:09

longpress action without first have the shortpress action

#1 Post by megamarco83 » 16 Feb 2019, 00:44

Hi i have this configuration:
2 relay: relay_kitchen and relay_bathroom
2 wall switch: wall_kitchen and wall_batroom

every relay is triggered by it's wall switch shortpress.

the wall switch are setted as pushbutton active low
the longpress is setted as active only on low

the scope is that i want that if i longpress the kitchen wall switch the bathroom relay will turn on, but without triggering the relay of kitchen.

this is my rules:

Code: Select all

On System#Boot do    //When the ESP boots, do relay to OFF just to be sure
  gpio,13,1 //kitchen
  gpio,14,1 //bathroom
endon

on wall_kitchen_1#Switch do
	if [sniff#kitchen]=0 
	  Publish domoticz/in,{"command": "switchlight", "idx": 96, "switchcmd": "On" } // id of kitchenLight
	endif
	if [sniff#kitchen]=1
	  Publish domoticz/in,{"command": "switchlight", "idx": 96, "switchcmd": "Off" }
	endif
endon


on wall_kitchen_1#Switch=10 do // longpress ->bathroom
	if [sniff#bathroom]=0 
	  Publish domoticz/in,{"command": "switchlight", "idx": 97, "switchcmd": "On" } / id of BathroomLight
	endif
	if [sniff#bathroom]=1
	  Publish domoticz/in,{"command": "switchlight", "idx": 97, "switchcmd": "Off" }
	endif
endon


on sniff#kitchen=1 do gpio,13,0 
on sniff#kitchen=0 do gpio,13,1 
endon

on wall_bathroom_1#Switch do
	if [sniff#bathroom]=0 
	  Publish domoticz/in,{"command": "switchlight", "idx": 97, "switchcmd": "On" } // id of bathroomlight
	endif
	if [sniff#bathroom]=1 
	  Publish domoticz/in,{"command": "switchlight", "idx": 97, "switchcmd": "Off" }
	endif
endon

on sniff#bathroom=1 do gpio,14,0 
on sniff#bathroom=0 do gpio,14,1 
endon
if longpress bathroom relay turn on, but before relay kitchen is turned on and in a while off. How i can avoid that?
thanks

xury
Normal user
Posts: 44
Joined: 02 Apr 2018, 12:54

Re: longpress action without first have the shortpress action

#2 Post by xury » 16 Feb 2019, 02:42

You not using a timer to determine when is a short press and when is a long.
See at rules tutorial info:

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

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

Re: longpress action without first have the shortpress action

#3 Post by megamarco83 » 16 Feb 2019, 09:30

thanks, but it was an "old" way to perform the long press that you that you link
if i understand well now inside the new fw there are events for long and doubleclick:

https://espeasy.readthedocs.io/en/lates ... witch-page

Long press event: If enabled the unit will detect a long press of a button. There’s three different behaviors of the long press:

Active only on low: this means that the unit will only be triggering the long press event if the signal is low. Two different event values are used, 10 if the state goes from 0 to 1 (Switch#State=10), and 11 if the state goes from 1 to 0 (Switch#State=11).
Active only on high: same as above but only triggered on high signal.
Active on high & low: the long press will be triggered both on high and low signals

so how i can use the event in the new fw but triggering directly the longpress event without activating before the shortpress?
thanks

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

Re: longpress action without first have the shortpress action

#4 Post by megamarco83 » 18 Feb 2019, 09:40

any suggestion? :-)

tobias007
Normal user
Posts: 2
Joined: 16 Jun 2019, 13:31

Re: longpress action without first have the shortpress action

#5 Post by tobias007 » 16 Jun 2019, 13:34

Hi,

I have the same issue.

I tried all possible combinations to avoid a short press message before the long press activates. But it always triggers the short press first.

Any possibility to implement this?

Thanks a lot.

Kind regards. Tobias

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

Re: longpress action without first have the shortpress action

#6 Post by grovkillen » 16 Jun 2019, 13:49

Using rules you can filter out those short presses.
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:

tobias007
Normal user
Posts: 2
Joined: 16 Jun 2019, 13:31

Re: longpress action without first have the shortpress action

#7 Post by tobias007 » 16 Jun 2019, 16:21

Hi Grovkillen,

thanks for the quick reply. Could you provide any example?

Thanks in advance.

Tobias

anarro
Normal user
Posts: 14
Joined: 01 Aug 2016, 08:32

Re: longpress action without first have the shortpress action

#8 Post by anarro » 21 Jul 2019, 20:40

Hi,

Please, any example??

anarro
Normal user
Posts: 14
Joined: 01 Aug 2016, 08:32

Re: longpress action without first have the shortpress action

#9 Post by anarro » 27 Jul 2019, 13:23

Hi,

this is my final solution:

Code: Select all

on sw1#state do
 if [sw1#state]=3
  //double click triggered!
  publish /HA/esp_papa/sw1/state,1
  timerSet,1,0
 elseif [sw1#state]=10
  //Longclick triggered!
  publish /HA/esp_mama/sw1/state,1
  timerSet,1,0
 else
  //click triggered!
  timerSet,1,1
 endif
endon

on rules#timer=1 do
  publish /HA/esp_papas/sw1/state,1
endon

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

Re: longpress action without first have the shortpress action

#10 Post by grovkillen » 27 Jul 2019, 13:30

Perfect solution *thumbs up*
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:

rt1970
Normal user
Posts: 2
Joined: 21 Jan 2020, 00:17

Re: longpress action without first have the shortpress action

#11 Post by rt1970 » 13 Apr 2020, 20:13

It doesnt work. It will do nothing. I think the problem is: if [sw1#state]=3
I have this Code in my WEMOS D1 (one Switch and 3 LEDs: Click, Double Click and long Click)

Code: Select all

on Taster#State do
 if [Taster#State]=3
  //double click triggered!
  gpiotoggle,0
  timerSet,1,0
 elseif [Taster#State]=10
  //Longclick triggered!
  gpiotoggle,2
  timerSet,1,0
 else
  //click triggered!
  gpiotoggle,4
  timerSet,1,1
 endif
endon

on rules#timer=1 do
  publish /HA/esp_papas/sw1/state,1
endon
My Logging is:

Code: Select all

435704: SW : GPIO=5 State=0 Output value=0
435706: EVENT: Taster#State=0.00
435804: SW : GPIO=5 State=1 Output value=1
435806: EVENT: Taster#State=1.00
436104: SW : GPIO=5 State=0 Doubleclick=3
436109: EVENT: Taster#State=3.00
436704: SW : GPIO=5 State=1 Output value=1
436708: EVENT: Taster#State=1.00
441904: SW : GPIO=5 State=0 Output value=0
441906: EVENT: Taster#State=0.00
442904: SW : LongPress: GPIO= 5 State=0 Output value=10
442906: EVENT: Taster#State=10.00

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 21 guests