Set Input GPIO values via Rules

Moderators: grovkillen, Stuntteam, TD-er

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

Set Input GPIO values via Rules

#1 Post by iz8mbw » 23 Oct 2023, 18:35

Hello.
I need to set an Input GPIO value to 0 (zero) via Rules on ESP32 board.
For example in Rules if I have some like that:

Code: Select all

On Rules#Timer=2 do
 GPIO,34,0
 Let,8,0
Endon
but it does not put GPIO 34 to 0.
If I use instead an Input/Output GPIO it works.

How can I set an Input GPO value via Rules?

Thanks.

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

Re: Set Input GPIO values via Rules

#2 Post by chromo23 » 23 Oct 2023, 19:11

I don´t know what you want to archive but if you want to kind of reset the value you could do so by storing the gpio state in a dummy device.
After the timer has finished you can set the value of the dummy device to zero. And if you use TaskValueSetAndRun an event is created to switch something if you want:

Code: Select all

On Switch#State Do
  TaskValueSetAndRun,DummyDevice,FirstValue,%eventvalue%
Endon

On Rules#Timer=2 Do
  TaskValueSetAndRun,DummyDevice,FirstValue,0
   Let,8,0
Endon

On DummyDevice#FirstValue Do
  //switch something
Endon

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

Re: Set Input GPIO values via Rules

#3 Post by TD-er » 23 Oct 2023, 19:15

If it is an input, then you probably have something connected to it that will pull the pin to a specific state.

The gpio command will switch the pin to be an output pin and try to pull it low.
But if you have pulled the pin high, then the one with the strongest pulling force will "win".
A GPIO pin on an ESP32 may pull upto 40 mA to GND (less current wel pulling up), thus whatever is connected to that pin suddenly has to handle so much current.
Not all devices can handle this for a long time and you may also damage the GPIO pin of the ESP.

Can you show what you try to do here and what is connected?

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

Re: Set Input GPIO values via Rules

#4 Post by iz8mbw » 23 Oct 2023, 19:27

So if I have a push button switch connected to a GPIO (pulled down via a resistor) and I press the button (so I gives to that GPIO a 3V3 just the time of pushing the button), the GPO changes to 1, if I press again it will switch to 0 and so on in loop at every press. Well, it works OK and by design.
If in my Rules I need/want to "simulate" a press or better to say put that GPIO to 0, how can I do it?

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

Re: Set Input GPIO values via Rules

#5 Post by chromo23 » 23 Oct 2023, 19:33

iz8mbw wrote: 23 Oct 2023, 19:27 If in my Rules I need/want to "simulate" a press or better to say put that GPIO to 0, how can I do it?
Switch the device you also control with the pushbutton not the pushbutton itself....

Edit: your complete ruleset would be helpful for better understanding and helping

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

Re: Set Input GPIO values via Rules

#6 Post by TD-er » 23 Oct 2023, 19:47

You can't change the Switch state.
But you can 'copy' the value to a Dummy task and on a switch event toggle the dummy task value.

Assuming your switch task is called "switch" and the task value is "state".
The dummy task is then called "dummysw" and its task value is "state".
If not, you may need to change it in these rules:

Code: Select all

on switch#state do
  taskvalueset,dummysw,state,![dummysw#state]
  taskrun,dummysw
endon

// override switch state sending an event like this:
// event,overrideswitch=0 to set the dummysw#state to 0
// event,overrideswitch=1 to set the dummysw#state to 1
on overrideswitch do
  taskvalueset,dummysw,state,%eventvalue1%
  taskrun,dummysw
endon
If you need to immediately send out data to any connected controller (to the dummy task, not the switch task), you can either call "taskvaluesetandrun" or call "taskrun,dummysw" as a separate command.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests