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

About: I'm a lot of things. Galen Wollenberg

HomeKit HomeBridge Siri Enabled Arduino ESP8266 Self Powered 110v Wifi Controlled Power switch

by Galen Wollenberg

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

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.



Step 1: Don't Electrocute Yourself.

Don't Electrocute Yourself.

Step 2: Install HomeBridge for HomeKit on a Raspberry Pi

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

Once installed, make sure you can see the Bridge from within the HomeKit app on your iOS device, before continuing.

Step 3: 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

Ensure these plugin are installed. It may be installed by default in the newer versions:

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

Try something like . You should get a webpage returned.

Assuming your ESP8266 pulls a DHCP ip of :

(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": "",
    "off_url": "",
    "http_method": "GET"

Step 4: 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 5: ESP8266 Arduino Code

<p>/*<br> *  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.
 */</p><p>#include </p><p>const char* ssid = "EDITMEWITHYOURWIFISSIDNAME";
const char* password = "EDITMEWITHYOURWIFIPASSWORD";</p><p>// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);</p><p>void setup() {
  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.print("Connecting to ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  //Serial.println("WiFi connected");
  // Start the server
  //Serial.println("Server started");</p><p>  // Print the IP address
}</p><p>void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
  // Wait until the client sends some data
  //Serial.println("new client");
  // Read the first line of the request
  String req = client.readStringUntil('\r');
  // 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");
  }</p><p>  // 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();</p><p>  // 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 += "</p><p>\n";</p><p>  // Send the response to the client
  //Serial.println("Client disonnected");</p><p>  // The client will actually be disconnected 
  // when the function returns and 'client' object is detroyed

Step 6: Test the New Accessory in IOS HomeKit App

Test the new Accessory in iOS HomeKit App and Siri

Check out my Light Sensor plugin for HomeBridge / HomeKit !

IoT Builders Contest

Participated in the
IoT Builders Contest

Circuits Contest 2016

Participated in the
Circuits Contest 2016