Control of the relay when clicking the button (without network)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
kostasoft
New user
Posts: 2
Joined: 31 Oct 2016, 19:43

Control of the relay when clicking the button (without network)

#1 Post by kostasoft » 31 Oct 2016, 20:12

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.
Attachments
pic01.PNG
pic01.PNG (27.25 KiB) Viewed 11566 times
pic02.PNG
pic02.PNG (39.79 KiB) Viewed 11566 times

dlefol
Normal user
Posts: 26
Joined: 11 Nov 2015, 23:28

Re: Control of the relay when clicking the button (without network)

#2 Post by dlefol » 01 Nov 2016, 21:07

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

raptor
Normal user
Posts: 25
Joined: 25 Oct 2016, 10:39
Location: Montana / Bulgaria

Re: Control of the relay when clicking the button (without network)

#3 Post by raptor » 02 Nov 2016, 15:22

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
Untitled.png (30.08 KiB) Viewed 11478 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
Regards from Bulgaria.
raptor

kostasoft
New user
Posts: 2
Joined: 31 Oct 2016, 19:43

Re: Control of the relay when clicking the button (without network)

#4 Post by kostasoft » 02 Nov 2016, 15:27

Many thanks! I understood everything.

javier77
New user
Posts: 8
Joined: 04 Nov 2016, 15:13

Re: Control of the relay when clicking the button (without network)

#5 Post by javier77 » 04 Nov 2016, 15:16

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!

raptor
Normal user
Posts: 25
Joined: 25 Oct 2016, 10:39
Location: Montana / Bulgaria

Re: Control of the relay when clicking the button (without network)

#6 Post by raptor » 05 Nov 2016, 17:41

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.
Regards from Bulgaria.
raptor

javier77
New user
Posts: 8
Joined: 04 Nov 2016, 15:13

Re: Control of the relay when clicking the button (without network)

#7 Post by javier77 » 05 Nov 2016, 20:39

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

raptor
Normal user
Posts: 25
Joined: 25 Oct 2016, 10:39
Location: Montana / Bulgaria

Re: Control of the relay when clicking the button (without network)

#8 Post by raptor » 08 Nov 2016, 12:19

Unfortunately, I can't help you. I tried this only with Sonoff device.
Regards from Bulgaria.
raptor

gambi
New user
Posts: 3
Joined: 06 Sep 2016, 04:47

Re: Control of the relay when clicking the button (without network)

#9 Post by gambi » 24 Nov 2016, 20:11

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 ?

FranckkyDoo
Normal user
Posts: 21
Joined: 31 Oct 2016, 03:03

Re: Control of the relay when clicking the button (without network)

#10 Post by FranckkyDoo » 26 Mar 2017, 20:51

javier77

Yes

Positive to GPIO and gnd to ground

Zeric
Normal user
Posts: 18
Joined: 29 Mar 2017, 22:37

Re: Control of the relay when clicking the button (without network)

#11 Post by Zeric » 30 Mar 2017, 01:02

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

danmero
Normal user
Posts: 64
Joined: 11 May 2017, 01:19

Re: Control of the relay when clicking the button (without network)

#12 Post by danmero » 11 May 2017, 01:25

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,

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests