Esp with physical button steering a Sonoff.

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
ManS-H
Normal user
Posts: 281
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Esp with physical button steering a Sonoff.

#1 Post by ManS-H » 13 Dec 2017, 10:53

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?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Esp with physical button steering a Sonoff.

#2 Post by grovkillen » 13 Dec 2017, 11:13

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 :idea: :idea: :idea:

User avatar
ManS-H
Normal user
Posts: 281
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Esp with physical button steering a Sonoff.

#3 Post by ManS-H » 13 Dec 2017, 11:46

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:

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Esp with physical button steering a Sonoff.

#4 Post by grovkillen » 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).
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 :idea: :idea: :idea:

User avatar
ManS-H
Normal user
Posts: 281
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Esp with physical button steering a Sonoff.

#5 Post by ManS-H » 13 Dec 2017, 12:58

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.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Esp with physical button steering a Sonoff.

#6 Post by grovkillen » 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 :)
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 :idea: :idea: :idea:

User avatar
ManS-H
Normal user
Posts: 281
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Esp with physical button steering a Sonoff.

#7 Post by ManS-H » 13 Dec 2017, 13:39

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.

User avatar
ManS-H
Normal user
Posts: 281
Joined: 27 Dec 2015, 11:26
Location: the Netherlands

Re: Esp with physical button steering a Sonoff.

#8 Post by ManS-H » 14 Dec 2017, 20:52

@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

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Esp with physical button steering a Sonoff.

#9 Post by grovkillen » 14 Dec 2017, 21:05

Happy to have assisted. :ugeek:
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 :idea: :idea: :idea:

Post Reply

Who is online

Users browsing this forum: No registered users and 124 guests