"push button active high" swith to 0 with Rules

Moderators: grovkillen, Stuntteam, TD-er

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

"push button active high" swith to 0 with Rules

#1 Post by ohaldi » 14 Dec 2022, 18:39

Hello,
I have a switch of type "push button active high" named "DELAY" on the GPIO-14.
When I press this button, I change a "state" value from 0 to 1 or vice versa.
How can I also set this "state" value to 0 using a ruler?
I tried with:
1. DELAY#State=0
2. GPIO,14,0
but both don't work

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: "push button active high" swith to 0 with Rules

#2 Post by chromo23 » 14 Dec 2022, 18:47

I am not sure what you want to archive but your code should be wrapped in a rules block "ON...DO...Endon"

Code: Select all

On Delay#State=0 Do
  GPIO,14,0
Endon

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

Re: "push button active high" swith to 0 with Rules

#3 Post by TD-er » 14 Dec 2022, 21:02

You may try to check the checkbox on the tools->Advanced page to allow TaskValueSet on tasks other than "dummy" and then call from the rules:

Code: Select all

taskvalueset,X,1,0
Where X is the task index of your switch task. (task nr as shown on the "devices" tab, left column)

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

Re: "push button active high" swith to 0 with Rules

#4 Post by ohaldi » 18 Dec 2022, 13:57

Many thanks for you help.

I checked the following box:
AllowTaskValueSet on all Plugins:

At the end of my rule I have now added the line :

Code: Select all

...
On DOOR#State=1 do // Door closed
  lcdcmd,clear
  LCD,2,1,"Die Tor ist zu"
  TimerSet,1,0 // Stop Loops
  TimerSet,2,0 // Stop Repeat
  taskvalueset,6,1,0
Endon
With this command "taskvalueset,6,1,0" it works fine. The DOOR#State value on the device tab Task number 6 changes from 1 to zero.
The only strange problem when I press my "DELAY" button on the GPIO-14, it doesn't activate the first time so that the value changes back to 1.
I have to press it twice.

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

Re: "push button active high" swith to 0 with Rules

#5 Post by TD-er » 18 Dec 2022, 14:33

Is this only on the first attempt, when booted ESPEasy?
Or do you need to do this always?

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

Re: "push button active high" swith to 0 with Rules

#6 Post by ohaldi » 18 Dec 2022, 15:09

Yes, I would like it to work always.
I don't think the variant with "taskvalueset" is the best. I'm new to EspEasy, I have the impression that the "taskvalueset" function changes a memory value and not the value stored in the GPIO14.
I set the button connected to the GPIO14 to "Switch Button Type:" as follows: "Push Button Active High". This changes the value at each push. So far it works well.
But I would like that when I enter my final function that the value returns to zero.

