Sonoff - hardware button

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
m.klinge
Normal user
Posts: 12
Joined: 10 Jan 2017, 20:19

Sonoff - hardware button

#1 Post by m.klinge » 10 Jan 2017, 20:33

I've recently purchased a sonoff device and flashed it with version 120.

It work's perfectly fine over wifi, but I cannot get it to resond on the button press. The light does not seem to Work either.

I have confgured the following GPIO's under hardware:
WiFi status led: GPIO-13
SDA: GPIO-4
SCL: GPIO-5

And under devices Ive configured a button to trigger GPIO-0.When looking at the logs it does see the button being pressed, it just doesn't turn on.

Is there anything I'm missing here? I'm quite new to this so could be it's something very basic :-)

Thanks!

//M

Justblair
Normal user
Posts: 63
Joined: 08 Aug 2016, 23:42

Re: Sonoff - hardware button

#2 Post by Justblair » 10 Jan 2017, 23:41

To get it to respond to button presses you need to set up a switch in the devices section. The create a rule that changes gpio when a switch is detected.

m.klinge
Normal user
Posts: 12
Joined: 10 Jan 2017, 20:19

Re: Sonoff - hardware button

#3 Post by m.klinge » 11 Jan 2017, 08:31

Justblair wrote:To get it to respond to button presses you need to set up a switch in the devices section. The create a rule that changes gpio when a switch is detected.
I have set up the switch, but where do I configure the rule?
Mind you it's working as a stand alone, and I need it to be able to respond to button press even if the wifi connection is lost.

//M

Justblair
Normal user
Posts: 63
Joined: 08 Aug 2016, 23:42

Re: Sonoff - hardware button

#4 Post by Justblair » 11 Jan 2017, 09:24

This might help

http://www.letscontrolit.com/wiki/index ... rial_Rules

I have this as my setup... I actually have two switched set up in devices.

One lightSwitch which has a pull up activated and is push button active low. This is attached to gpio 0 and is the push button on the Sonoff
The Second called lightState is non pull up and an ordinary switch. It just reports on the state of the relay. it is attached to gpio 12.

Rule

on lightSwitch#Switch do
if [lightState#Switch]=0
gpio,12,1

else
gpio,12,0
endif
endon

I cant remember exactly why I came to this solution, It was either so that the use of the physical switch could take into account the state of the relay (ie it would not get out of phase with openhab) or it was because I was having issues with mqqt signals not reaching their destination (which i later solved by attaching the retain flag on Openhab and also the sonoff). I can tell you though it does work very well.

I also use this rule... on my switch named backroomDeskLamp. It means that the physical switch on the desklamp switches both lamps in the room. This has a very high WAF.

on lightSwitch#Switch do
if [lightState#Switch]=0
gpio,12,1
Publish /backroomFloorLamp/gpio/12,1

else
gpio,12,0
Publish /backroomFloorLamp/gpio/12,0
endif
endon
Last edited by Justblair on 11 Jan 2017, 09:43, edited 3 times in total.

m.klinge
Normal user
Posts: 12
Joined: 10 Jan 2017, 20:19

Re: Sonoff - hardware button

#5 Post by m.klinge » 11 Jan 2017, 09:26

Ahhhhh!

I wasn't aware I need to tick the box under advanced to be able to enter the rules!

Now I got it :-)

//M

Justblair
Normal user
Posts: 63
Joined: 08 Aug 2016, 23:42

Re: Sonoff - hardware button

#6 Post by Justblair » 11 Jan 2017, 09:41

I made a mistake there. The physical switch is on gpio-0. I have an external switch attached to gpio 14 (the 5th pin on the sonoffs header) I will correct the post for future visitors.

m.klinge
Normal user
Posts: 12
Joined: 10 Jan 2017, 20:19

Re: Sonoff - hardware button

#7 Post by m.klinge » 11 Jan 2017, 10:50

Justblair wrote:I made a mistake there. The physical switch is on gpio-0. I have an external switch attached to gpio 14 (the 5th pin on the sonoffs header) I will correct the post for future visitors.
Thanks - after a bit of fiddeling around I came to this solution. I like the button to work on first press no matter if the switch was turned on by wifi or the button (GPIO13 is just for the light to turn on):

on Relay#state do
if [Relay#state]=0
gpio,13,1
else
gpio,13,0
endif
endon
on Button#state do
if [Relay#state]=0
gpio,13,0
gpio,12,1
else
gpio,13,1
gpio,12,0
endif
endon

The desk lap part sounds interesting, how do the sonoff "know" when you've switched on the lamp?

//M

Justblair
Normal user
Posts: 63
Joined: 08 Aug 2016, 23:42

Re: Sonoff - hardware button

#8 Post by Justblair » 12 Jan 2017, 11:48

I am not sure what you are asking.

Code: Select all

on lightSwitch#Switch do
if [lightState#Switch]=0
gpio,12,1
Publish /backroomFloorLamp/gpio/12,1

else
gpio,12,0
Publish /backroomFloorLamp/gpio/12,0
endif
endon
This code listens for the button to be pressed. when it is pressed it checks the relay of the desklamp (which has the most easily reached button).

Once a button press has been detected it checks the state of the relay and either switches it on or off accordingly.

The command "Publish /backroomFloorLamp/gpio/12,1" publishes to the mqtt broker the instruction to switch on the floor lamp. Which in turn turns on. My openhab2 server is also listening on this topic so it flips its switches etc. to match the state of the lights. This means from the app I can see the state of each of the lights in the house regardless of how they have been switched (ie from the app or the buttons).

m.klinge
Normal user
Posts: 12
Joined: 10 Jan 2017, 20:19

Re: Sonoff - hardware button

#9 Post by m.klinge » 12 Jan 2017, 16:11

Ah ok - I tought you was talking of a non-ESP controlled lamp. This makes perfectly sense :-)

//M
Justblair wrote:I am not sure what you are asking.

Code: Select all

on lightSwitch#Switch do
if [lightState#Switch]=0
gpio,12,1
Publish /backroomFloorLamp/gpio/12,1

else
gpio,12,0
Publish /backroomFloorLamp/gpio/12,0
endif
endon
This code listens for the button to be pressed. when it is pressed it checks the relay of the desklamp (which has the most easily reached button).

Once a button press has been detected it checks the state of the relay and either switches it on or off accordingly.

The command "Publish /backroomFloorLamp/gpio/12,1" publishes to the mqtt broker the instruction to switch on the floor lamp. Which in turn turns on. My openhab2 server is also listening on this topic so it flips its switches etc. to match the state of the lights. This means from the app I can see the state of each of the lights in the house regardless of how they have been switched (ie from the app or the buttons).

vojtishek
Normal user
Posts: 70
Joined: 12 Jan 2017, 08:00

Re: Sonoff - hardware button

#10 Post by vojtishek » 05 Mar 2017, 21:17

Hi guys,

Is this means, that If I connect GPIO14 and GND to switch then I can read switch state somehow in domoticz by adding switch in espeasy gui device with gpio14?
I have flashed sonoff with espeasy and would like to change on off state as well by switch.

Thank you
Vojta

Post Reply

Who is online

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