[SOLVED] Help with Rules for Toggle push button switch with alternate commands to drive rolling shutter
Moderators: grovkillen, Stuntteam, TD-er
[SOLVED] Help with Rules for Toggle push button switch with alternate commands to drive rolling shutter
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!
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.
Re: Help with Rules for Toggle push button switch with alternate commands
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:
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
Re: Help with Rules for Toggle push button switch with alternate commands
...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:
so rolling shutter strass to move also if the push button is not pressed.
Code: Select all
On System#Boot do
GPIO,18,0
Endon
Re: Help with Rules for Toggle push button switch with alternate commands
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?
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)
Re: Help with Rules for Toggle push button switch with alternate commands
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.
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.
Re: Help with Rules for Toggle push button switch with alternate commands
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)
Re: Help with Rules for Toggle push button switch with alternate commands
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.
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.
Re: Help with Rules for Toggle push button switch with alternate commands
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.
I mean, I can wait that Rule is applied some seconds after the boot.
Thanks.
Re: Help with Rules for Toggle push button switch with alternate commands
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
Please read the documentation.
Re: Help with Rules for Toggle push button switch with alternate commands
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.
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.
Re: Help with Rules for Toggle push button switch with alternate commands
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
Re: Help with Rules for Toggle push button switch with alternate commands
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:
In this way every time I press the push button the rolling shutter open or close alternately.
Thanks!
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
Thanks!
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest