To avoid these ads, REGISTER NOW!

DIY home automation , 30$

cthulu

Well-known member
Joined
Aug 20, 2014
Messages
246
Location
Western Washington
Hey guys, I recently finished a project to send power to my parts washer on Saturdays without me having to get up and turn it on. This same basic principal can be used with basically anything that pulls under 30 amps, you could also use a larger amperage contactor and run this for larger appliances as well.

Goal was to be able to use my computer to set a timer/schedule for things in the shop, End of the post lists all the parts used and what I paid with links. Total cost per unit is about 30$

After you've assembled the box and soldered your breakaway pins in the sonoff device (3v3, grd, tx,rx) , directions below. You are ready to start programming the new device.

http://blog.kilomon.com/2018/01/hacking-sonoff-wifi-switch.html

You'll need to download arduino and install it on your computer.

https://www.arduino.cc/en/Main/Software

You can then use this software and the programmer listed in the parts section to connect to the sonoff device and reprogram it with the below code.

The second part of the directions helped a lot but the code didn't get me there 100% so I used the below code instead.

http://blog.kilomon.com/2018/02/hacking-sonoff-wifi-switch-part-2.html

// Load Wi-Fi library
#include <ESP8266WiFi.h>

// Replace with your network credentials
const char* ssid = "YourWifiSSID";
const char* password = "YourWIFIpassword";

// Set web server port number to 80
WiFiServer server(80);

// Variable to store the HTTP request
String header;

// Auxiliar variables to store the current output state
String output5State = "off";
String output4State = "off";

// Assign output variables to GPIO pins
const int output5 = 13;
const int output4 = 12;

void setup() {
Serial.begin(115200);
// Initialize the output variables as outputs
pinMode(output5, OUTPUT);
pinMode(output4, OUTPUT);
// Set outputs to LOW
digitalWrite(output5, LOW);
digitalWrite(output4, LOW);

// Connect to Wi-Fi network with SSID and password
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
}

