Page 1 of 1

Esp with physical button steering a Sonoff.

Posted: 13 Dec 2017, 10:53
by ManS-H
Hello,

I have the idea to switch on/off my 3 Sonoff devices with a physical button. For that i want made a small box with a esp8266 and 3 push buttons so if it is necessary i can switch on/off my table lights without using a smartphone or tablet.

My question, is this possible on this way?

Re: Esp with physical button steering a Sonoff.

Posted: 13 Dec 2017, 11:13
by grovkillen
Yes no problem at all, you can use either HTTP or MQTT to trigger that from the "controller board" unit.

Re: Esp with physical button steering a Sonoff.

Posted: 13 Dec 2017, 11:46
by ManS-H
Thanks for the answer, but did you maybe have a small sample how to do that? Thats my problem on the moment, i do't see the light. :oops:

Re: Esp with physical button steering a Sonoff.

Posted: 13 Dec 2017, 12:31
by grovkillen
First of, do you have a MQTT broker up and running? If not, do you want one? If not, the only way is the HTTP way.

MQTT will give you feedback on your push button actions more streamline.
HTTP does not require any server to work, it is possible to get feedback from the Sonoffs this way but it's a bit more to tinker with rules.

You will need to make your decision regarding the information protocol (HTTP or MQTT) before I will start giving you more advice since the two approaches are not similar.

If you want to test a MQTT server but doesn't want to install one you may download the portable Mosquitto server which I have made on my blog (link far down in some of the ESP related blog posts).

Re: Esp with physical button steering a Sonoff.

Posted: 13 Dec 2017, 12:58
by ManS-H
grovkillen wrote: 13 Dec 2017, 12:31 First of, do you have a MQTT broker up and running? If not, do you want one? If not, the only way is the HTTP way.

MQTT will give you feedback on your push button actions more streamline.
HTTP does not require any server to work, it is possible to get feedback from the Sonoffs this way but it's a bit more to tinker with rules.

You will need to make your decision regarding the information protocol (HTTP or MQTT) before I will start giving you more advice since the two approaches are not similar.

If you want to test a MQTT server but doesn't want to install one you may download the portable Mosquitto server which I have made on my blog (link far down in some of the ESP related blog posts).
For me MQTT is complete new, so for me is the best way to start the HTTP way. After that i can decided how it works with MQTT, and then is your portable solution an option.

Re: Esp with physical button steering a Sonoff.

Posted: 13 Dec 2017, 13:31
by grovkillen
Ok, on the three Sonoffs you need to have these rules:

Code: Select all

 on button#switch do
  Event,ToggleRelay
 endon 
 
  on ToggleRelay do
  if [relay#state]=0
   gpio,12,1
  else
   gpio,12,0
  endif
 endon 
This makes the Sonoff button turn off or on the relay (aka the power).

Now on the controller ESP unit:

Code: Select all

 on button1#switch do
  SendToHTTP,<ip of sonoff1>,80,/control?cmd=Event,ToggleRelay
 endon 
 on button2#switch do
  SendToHTTP,<ip of sonoff2>,80,/control?cmd=Event,ToggleRelay
 endon 
 on button3#switch do
  SendToHTTP,<ip of sonoff3>,80,/control?cmd=Event,ToggleRelay
 endon 
 
If you want the nodes (Sonoffs) to report back that they have turned the light on you need to SendToHTTP from their side to for example light a LED up or something.

Please be aware that I typed these rules out of my head and haven't run them. Some typos and mistakes might be existing. Do not get angry with me :)

Re: Esp with physical button steering a Sonoff.

Posted: 13 Dec 2017, 13:39
by ManS-H
grovkillen wrote: 13 Dec 2017, 13:31 Ok, on the three Sonoffs you need to have these rules:

Code: Select all

 on button#switch do
  Event,ToggleRelay
 endon 
 
  on ToggleRelay do
  if [relay#state]=0
   gpio,12,1
  else
   gpio,12,0
  endif
 endon 
This makes the Sonoff button turn off or on the relay (aka the power).

Now on the controller ESP unit:

Code: Select all

 on button1#switch do
  SendToHTTP,<ip of sonoff1>,80,/control?cmd=Event,ToggleRelay
 endon 
 on button2#switch do
  SendToHTTP,<ip of sonoff2>,80,/control?cmd=Event,ToggleRelay
 endon 
 on button3#switch do
  SendToHTTP,<ip of sonoff3>,80,/control?cmd=Event,ToggleRelay
 endon 
 
If you want the nodes (Sonoffs) to report back that they have turned the light on you need to SendToHTTP from their side to for example light a LED up or something.

Please be aware that I typed these rules out of my head and haven't run them. Some typos and mistakes might be existing. Do not get angry with me :)
Thanks grovkillen for the quick response and help. This help me on the way what i want.

Re: Esp with physical button steering a Sonoff.

Posted: 14 Dec 2017, 20:52
by ManS-H
@grovkillen,

Buttons and Sonoff's are working with the rules. It was a lot of reading to understand the mechanism of rules. But with your samples i have now a working solution, Thanks

Re: Esp with physical button steering a Sonoff.

Posted: 14 Dec 2017, 21:05
by grovkillen
Happy to have assisted. :ugeek: