[SOLVED] Help with Rules for Toggle push button switch with alternate commands to drive rolling shutter

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

[SOLVED] Help with Rules for Toggle push button switch with alternate commands to drive rolling shutter

#1 Post by iz8mbw » 05 Sep 2023, 08:36

Hello.
I would like to use a push button switch connectted to ESPEasy in order to send HTTP command (using the SendToHTTP feature of ESPEasy) to open and close my rolling shutter.
So the behaviour of the push button switch should be:

Default to low, no actions (push button switch don't pressed)
When I press the push button switch, ESPEasy will send the "Open" HTTP command. [So the high level will be for some milliseconds, just the time needed to press push, after it will return to low]
When I press (later again) the push button switch, ESPEasy will send the "Close" HTTP command. [So the high level will be for some milliseconds, just the time needed to press tpush, after it will return to low]
and so on in "loop".

So, every time I press the push button switch, ESPEasy will send alternately the "Open" and "Close" HTTP command.

Thanks!
Last edited by iz8mbw on 07 Sep 2023, 08:22, edited 3 times in total.

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

Re: Help with Rules for Toggle push button switch with alternate commands

#2 Post by TD-er » 05 Sep 2023, 08:43

That's really simple to do.

You just add a Switch task.
This should be set to:
Switch Type: Switch
Switch Button Type: Push Button Active Low

As debounce you set something like 50 msec.

Let's assume you have named this task "Button1"

The rules will be something like this:

Code: Select all

on Button1#state do
  if %eventvalue1%=0
    // Commands for "off" state
  else
    // Commands for "on" state
  endif
endon

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Help with Rules for Toggle push button switch with alternate commands

#3 Post by iz8mbw » 05 Sep 2023, 10:12

Thanks, it works!

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Help with Rules for Toggle push button switch with alternate commands

#4 Post by iz8mbw » 05 Sep 2023, 11:20

...but when I reboot the ESP32 board it will go to set to "high" also if I have set this command at the beginning of the Rules:

Code: Select all

On System#Boot do
 GPIO,18,0
Endon
so rolling shutter strass to move also if the push button is not pressed.

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

Re: Help with Rules for Toggle push button switch with alternate commands

#5 Post by Ath » 05 Sep 2023, 11:35

On the Hardware tab you can set the initial state for this GPIO pin, that will be set really early after the device is booted.

Maybe you can swap the logic so that a low (0) value is the On position, and High (1) the Off position?
/Ton (PayPal.me)

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Help with Rules for Toggle push button switch with alternate commands

#6 Post by iz8mbw » 05 Sep 2023, 12:00

Yes, I have tried to invert the logic but what changes is the rolling shutter direction, so this approach isn't good.

I have also tried in the Hardware tab to set to LOW that GPIO pin but anyway for some milliseconds it looks like the GPIO is set to high so rolling shutters moves.

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

Re: Help with Rules for Toggle push button switch with alternate commands

#7 Post by Ath » 05 Sep 2023, 12:41

iz8mbw wrote: 05 Sep 2023, 12:00 I have also tried in the Hardware tab to set to LOW that GPIO pin but anyway for some milliseconds it looks like the GPIO is set to high so rolling shutters moves.
That is why I suggested to swap the logic. You might use some transistors or logic gates to invert the signal? As for most GPIO pins high is the initial state.
/Ton (PayPal.me)

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

Re: Help with Rules for Toggle push button switch with alternate commands

#8 Post by TD-er » 05 Sep 2023, 13:00

The 'logic state' of the switch task has nothing to do with the boot state of a pin for this specific use case.
The pin is used here as an input pin and the switch task is used as a toggle switch.
Thus the boot state has nothing to do with it here.

The problem here is that you don't have the proper state of the switch during boot.

If it is OK to only keep this state after a warm boot (crash/deepsleep/reboot), then you can store the state in a dummy task.
The state of the dummy task will be restored at a reboot, but not after a power cycle.

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Help with Rules for Toggle push button switch with alternate commands

#9 Post by iz8mbw » 05 Sep 2023, 13:03

Is there some software solution like apply the Rules for that GPO only after 2 seconds after the boot?

I mean, I can wait that Rule is applied some seconds after the boot.

Thanks.

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

Re: Help with Rules for Toggle push button switch with alternate commands

#10 Post by chromo23 » 05 Sep 2023, 14:06

iz8mbw wrote: 05 Sep 2023, 13:03 Is there some software solution like apply the Rules for that GPO only after 2 seconds after the boot?

I mean, I can wait that Rule is applied some seconds after the boot.

Thanks.
Yes, you could set a timer for that:

Code: Select all

On System#Boot do
 TimerSet,1,2 //set timer #1 to 2 seconds
Endon

On Rules#Timer=1 Do
  GPIO,18,0
Endon
Source: https://espeasy.readthedocs.io/en/lates ... imer#timer
Please read the documentation.

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Help with Rules for Toggle push button switch with alternate commands

#11 Post by iz8mbw » 05 Sep 2023, 15:46

but I suppose in this case I set the Timer to set the GPIO18 to 0 (wait 2 seconds after boot and then set GPIO18 to 0).
Since when I reboot or power-on the ESP32 my rolling shutters start to move also if no push button is pressed, I think the timer should be applied to the command that drive the rolling shutters.
In other words, wait 2 second before to consider to take acre about the push button.

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

Re: Help with Rules for Toggle push button switch with alternate commands

#12 Post by chromo23 » 05 Sep 2023, 17:50

iz8mbw wrote: 05 Sep 2023, 15:46 In other words, wait 2 second before to consider to take acre about the push button.
in order to wait 2 sec before input is processed you could use a variable:

Code: Select all

On System#Boot do
  TimerSet,1,2 //set timer #1 to 2 seconds
Endon

On Rules#Timer=1 Do
  Let,1,1 //set variable 1 to 1
Endon

On Button#Input Do
  If %eventvalue%=1 And [var#1]=1
    // do something
  Endif
Endon

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Help with Rules for Toggle push button switch with alternate commands

#13 Post by iz8mbw » 07 Sep 2023, 08:15

Hello.
Thanks to @chromo23 and thanks to all.
Finally I was able to avoid the initial (at boot or at reboot) "flapping" of GPIO state that sent involuntary commands to my rolling shutter.

This is my final code that drive my rolling shutter via HTTP GET (drive a Shelly 2.5) using a push button direct connected to ESPEasy:

Code: Select all

On System#Boot do
  TimerSet,1,3 //set timer #1 to 3 seconds
Endon

On Rules#Timer=1 Do
  Let,1,1 //set variable 1 to 1 after the 3 seconds of the timer
Endon

On Sw#State Do //on push button press
  If %eventvalue%=0 And [var#1]=1
    SendToHTTP 192.168.1.12,80,/roller/0?go=close //close rolling shutter
   Endif
  If %eventvalue%=1 And [var#1]=1
  SendToHTTP 192.168.1.12,80,/roller/0?go=open  //open rolling shutter
    Endif
 Endon
 
In this way every time I press the push button the rolling shutter open or close alternately.
Thanks!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests