Page 1 of 1
Control of the relay when clicking the button (without network)
Posted: 31 Oct 2016, 20:12
by kostasoft
Hi, everybody!
My device - Sonoff from Itead
Pinouts:
gpio0 - Button
gpio12 - Relay
gpio13 - Led
How to me to make that when clicking the button the relay switched?
And that it worked only by means of the standard program in a firmware that it was possible to include or turn off manually the light in the absence of the Internet or Wi-Fi of a network in particular.
Re: Control of the relay when clicking the button (without network)
Posted: 01 Nov 2016, 21:07
by dlefol
If I understand well what you're trying to do, you need to set up a rule as detailed in this post:
viewtopic.php?f=2&t=1867&p=8627&hilit=s ... ules#p8627
Re: Control of the relay when clicking the button (without network)
Posted: 02 Nov 2016, 15:22
by raptor
Hi, kosta!
First go to Tools->Advanced and enable Rules (click on Rules checkbox).
Then go to Devices and cerate switch input like here:

- Untitled.png (30.08 KiB) Viewed 13059 times
Then go to Rules tab and paste this code:
on switchon do
gpio 12,1
gpio 13,0
inputswitchstate 0,1
endon
on switchoff do
gpio 12,0
gpio 13,1
inputswitchstate 0,0
endon
on Switch#switch do
if [Switch#switch]=1
event switchon
else
event switchoff
endif
endon
Submit and reboot!
Test. This setup works for me.
For more info about rules you can see the link which dlefol give you and this
http://www.letscontrolit.com/wiki/index ... rial_Rules
Re: Control of the relay when clicking the button (without network)
Posted: 02 Nov 2016, 15:27
by kostasoft
Many thanks! I understood everything.
Re: Control of the relay when clicking the button (without network)
Posted: 04 Nov 2016, 15:16
by javier77
Hi, i am a newbie with this and i am trying to do this same project to start. The button needs to be wired to gnd and the positive to gpio0? Thanks in advance!
Re: Control of the relay when clicking the button (without network)
Posted: 05 Nov 2016, 17:41
by raptor
Hi, javier77!
If your device is Sonoff you don't need to wire the button! The button is already connected to gpio0. You need to make the settings which you can see in my previous post.
Re: Control of the relay when clicking the button (without network)
Posted: 05 Nov 2016, 20:39
by javier77
raptor wrote:Hi, javier77!
If your device is Sonoff you don't need to wire the button! The button is already connected to gpio0. You need to make the settings which you can see in my previous post.
I am trying this on a NodeMCU D1 mini using an arduino relay module and a push button.
Thanks in advance.
Javier
Re: Control of the relay when clicking the button (without network)
Posted: 08 Nov 2016, 12:19
by raptor
Unfortunately, I can't help you. I tried this only with Sonoff device.
Re: Control of the relay when clicking the button (without network)
Posted: 24 Nov 2016, 20:11
by gambi
raptor wrote:Hi, kosta!
First go to Tools->Advanced and enable Rules (click on Rules checkbox).
Then go to Devices and cerate switch input like here:
Untitled.png
Then go to Rules tab and paste this code:
on switchon do
gpio 12,1
gpio 13,0
inputswitchstate 0,1
endon
on switchoff do
gpio 12,0
gpio 13,1
inputswitchstate 0,0
endon
on Switch#switch do
if [Switch#switch]=1
event switchon
else
event switchoff
endif
endon
Submit and reboot!
Test. This setup works for me.
For more info about rules you can see the link which dlefol give you and this
http://www.letscontrolit.com/wiki/index ... rial_Rules
Hello Raptor, button works without network ?
Re: Control of the relay when clicking the button (without network)
Posted: 26 Mar 2017, 20:51
by FranckkyDoo
javier77
Yes
Positive to GPIO and gnd to ground
Re: Control of the relay when clicking the button (without network)
Posted: 30 Mar 2017, 01:02
by Zeric
This is all I have for my sonoff's:
On button#switch do // when button is pressed, toggle the relay
if [button#switch]=1
gpio, 12, 1
else
gpio, 12, 0
endif
endon
---Device Settings---
Device: Switch input
Name: button
Delay: 0
IDX/Var: [what ever you need, I just use 1]
1st GPIO: GPIO-0
Switch Type: Switch
Switch Button Types: Push Button Active Low
Pull Up, Inversed, Send Boot State, Send Data - unchecked
Value Name 1: switch
Re: Control of the relay when clicking the button (without network)
Posted: 11 May 2017, 01:25
by danmero
Hi
Only related , I set this configuration to be able to cycle the relay
Code: Select all
on System#Boot do / Set boot options
gpio,12,1
endon
on pushbutton#Switch=0 do / On push button call event/function cycle
event cycle
endon
On Clock#Time=MonTueFri,03:53 do / cron like job
event cycle
endon
on cycle do / set gpio, start timer
gpio,12,0
gpio,13,0
timerset,1,15
endon
on Rules#Timer=1 do / on time expire reset gpio
gpio,12,1
gpio,13,1
endon
Regards,