Esp with physical button steering a Sonoff.
Moderators: grovkillen, Stuntteam, TD-er
-
- Normal user
- Posts: 286
- Joined: 27 Dec 2015, 11:26
- Location: the Netherlands
Esp with physical button steering a Sonoff.
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?
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?
-
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
Re: Esp with physical button steering a Sonoff.
Yes no problem at all, you can use either HTTP or MQTT to trigger that from the "controller board" unit.
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

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



-
- Normal user
- Posts: 286
- Joined: 27 Dec 2015, 11:26
- Location: the Netherlands
Re: Esp with physical button steering a Sonoff.
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. 

-
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
Re: Esp with physical button steering a Sonoff.
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).
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).
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

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



-
- Normal user
- Posts: 286
- Joined: 27 Dec 2015, 11:26
- Location: the Netherlands
Re: Esp with physical button steering a Sonoff.
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.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).
-
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
Re: Esp with physical button steering a Sonoff.
Ok, on the three Sonoffs you need to have these rules:
This makes the Sonoff button turn off or on the relay (aka the power).
Now on the controller ESP unit:
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
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
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
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

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

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



-
- Normal user
- Posts: 286
- Joined: 27 Dec 2015, 11:26
- Location: the Netherlands
Re: Esp with physical button steering a Sonoff.
Thanks grovkillen for the quick response and help. This help me on the way what i want.grovkillen wrote: ↑13 Dec 2017, 13:31 Ok, on the three Sonoffs you need to have these rules:
This makes the Sonoff button turn off or on the relay (aka the power).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
Now on the controller ESP unit:
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.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
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![]()
-
- Normal user
- Posts: 286
- Joined: 27 Dec 2015, 11:26
- Location: the Netherlands
Re: Esp with physical button steering a Sonoff.
@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
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
-
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
Re: Esp with physical button steering a Sonoff.
Happy to have assisted. 

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

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



Who is online
Users browsing this forum: No registered users and 17 guests