HomeKit HomeBridge Enabled Arduino ESP8266 Self Powered 110v Wifi Controlled Powerswitch

http://www.instructables.com/id/HomeKit-Enabled-Arduino-ESP8266-Self-Powered-110v-/

Why buy a UL Listed iDevices Switch when you can potentially electrocute yourself or start a fire with a self built alternative instead?

Here’s how!

First, you must install HomeBridge on a Raspberry Pi, and configure it as a HomeKit bridge device. Instructions below.

Once you have HomeKit / HomeBridge working on your Pi and your iPhone, we can build a wireless power switch that can be controlled by Siri and the HomeKit app.

We start with a PowerTail2, and use the ESP8266 to control the on/off line.

We power the ESP8266 with a AMS1117 3.3V Power Supply Module. This brings the 5v from the charger down to the proper 3.3v that the ESP8266 needs.

We provide the power with a used cell phone charger. 110v -> 5v. This is wired directly to the ‘Line’ side of the PowerTail2 circuit board. It is always ‘Live’ or ‘Hot’ and will shock you.

We Load the code into the ESP8266 via your favorite USB/Serial converter (FTDI).

We plug it in. Homekit sees the device via the HomeBridge configuration file addition (accessory) on the Raspberry Pi.

You control the device on your iPhone, and turn electricity on and off at will.

More info to come.

Resources:

https://github.com/esp8266/Arduino/tree/master/lib…

http://www.electrodragon.com/w/ESP8266_AT_Commands

https://www.google.com/search?q=esp8266+arduino&es…

http://www.powerswitchtail.com/Documents/PSTK%20In…

Homekit:

https://github.com/nfarina/homebridge

https://github.com/nfarina/homebridge/wiki/Running…

https://www.npmjs.com/package/homebridge-indigo

https://www.google.com/webhp?sourceid=chrome-insta…

https://github.com/lagunacomputer/homebridge-Curre…

Step 1 Build It:

Solder it together.

1x PowerTail II Power switch kit $19.99 + shipping

1x ESP8266 ESP-01 module $5.50

1x AMS1117-3.3 Power Module AMS1117 3.3V Power Supply Module With Heat Sink $0.99

1x 110v to 5v/1A used cell phone charger

1x small Perfboard for circuit approx 2″x1.25″ inch

2x 110v extension cord to cut up $1.99 each at Home Depot

1x small SPST on/off switch

Step 2: Edit the HomeBridge /var/homebridge/config.json file on the Raspberry Pi HomeBridge

the file may alternatively be in /home/.homebridge or /root/home/./homebridge. read the docs from the github link

https://github.com/nfarina/homebridge

Ensure this plugin is installed. It may be installed by default in the newer versions:

https://www.npmjs.com/package/homebridge-http

Program the ESP8266. Upon powering up (3.3v do not use 5V!) it should be seen on the network.

Try something like http://192.168.1.110/gpio/1 . You should get a webpage returned.

Assuming your ESP8266 pulls a DHCP ip of :192.168.1.110

(you should probably set a DHCP reservation on your router, for each ESP8266 you add)

add this code to the config.json file. ( sudo nano /var/homebridge/config.json) etc:

mind the last comma, you may or may not need it if you have other accessories, or Homebridge is crashing on load.

{ “accessory”: “Http”,
“name”: “PowerTail”,
“on_url”: “http://192.168.1.110/gpio/1”,
“off_url”: “http://192.168.1.110/gpio/0”,
“http_method”: “GET”
},

Step 3: ESP8266 Arduino Code

/* * This sketch demonstrates how to set up a simple HTTP-like server.
* The server will set a GPIO pin depending on the request
* http://server_ip/gpio/0 will set the GPIO0 low,
* http://server_ip/gpio/1 will set the GPIO0 high
* server_ip is the IP address of the ESP8266 module, will be
* printed to Serial when the module is connected.
*/

#include

const char* ssid = "EDITMEWITHYOURWIFISSIDNAME";
const char* password = "EDITMEWITHYOURWIFIPASSWORD";

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {
Serial.begin(115200);
delay(10);
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
// prepare GPIO0
pinMode(0, OUTPUT);
digitalWrite(0, 0);

// Connect to WiFi network
//Serial.println();
//Serial.println();
//Serial.print("Connecting to ");
//Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
//Serial.print(".");
}
//Serial.println("");
//Serial.println("WiFi connected");

// Start the server
server.begin();
//Serial.println("Server started");

// Print the IP address
//Serial.println(WiFi.localIP());
}

void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}

// Wait until the client sends some data
//Serial.println("new client");
while(!client.available()){
delay(1);
}

// Read the first line of the request
String req = client.readStringUntil('\r');
//Serial.println(req);
client.flush();

// Match the request
int val;
if (req.indexOf("/gpio/0") != -1)
val = 0;
else if (req.indexOf("/gpio/1") != -1)
val = 1;
else {
//Serial.println("invalid request");
client.stop();
return;
}

// Set GPIO0 according to the request
digitalWrite(0, val);
digitalWrite(LED_BUILTIN, val); // Turn the LED on (Note that LOW is the voltage level
client.flush();

// Prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n
\r\nGPIO is now ";
s += (val)?"high":"low";
s += "

\n";

// Send the response to the client
client.print(s);
delay(10);
//Serial.println("Client disonnected");

// The client will actually be disconnected
// when the function returns and 'client' object is detroyed
}

Step 4: Test the new Accessory in iOS HomeKit App

Step 5: Don’t Electrocute Yourself.

https://lagunabeachcomputer.com/wp-content/uploads/2016/10/image1-150×150.png

https://lagunabeachcomputer.com/wp-content/uploads/2016/10/homekit_siri-150×150.png

http://52.27.64.85/wp-content/uploads/2016/10/pst_ii_rev_6a_oct_2013.bmp

https://lagunabeachcomputer.com/wp-content/uploads/2016/10/esp8266-reflash-firmware-150×150.png

https://lagunabeachcomputer.com/wp-content/uploads/2016/10/IMG_4286-150×150.jpg

https://lagunabeachcomputer.com/wp-content/uploads/2016/10/IMG_4283-150×150.jpg

Leave a Reply

Your email address will not be published. Required fields are marked *