I also have another strange problem with this "Delay#State" button.
With : If [Delay#State]=0 the if is not interpreted correctly:

Code: Select all

on Door#State=0 do // Door is open
  event,Progress    
  LCD,1,1,""
  LCD,2,1, "Die Tor ist offen"
  If [Delay#State]=0 // Button Delay 
    LCD,4,1, "Pause AUS"
    let 2,5 // Long Time Bar 5s
  else
    LCD,4,1, "Pause EIN"
    let 2,20 // Long Time Bar 20s
  end  
  event,Progress      
endon
This always displays: LCD,4,1, "Pause AUS"
But the following example with on and endon work well:

Code: Select all

on Delay#State=1 do // Delay Button
  LCD,4,1, "Pause EIN"
  let 2,5 // Long Time Bar 20s
  event,Progress      
endon

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

Re: "push button active high" swith to 0 with Rules

#7 Post by Ath » 18 Dec 2022, 15:14

Can you show your entire rules? As by showing only some changing parts of it it gets more and more confusing.

Also showing how your devices list is set up would be helpful, especially the Switch configuration
/Ton (PayPal.me)

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

Re: "push button active high" swith to 0 with Rules

#8 Post by ohaldi » 18 Dec 2022, 15:47

Here the entire rules?

Code: Select all

on System#Boot do
  AsyncEvent,PIR#State=[PIR#State] // Let the PIR eventhandler take care of the logic
endon

on Door#State=0 do // Door is open
  event,Progress    
  LCD,1,1,""
  LCD,2,1,"Die Tor ist offen"
  If  [Delay#State]=0  // Button Delay 
    LCD,4,1,"Pause AUS"
    let 2,1 // Long Time Bar 20s
  else
    LCD,4,1,"Pause EIN"
    let 2,5 // Long Time Bar 20s
  end  
  event,Progress      
endon

on Progress do
  let 1,%eventvalue1|20% // Display with 20 characters
  LoopTimerSet,1,%v2%,%v1% // Repeat timer 1 every x sec. for n times
endon

on Rules#Timer=1 do
  LCD,1,1,{substring:0:%eventvalue2%:********************} // Timer Line 1
  if %eventvalue2%=%v1% // Have we reached 100%?
    lcdcmd,clear
    LCD,1,1,"Die Tor geht zu!"
    Pulse,27,1,400  // Pulse on GIPO 27 to close the Door
    TimerSet,2,10    // Timer to check it door closed after 10s else repeat
  endif
endon

On Rules#Timer=2 do // Door timer
  if [Door#State]=0 // Door still open?
    LCD,1,1,"Tor schliessung !.."
    Pulse,27,1,400  // Pulse on GIPO 27 to close the Door
    TimerSet,2,10   // Repeat timer 2 until door closed
  else
    TimerSet,2,0    // Stop timer 2
  endif
endon

on PIR#state do // Will be triggered when PIR state changes
  if [Door#State]=0 // Door open?
    if %eventvalue1%=1 
      TimerSet,1,0 // Stop countdown
      LCD,1,1,"ACHTUNG PIR Meldung!" 
      notify 1 //Send Email
      TimerSet,2,0    // Stop Repeat
    else // No movement on PIR
      AsyncEvent,Progress // Using default
    endif
  endif
endon

On DOOR#State=1 do // Door closed
  lcdcmd,clear
  LCD,2,1,"Die Tor ist zu"
  TimerSet,1,0 // Stop Loops
  TimerSet,2,0 // Stop Repeat
  // taskvalueset,6,1,0
Endon
Device.png
Device.png (39.3 KiB) Viewed 1778 times
Device-Door.png
Device-Door.png (65.94 KiB) Viewed 1778 times
Device-Delay.png
Device-Delay.png (69.02 KiB) Viewed 1778 times

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

Re: "push button active high" swith to 0 with Rules

#9 Post by TD-er » 18 Dec 2022, 16:05

Please have a look at this documentation page:
https://espeasy.readthedocs.io/en/lates ... e-on-esp32

It shows you the best pins to use on an ESP32 and remarks why some pins may not be the best option for some applications.

Do you have pull-up resistors present on the pins?

Pin 17 is a bit tricky as it may in some circumstances show "funky" behavior. See the special notes on that page I linked.

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

Re: "push button active high" swith to 0 with Rules

#10 Post by ohaldi » 18 Dec 2022, 16:46

Thanks again for your patience with my problem.
Yes, I have a resitor with 4.6kOhm. But pull-down.
Like this :
Device-Delay-Pull-Down-Resistor.png
Device-Delay-Pull-Down-Resistor.png (30.62 KiB) Viewed 1771 times
I changed the GPIO-17 to GPIO-25 and GPIO-14 to GPIO26.
Device_b.png
Device_b.png (44.35 KiB) Viewed 1771 times
But I still have the above mentioned issues!

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

Re: "push button active high" swith to 0 with Rules

#11 Post by TD-er » 18 Dec 2022, 16:53

Why are you using it as a pull down resistor?
Typically switches are configured with pull-up resistors and the switch then pulls it down.

Not sure if it really makes a difference here, with regards to picking up noise which may trigger false pulses.
Anyway, Since you're using a push button, pressing it may trigger several pulses.
So you should have the debounce filter enabled with something like 50 or 100 msec.
Do you have this debounce enabled?

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

Re: "push button active high" swith to 0 with Rules

#12 Post by ohaldi » 18 Dec 2022, 17:04

OK, I'm going to change in the future to pull-up. I found this example somewhere on the web.
I also realized my logical error. In fact, with the on / endon command, this is only executed when there is a change, not all the time. This is the reason why my if "If [Delay#State]=0"
inside is not evaluated.
Now I just need to find a way to set the [Delay#State] to zero without having to press the button.

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

Re: "push button active high" swith to 0 with Rules

#13 Post by Ath » 18 Dec 2022, 17:12

What's the intent of that Delay button?

NB: You can use a Dummy device to store 1..4 values, or use the Let command to set an internal variable that can be referenced via [VAR#n] or %Vn%, where n is the number you used in the Let command (1..MAXINT).
/Ton (PayPal.me)

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

Re: "push button active high" swith to 0 with Rules

#14 Post by ohaldi » 21 Dec 2022, 11:02

I have read your idea on the basis of Dummy variables. And this was the right solution for me. Thanks again.
Devices.png
Devices.png (72.95 KiB) Viewed 1690 times
The script has also become simpler with the Dummy variable.

Code: Select all

on System#Boot do
  TaskValueSet 5,1,10
  AsyncEvent,PIR#State=[PIR#State] // Let the PIR eventhandler take care of the logic
endon

on Door#State=0 do // Door is open
  TimerSet,1,0 // Stop Loops
  event,Progress    
  LCD,1,1,""
  LCD,2,1,"Das Tor ist offen"
endon

on DelayButton#State=1 do  // Set Delay ON
  TaskValueSet 5,1,40 // Slow Prog.Bar 40s
  event,Progress
  LCD,4,1,"Pause ist EIN"
endon 

on Progress do
  let 1,%eventvalue1|20% // Display with 20 characters
  LoopTimerSet,1,[Delay#Value],%v1% // Repeat timer 1 every x sec. for n times
endon

on Rules#Timer=1 do
  LCD,1,1,{substring:0:%eventvalue2%:********************} // Timer Line 1
  // LCD,4,1,%eventvalue2%[Delay#Value]
  if %eventvalue2%=%v1% // Have we reached 100%?
    lcdcmd,clear
    LCD,1,1,"Die Tor geht zu!"
    Pulse,27,1,400  // Pulse on GIPO 27 to close the Door
    TimerSet,2,10    // Timer to check it door closed after 10s else repeat
  endif
endon

On Rules#Timer=2 do // Door timer
  if [Door#State]=0 // Door still open?
    LCD,1,1,"Tor schliessung !.."
    Pulse,27,1,400  // Pulse on GIPO 27 to close the Door
    TimerSet,2,10   // Repeat timer 2 until door closed
  else
    TimerSet,2,0    // Stop timer 2
  endif
endon

on PIR#state do // Will be triggered when PIR state changes
  if [Door#State]=0 // Door open?
    if %eventvalue1%=1 
      TimerSet,1,0 // Stop countdown
      LCD,1,1,"ACHTUNG PIR Meldung!" 
      notify 1 //Send Email
      AsyncEvent,Progress // Using default
    endif
  endif
endon

On DOOR#State=1 do // Door closed
  lcdcmd,clear
  LCD,2,1,"Das Tor ist zu"
  TimerSet,1,0 // Stop Loops
  TimerSet,2,0 // Stop Repeat
  TaskValueSet 5,1,10
Endon
Now everything works perfectly here is the explanation of the Script:
The purpose of the script is to manage the automatic closing of the garage door. The motorization is based on the system of the company Sommer. The script should react when the door is opened (GPIO-25 changes from 0 to 1). At this point Timer 1 starts with the display of a 20-digit progress bar (star display). If motion is detected by the PIR sensor. The progress bar is reset to zero. The space between each character is 10 seconds. This means that if no movement disturbs the progress bar, a relay closure over 400ms is activated (relay controlled by GPIO-27). At the same time Timer 2 is activated for 20 seconds. The closing signal is restarted periodically as long as the door is not closed. To extend the waiting time of the automatic closing, a button placed on GPIO-26 changes the value stored in the Dummy memory of Task 5. The time of the progress bar increases between each character to 40s. This is about 40sx20c =800 seconds / a little more than 6 minutes. Once the door is closed, the default value of Task 5 is reset and the timers are reset.

However, I still have many confusion about how the Rules work with ESPEasy!

Post Reply

Who is online

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