Mitch K
Published © CC BY-NC

Hack a GE Smart Outlet

I bought a GE smart outlet because it was on sale @Lowes really cheap. Well their app stinks and its not HomeKit compatible. I fixed that!

IntermediateFull instructions provided6 hours1,032
Hack a GE Smart Outlet

Things used in this project

Hardware components

Espressif ESP8285
×1
GE Smart Outlet model MTS5400
×1

Software apps and online services

Blynk
Blynk

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires
Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires
Screwdriver - TA triangular drive bit

Story

Read more

Schematics

Pins

Code

smartOutlet

Arduino
Program for the ESP8285
#include <Arduino.h> // to make platformio happy

// for BLynk
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h> 
#include <TimeLib.h>
#include <WidgetRTC.h>

//for OTA
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>


WidgetRTC rtc;

//define out pins
const byte relayPin = 13;
const byte relayLED = 14;
const byte pushButtonPin = 4;
const byte on = 1;
const byte off = 0;

// Blynk variables - enter yours here:
char auth[] = "auth token here";
char ssid[] = "wifi here";
char pass[] = "wifi pass";

// for my static IP - comment out if using public server
IPAddress myIP(10, 32, 1, 218);
IPAddress router(10, 32, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress dns1(10, 32, 1, 1);
IPAddress dns2(8, 8, 8, 8);

// time variables
byte hourTime2 = 0;
byte onTimeHour = 0;
byte onTimeMin = 0;
byte onTimeSec = 0;
byte offTimeHour = 0;
byte offTimeMin = 0;
byte offTimeSec = 0;

byte relayState = 0;
byte override = 0;

// timer variables
unsigned long timer1 = 0;
unsigned long timer2 = 0;
unsigned long clockDelay = 20000;

void setup()
{
  pinMode(relayPin, OUTPUT);
  pinMode(relayLED, OUTPUT);
  pinMode(pushButtonPin, INPUT_PULLUP); //pullup, grounds when pressed

//Customize its name on your network
  WiFi.hostname("ESP-GEswitch1");
  ArduinoOTA.setHostname("ESP-GEswitch1");

// connect to wifi with specified above settings, comment out to use public server:
  WiFi.config(myIP, router, subnet, dns1, dns2);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  while (WiFi.waitForConnectResult() != WL_CONNECTED)
  {
    delay(100);
  }
  Blynk.config(auth, IPAddress(10, 32, 1, 1), 8080);
/// end of comment out

//uncomment this to use public
//Blynk.begin(auth, ssid, pass);

  ArduinoOTA.begin(); // start over tha air service
}


void loop()
{
  Blynk.run(); // needs to run in loop
  ArduinoOTA.handle(); // needs to run in loop to catch command
  
  checkPushButton();  // evaluate if our button is pushed or not
  clockTimers();  // manage the on/off time

  if (millis() - timer1 > 60000)  // runs every 60 sec
  {
    signalStrenght(); // get wifi signal
    timer1 = millis();
  }
}

//////////////////////////////////////////////

void relayControl(byte action) //function to controll relay and LED
{
  if (action)
  {
    digitalWrite(relayPin, HIGH);
    digitalWrite(relayLED, HIGH);
  }
  else
  {
    digitalWrite(relayPin, LOW);
    digitalWrite(relayLED, LOW);
  }
  
  relayState = action;  //update the state of the relay
}

//////////////////////////////////////////////

void checkPushButton()
{
  if (!digitalRead(pushButtonPin)) 
  {
    delay(200);

    if (!digitalRead(pushButtonPin)) //used for debounce
    {
      if (relayState) //if on turn off & vise versa
      {
        relayControl(off);  
        Blynk.virtualWrite(V0, off); //synces Blynk on/off button
      }
      else
      {
        relayControl(on);
        Blynk.virtualWrite(V0, on); //synces Blynk on/off button
      }
    }
  }
}
//////////////////////////////////////////////

void clockTimers()
{
  if (!override)  //check if override is on
  {
    if (hour() == onTimeHour && minute() == onTimeMin && second() == onTimeSec) //checks if on timer is now
    {
      relayControl(on);
      Blynk.virtualWrite(V0, on); // synces Blynk on/off button
    }

    if (hour() == offTimeHour && minute() == offTimeMin && second() == offTimeSec) //checks if off timer is now
    {
      relayControl(off);
      Blynk.virtualWrite(V0, off); //synces Blynk on/off button
    }

    if (millis() - timer2 > clockDelay) //updates V6(time) every 20 sec
    {
      if (hour() > 12) //used for 12hr formatting
      {
        hourTime2 = hour() - 12;
      }
      else
      {
        hourTime2 = hour();
      }

      if (minute() < 10)//again, for time formatting
      {
        String currentTime = String(hourTime2) + ":" + "0" + minute();
        Blynk.virtualWrite(V6, currentTime);
      }
      else
      {
        String currentTime = String(hourTime2) + ":" + minute();
        Blynk.virtualWrite(V6, currentTime);
      }
      timer2 = millis(); //update timer
    }
  }
}

///////////////////////////////////////////////

void signalStrenght() //get the RSSI
{
  int cumRssi = 0; //initialize locally, we don't need them anywhere else
  int rssi = 0;

  for (byte i = 0; i < 3; i++) //get rssi average
  {
    rssi = wifi_station_get_rssi(); //get rssi
    cumRssi += rssi;
    delay(10);
  }

  rssi = cumRssi / 3;
  Blynk.virtualWrite(V31, rssi); //update app (signal)
}

//////////////////////////////////////////////

BLYNK_CONNECTED() //runs whenever hardware connects to server
{
  Blynk.syncAll(); //restores on/off to last state
  rtc.begin(); //starts the time
}

//////////////////////////////////////////////

BLYNK_WRITE(V0) // our on/off button
{
  int button = param.asInt();
  relayControl(button);
}

BLYNK_WRITE(V21) // our override button
{
  override = param.asInt();
}

BLYNK_WRITE(V20) // get on/off time
{
  TimeInputParam t(param);

  onTimeHour = t.getStartHour();
  onTimeMin = t.getStartMinute();
  onTimeSec = t.getStartSecond();

  offTimeHour = t.getStopHour();
  offTimeMin = t.getStopMinute();
  offTimeSec = t.getStopSecond();
}

BLYNK_WRITE(V30) // restart chip
{
  byte reset = param.asInt();

  if (reset)
  {
    ESP.restart();
  }
}

Homebridge Config

JSON
A example for integrating Blynk into home bridge to provide HomeKit service
    "platforms": [
        {
            "platform": "BlynkPlatform",
            "serverurl": "http://blynk-cloud.com",
            "pollerseconds": 1,
            "devices": [
                {
                    "name": "GE Smart Switch",
                    "token": "your project token here",
                    "deviceId": 111,
                    "manufacturer": "kirtch2020",
                    "accessories": [
                        {
                        "model": "Switch",
                        "name": "Aquarium Light",
                        "pintype": "VIRTUAL",
                        "pinnumber": 0,
                        "type": "BUTTON"
                        }
                    ]
                }
            ]
        }

Credits

Mitch K

Mitch K

6 projects • 22 followers
Maker, designer, & all around fun to be around!
Thanks to GE.

Comments

Add projectSign up / Login