Rules same GPIO and Longpress event

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
ohaldi
Normal user
Posts: 61
Joined: 31 Jan 2020, 09:10
Location: Switzerland

Rules same GPIO and Longpress event

#1 Post by ohaldi » 29 Aug 2020, 20:40

Hello,

I'm Using on ESP_01 with a PIR on GPIO 2 and a Relay on GPIO 0.
In parallel on the pir, I have a push button.
By the action of the PIR or the push button the relay is activated for 5 seconds (this work).
By pressing the push button for more than 4 sec. I would like to switch on the relay with a delay of 25 seconds.
LongPress detection: GPIO= 2 State=1 Output value=11 is OK.
But the elseif [ESP_01-PIR#STATE]=11.00 is not executed !
I tested also with =11 but it's dosent work too.
Below ma Rule.
Many thanks in advance for your help
Otto

Rules set 1:
on System#Boot do
LongPulse,0,1,5
endon

on ESP_01-PIR#STATE do
if [ESP_01-PIR#STATE]=1 // PIR ou Button
LongPulse,0,0,5 // Relay ON 5s
elseif [ESP_01-PIR#STATE]=11.00 // Button pressé sur plus de 4 sec.
LongPulse,0,0,25 // Relay ON 25s
endif
endon

Log
966879: SW : GPIO=2 State=1 Output value=1
966882: EVENT: ESP_01-PIR#STATE=1.00
966893: ACT : LongPulse,0,0,5
966894: Command: LongPulse
966897: SW : GPIO 0 Pulse set for 5 sec
970879: SW : LongPress: GPIO= 2 State=1 Output value=11
970882: EVENT: ESP_01-PIR#STATE=11.00
970893: ACT : LongPulse,0,0,5
970894: Command: LongPulse
970897: SW : GPIO 0 Pulse set for 5 sec
972080: SW : GPIO=2 State=0 Output value=0
972082: EVENT: ESP_01-PIR#STATE=0.00
Attachments
LongpressEvent.jpg
LongpressEvent.jpg (39.54 KiB) Viewed 7849 times

User avatar
Ath
Normal user
Posts: 3519
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules same GPIO and Longpress event

#2 Post by Ath » 29 Aug 2020, 21:30

What version of ESPEasy do you have installed?
The latest is always available from https://github.com/letscontrolit/ESPEasy/releases
/Ton (PayPal.me)

User avatar
ThomasB
Normal user
Posts: 1065
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Rules same GPIO and Longpress event

#3 Post by ThomasB » 30 Aug 2020, 05:29

Try this rule set (untested):

Code: Select all

on System#Boot do
  LongPulse,0,1,5
endon

if ESP_01-PIR#STATE=11 do // This was a 4 Sec Long press. Extend relay time.
  LongPulse,0,0,21 // 4 Secs has already elapsed, add another 21 secs.
endon

on ESP_01-PIR#STATE=1 do // Button is pressed.
  LongPulse,0,0,5
endon
- Thomas

User avatar
ohaldi
Normal user
Posts: 61
Joined: 31 Jan 2020, 09:10
Location: Switzerland

Re: Rules same GPIO and Longpress event

#4 Post by ohaldi » 30 Aug 2020, 12:38

Hello Thomas,
Many thanks for your help, but do not work.
Line 6: LongPulse,0,0,21 is not executed!
Regards
Otto

59189822: SW : GPIO=2 State=1 Output value=1
59189825: EVENT: ESP_01-PIR#STATE=1.00
59189836: ACT : LongPulse,0,0,5
59189838: Command: LongPulse
59189840: SW : GPIO 0 Pulse set for 5 sec
59192272: WD : Uptime 987 ConnectFailures 0 FreeMem 21384 WiFiStatus 3
59193822: SW : LongPress: GPIO= 2 State=1 Output value=11
59193825: EVENT: ESP_01-PIR#STATE=11.00
59195622: SW : GPIO=2 State=0 Output value=0
59195625: EVENT: ESP_01-PIR#STATE=0.00

User avatar
ohaldi
Normal user
Posts: 61
Joined: 31 Jan 2020, 09:10
Location: Switzerland

Re: Rules same GPIO and Longpress event

#5 Post by ohaldi » 30 Aug 2020, 12:41

I'm using the following version : ESP_Easy_mega-20200426_normal_ESP8266_1M.bin

TD-er
Core team member
Posts: 8755
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules same GPIO and Longpress event

#6 Post by TD-er » 30 Aug 2020, 12:41

Just to be sure it isn't causing any issues, can you change the task name to not include a minus sign?

User avatar
Ath
Normal user
Posts: 3519
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules same GPIO and Longpress event

#7 Post by Ath » 30 Aug 2020, 13:27

I think the if should be on:

Code: Select all

on ESP_01-PIR#STATE=11 do // This was a 4 Sec Long press. Extend relay time.
  LongPulse,0,0,21 // 4 Secs has already elapsed, add another 21 secs.
endon
And removing the minus from the name, as TD-er suggested, will also help (should be added as 'unsupported' to the name-check, IMHO).
/Ton (PayPal.me)

User avatar
ohaldi
Normal user
Posts: 61
Joined: 31 Jan 2020, 09:10
Location: Switzerland

Re: Rules same GPIO and Longpress event

#8 Post by ohaldi » 30 Aug 2020, 20:42

I removed the minus and use the sample from Ath, now every thing work very well.
Thanks
Otto

User avatar
ThomasB
Normal user
Posts: 1065
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Rules same GPIO and Longpress event

#9 Post by ThomasB » 30 Aug 2020, 22:51

I think the if should be on:
Oops. Thanks for catching my typo ("if" should be "on").

- Thomas

User avatar
ohaldi
Normal user
Posts: 61
Joined: 31 Jan 2020, 09:10
Location: Switzerland

Re: Rules same GPIO and Longpress event

#10 Post by ohaldi » 31 Aug 2020, 07:42

Hello Thomas,
Yes the if must be "on".
Now I have to complete my script. When I press 4 seconds, it puts a delay of 25 sec.
But if someone moves the PIR it puts the delay back to 5 sec.
Regards
Otto

User avatar
Ath
Normal user
Posts: 3519
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules same GPIO and Longpress event

#11 Post by Ath » 31 Aug 2020, 07:50

ohaldi wrote: 31 Aug 2020, 07:42 But if someone moves the PIR it puts the delay back to 5 sec.
You can solve that by raising a flag during the extended time:

Code: Select all

on System#Boot do
  LongPulse,0,1,5
  Let 1,0  // Reset flag
endon

on ESP_01PIR#STATE=11 do // This was a 4 Sec Long press. Extend relay time.
  Let 1,1  // Raise flag
  TimerSet 1,21
  LongPulse,0,0,21 // 4 Secs has already elapsed, add another 21 secs.
endon

on ESP_01PIR#STATE=1 do // Button is pressed.
  if %v1%=0  // Only if flag not raised
    LongPulse,0,0,5
  endif
endon

on Rules#Timer=1 do
  Let 1,0  // Reset flag
endon
/Ton (PayPal.me)

User avatar
ohaldi
Normal user
Posts: 61
Joined: 31 Jan 2020, 09:10
Location: Switzerland

Re: Rules same GPIO and Longpress event

#12 Post by ohaldi » 03 Sep 2020, 21:35

Work well.
Many thanks for your help
Otto

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 110 guests