Pushbutton toggle

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
kgrassers
New user
Posts: 7
Joined: 12 May 2017, 14:54

Pushbutton toggle

#1 Post by kgrassers » 26 Jul 2017, 01:08

I would like to use a push button to toggle a relay based on GPIO condition.
Could someone help me?
I am not sure the proper way in rules to check status of GPIO.

On Pushbutton=1 do
if GPIO13 is 1
then
set GPIO13=0
else
set GPIO13=1

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Pushbutton toggle

#2 Post by grovkillen » 26 Jul 2017, 22:51

Please post your page with devices.

I suspect you need to do something like this:

Code: Select all

On pushbutton#state do
if pushbutton#state=1
 GPIO,13,0
else
 GPIO,13,1
endon
Have you studied the wiki at all?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

kgrassers
New user
Posts: 7
Joined: 12 May 2017, 14:54

Re: Pushbutton toggle

#3 Post by kgrassers » 31 Jul 2017, 23:25

I have looked at the wiki, i think :|

.. could you send me link?

I am using a Nodemcu Wemos D1.

i have a pushbutton connected between - and D2
relay connected from D7 -> Led -> inputrelay

the code you suggested always just preforms the first part of the statement
I would like to push the button and if the relay is already high then send it low and vise versa.

randytsuch
Normal user
Posts: 33
Joined: 05 Jun 2017, 05:32

Re: Pushbutton toggle

#4 Post by randytsuch » 01 Aug 2017, 00:47

Look at this thread, it should help

https://www.letscontrolit.com/forum/vie ... php?t=1655

BerndJ
Normal user
Posts: 86
Joined: 28 Sep 2015, 06:57

it´s so easy

#5 Post by BerndJ » 01 Aug 2017, 00:57

Hi,

in another Thread i find the solution, here are a rule for a modified (LED in red working on GPIO12) sonoff Basic:

Code: Select all

On Button#Switch=toggle do
if [Steckdose#Switch]=0
     gpio,12,1
  else
     gpio,12,0
 endif
EndOn
Thing we should include it
(the choice =toggle) to the wiki

U had to create a device switch input with name Button, Valuename Switch on GPIO0 and
also one with name Steckdose, Valuename Switch on GPIO12.

best wishes

BerndJ
Last edited by BerndJ on 01 Aug 2017, 12:43, edited 1 time in total.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Pushbutton toggle

#6 Post by grovkillen » 01 Aug 2017, 09:33

kgrassers wrote: 31 Jul 2017, 23:25 I would like to push the button and if the relay is already high then send it low and vise versa.
Then you need to create a device for the relay. You find more on the wiki for the Sonoff Touch (link below).

Code: Select all

On pushbutton#state do
if relay#state=1
 GPIO,13,0
else
 GPIO,13,1
endif
endon
https://www.letscontrolit.com/wiki/inde ... noff_Touch

PS. I forgot the "endif" in my first code.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Post Reply

Who is online

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