void loop(){
WiFiClient client = server.available(); // Listen for incoming clients

if (client) { // If a new client connects,
Serial.println("New Client."); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();

// turns the GPIOs on and off
if (header.indexOf("GET /5/on") >= 0) {
Serial.println("GPIO 5 on");
output5State = "on";
digitalWrite(output5, HIGH);
} else if (header.indexOf("GET /5/off") >= 0) {
Serial.println("GPIO 5 off");
output5State = "off";
digitalWrite(output5, LOW);
} else if (header.indexOf("GET /4/on") >= 0) {
Serial.println("GPIO 4 on");
output4State = "on";
digitalWrite(output4, HIGH);
} else if (header.indexOf("GET /4/off") >= 0) {
Serial.println("GPIO 4 off");
output4State = "off";
digitalWrite(output4, LOW);
}

// Display the HTML web page
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name="viewport" content="width=device-width, initial-scale=1">");
client.println("<link rel="icon" href="data:,">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
client.println(".button { background-color: #195B6A; border: none; color: white; padding: 16px 40px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
client.println(".button2 {background-color: #77878A;}</style></head>");

// Web Page Heading
client.println("<body><h1>ESP8266 Web Server</h1>");

// Display current state, and ON/OFF buttons for GPIO 5
client.println("<p>GPIO 5 - State " + output5State + "</p>");
// If the output5State is off, it displays the ON button
if (output5State=="off") {
client.println("<p><a href="/5/on"><button class="button">ON</button></a></p>");
} else {
client.println("<p><a href="/5/off"><button class="button button2">OFF</button></a></p>");
}

// Display current state, and ON/OFF buttons for GPIO 4
client.println("<p>GPIO 4 - State " + output4State + "</p>");
// If the output4State is off, it displays the ON button
if (output4State=="off") {
client.println("<p><a href="/4/on"><button class="button">ON</button></a></p>");
} else {
client.println("<p><a href="/4/off"><button class="button button2">OFF</button></a></p>");
}
client.println("</body></html>");

// The HTTP response ends with another blank line
client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}


Finally you now need a way to activate the switch to test it, I couldn't get the web browser working correctly so I used a windows programming language called PowerShell to do it. Replace the IP of your sonoff device in the below script and this will turn the led on and the relay on. (Yes, I know the on/off is backwards, but I didn't notice till I had put the box back together you could change the above code and reflash if it bugs you)

Copy the below into notepad and save as TurnOn.PS1 and select all files in notepad. Then you can right click the script and run it with powershell to turn on your device for further automation you can use windows task scheduler to execute the scripts on a set time frame.

#turns led and relay on
Invoke-WebRequest -UseBasicParsing -Uri http://192.168.1.149/5/off
Invoke-WebRequest -UseBasicParsing -Uri http://192.168.1.149/4/on


Below is the code for turning the relay and led off.

#turns led and relay off
Invoke-WebRequest -UseBasicParsing -Uri http://192.168.1.149/5/on
Invoke-WebRequest -UseBasicParsing -Uri http://192.168.1.149/4/off

Programmer, 12.49$

Reusable on future projects, there are cheaper ones that don't work as well as this one (ask me how I know)

https://www.amazon.com/gp/product/B075N82CDL/?tag=atomicindus08-20



Breakaway pins, 10.99$

You could just solder everything together permanently.

https://www.amazon.com/gp/product/B01MFBPH9N/?tag=atomicindus08-20



Power cord, 1-3, 9.12$

You could easily use any old powercord though.

https://www.amazon.com/gp/product/B000BQU576/?tag=atomicindus08-20



Contactors/Relay 12.99$

https://www.amazon.com/gp/product/B07587NZTC/?tag=atomicindus08-20


Cable Glands, 10.99$

https://www.amazon.com/gp/product/B01GJ03AUQ/?tag=atomicindus08-20


Project box, clear. 8.99$

https://www.amazon.com/gp/product/B072FS4118/?tag=atomicindus08-20

Jumper wires, 6.98$

https://www.amazon.com/gp/product/B01EV70C78/?tag=atomicindus08-20


Sonoff WiFi Swtich Pack of 2, 13.52

https://www.amazon.com/gp/product/B07BDFDHX9/?tag=atomicindus08-20
 

Attachments

  • 9153457662926493608.jpg
    9153457662926493608.jpg
    53.5 KB · Views: 131
To avoid these ads, REGISTER NOW!
OP
C

cthulu

Well-known member
Joined
Aug 20, 2014
Messages
246
Location
Western Washington
Nice, Subscribed...

I mean, its done? There's nothing else coming really, you plug it in then use powershell on your computer to schedule when you want the thing to actually get power. Was there something missing that you'd like to see in the post? This is half for you guys and half for me so I can remember what I did!
 

checkthisout

Well-known member
Joined
Sep 5, 2008
Messages
5,232
I mean, its done? There's nothing else coming really, you plug it in then use powershell on your computer to schedule when you want the thing to actually get power. Was there something missing that you'd like to see in the post? This is half for you guys and half for me so I can remember what I did!

I like your work, but....

Why didn't you just use a readily available wifi switch that would have about 1/2 the price you spent as well as being far less time spent?
 

ddawg16

Well-known member
Joined
Jul 11, 2008
Messages
21,005
Location
S. California
I like your work, but....

Why didn't you just use a readily available wifi switch that would have about 1/2 the price you spent as well as being far less time spent?

And where's the fun in that?

For the same reason we have garages.

I've been tempted to play around with a Raspberry PII. Lot more options for HMI's. And I would name it Jarvis
 
OP
C

cthulu

Well-known member
Joined
Aug 20, 2014
Messages
246
Location
Western Washington
I have a tp link wifi plug that can run schedules. Costs 20-30. Is this the same thing?

If you have something like the below, sort of. Its amperage use is limited, and everything you say or do on Alexa is stored by amazon forever and tied to you personally (or the residence) What I like about this is that large corporations don't have any involvement in the exchange of data, it's all local.

https://www.amazon.com/tp-link-wifi-plug/s?page=1&rh=i:aps,k:tp link wifi plug
 
OP
C

cthulu

Well-known member
Joined
Aug 20, 2014
Messages
246
Location
Western Washington
I like your work, but....

Why didn't you just use a readily available wifi switch that would have about 1/2 the price you spent as well as being far less time spent?

If they make a 30$ wifi switch that doesn't depend on Alexa or similar services and can handle 30 amps with infinite ability to schedule I would buy one. This was a fun project, but it was a project because a similar device for a reasonable amount of money doesn't exist!
 

dogdog

Well-known member
Joined
Nov 15, 2011
Messages
12,711
I mean, its done? There's nothing else coming really, you plug it in then use powershell on your computer to schedule when you want the thing to actually get power. Was there something missing that you'd like to see in the post? This is half for you guys and half for me so I can remember what I did!

Yes a Marker for me to find this when I needed it. Not something immediate..

MicroCenter have the google AIY kit on sale now for $5 limited 5 per person ATM, maybe see if it would work well with this switch/hack... when I got time later... playing with MCP41100 right now.

https://www.microcenter.com/product/483414/aiy-voice-kit
 
To avoid these ads, REGISTER NOW!

OccupantRJ

Well-known member
Joined
May 15, 2009
Messages
11,029
Location
Eastern North Carolina
For the same reason we have garages.

I've been tempted to play around with a Raspberry PII. Lot more options for HMI's. And I would name it Jarvis

As in butler? That is why I named the black French bulldog Jarvis that you played with here, because of being black in color with a white chest blaze that looked like a tux. Sadly Jarvis is no longer with us as of 3 years ago.
 
OP
C

cthulu

Well-known member
Joined
Aug 20, 2014
Messages
246
Location
Western Washington
Yes a Marker for me to find this when I needed it. Not something immediate..

MicroCenter have the google AIY kit on sale now for $5 limited 5 per person ATM, maybe see if it would work well with this switch/hack... when I got time later... playing with MCP41100 right now.

https://www.microcenter.com/product/483414/aiy-voice-kit

I don't know much about this kind of thing besides the principals behind it, was a little frustrating at times but I learned a lot and now plan to make a few of these for my heater, compressor and then maybe some home security. The components are really cheap so as long as you have a computer it's not a big deal to get everything up and running, go down there and buy a kit man!

The reason I like hacking the sonoff boards is that they are so cheap, use 110v current for the board (no separate power supply) and use a common wifi chip (eps8266)
 

rlitman

Well-known member
Joined
Oct 18, 2010
Messages
24,596
Location
Long Island
If they make a 30$ wifi switch that doesn't depend on Alexa or similar services and can handle 30 amps with infinite ability to schedule I would buy one. This was a fun project, but it was a project because a similar device for a reasonable amount of money doesn't exist!

Well, I for one like what you did.

For my own purposes, I'm ok with an Alexa controlled relay. I have a number of Sonoff devices running through their cloud services. Yes, I'd prefer to have it completely within my control, but I also need it to work for my other family members. And the built-in services are just so damned easy to get working.
 

checkthisout

Well-known member
Joined
Sep 5, 2008
Messages
5,232
If they make a 30$ wifi switch that doesn't depend on Alexa or similar services and can handle 30 amps with infinite ability to schedule I would buy one. This was a fun project, but it was a project because a similar device for a reasonable amount of money doesn't exist!

You can hook the $15.00 wifi switches up to isolated contact relays and then use them for whatever voltage and amps you like and then use already existing platforms to make them do what you like whenever you like.

Please understand though, I appreciate what you did. Just trying to wrap my head around in what ways it's better other than the satisfaction of making it more DIY.

I run smart things and use regular switches connected to misc relays to control various things.
 
OP
C

cthulu

Well-known member
Joined
Aug 20, 2014
Messages
246
Location
Western Washington
Please understand though, I appreciate what you did. Just trying to wrap my head around in what ways it's better other than the satisfaction of making it more DIY.
.

Gotcha, this uses a higher amperage relay just like you are doing but I don't like the Alexa integration due to privacy concerns. I wanted something where every bit of code was something I wrote and having it work without internet connectivity.
 

tboy

Well-known member
Joined
May 23, 2013
Messages
149
Location
Central Ohio
Gotcha, this uses a higher amperage relay just like you are doing but I don't like the Alexa integration due to privacy concerns. I wanted something where every bit of code was something I wrote and having it work without internet connectivity.

Great project. I suggest you check out the Shelly1 devices. I am just getting into this myself. I have a couple shelly1's and also Sonoff.

https://www.amazon.com/stores/page/4B307793-3BE3-4F0C-94C3-3F80FDDC83D2?store_ref=storeRecs_Instant_17871341011

Shelly1 can do 16 amps (a bit more overhead than the standard 15 amp house breaker) and can run locally without cloud integration. It is also maker friendly and breaks out the programing pins (without having to solder or open the case).

Cost is on par but more expensive than the sonoff. I bought two for 23$ from amazon. The app is very nice (way nicer than ewelink), that is if you are using stock firmware.
 
OP
C

cthulu

Well-known member
Joined
Aug 20, 2014
Messages
246
Location
Western Washington
Shelly1 can do 16 amps (a bit more overhead than the standard 15 amp house breaker) and can run locally without cloud integration. It is also maker friendly and breaks out the programing pins (without having to solder or open the case).

I ran across the Shelly products but thought they were two different channels at 8amps each, are you using it on anything that has serious draw? (compressor, electric motors, etc.) I do like that their product integrates into existing electric boxes, I see a lot of newer higher end homes having all the electrical integrated into something like this.
 

75gmck25

Well-known member
Joined
Jul 21, 2014
Messages
1,320
Location
Alexandria, VA
Originally Posted by checkthisout
"I like your work, but....
Why didn't you just use a readily available wifi switch that would have about 1/2 the price you spent as well as being far less time spent?"
----------------------------------------
Isn't that very similar to when your wife asks
"why do you need a 30x40 foot garage and $10k in tools to work on your classic car every evening just so you can drive it on the weekend, when you could buy a 2 year old Honda or Chevy for $10k and drive it every day without needing to work on it?"
What's the fun in that?

I've tried a few simple projects with the Raspberry Pi,and based on this post I'm interested in also playing around with Arduino.

My very simple explanation of how they are different is that the Raspberry Pi is a small computer (usually running a version of Linux), while the Arduino is more like a small controller (running a real-time operating system).

If you want to make a media server, small shop computer, or use it for other data processing and handling, then the Raspberry Pi is better. In fact, there is a standard boxed version that has the capability to be a media server. Just add storage with an external disk or memory stick, and connect it to your network and monitor. It already has an ethernet connection, bluetooth, USB ports, and HDMI video, and the package is about the size of a pack of cigarettes.

It seems that the Arduino is better suited to being used for a lighting or HVAC controller, monitoring status of mechanical devices, controlling devices, and other more mechanical tasks that are driven by inputs and outputs, although it can be programmed to make very complex decisions based on the inputs.

Bruce
 

tboy

Well-known member
Joined
May 23, 2013
Messages
149
Location
Central Ohio
I ran across the Shelly products but thought they were two different channels at 8amps each, are you using it on anything that has serious draw? (compressor, electric motors, etc.) I do like that their product integrates into existing electric boxes, I see a lot of newer higher end homes having all the electrical integrated into something like this.

You are thinking of the shelly2. It has two relays, 8 amps each. I think it is the same size as the Shelly1, which only has the one relay, 16 amps. So far I am not running anything big on it, just a light fixture with 4 led bulbs (so the load is miniscule). I could probably put one on my compressor outlet though, it is currently on a 15 amp breaker (i am pretty sure) so the Shelly1 should handle it. I'm not sure if the module would accept a 12 gauge wire though, I'd have to check on that.

I did note they are no longer available from amazon. Going back to their website it looks like they have oversold almost everything they make (i guess a good problem to have). I ended up buying a few more shelly1's from the website which said they had a 7 day lead. Here's hoping they get back to amazon soon.
 
To avoid these ads, REGISTER NOW!
Top Bottom