Since I purchased my SmartThings hub a few months ago I've been all about adding new sensors, lights and other smart things to my apartment.

Most recently I have been experimenting with the GE Link Light Bulbs. Overall I love them, but the one thing I (and my fiancée) have found a bit annoying is having to use a smartphone to control them. For the most part, this isn't necessary as I have a number of rules to automatically turn on the lights when need be, but there is always the odd situation where I want to turn the lights on/off manually.

Thinking of a better way to turn on these lights the old fashioned way (without having to install Zigbee light switches, we rent) turned me on to this latest electronics project.

SmartThings has a pretty robust API and I've tinkered around with controlling the lights from a web browser. The process basically involves a simple GET request to a predefined URL with a token, the ID of the switch I want to manipulate and what I want to do.

This lead me to develop physical buttons that hook into an Arduino to send the GET request when I press a button:

SmartThings Button

The circuit its self is pretty simple, each button is wired into a 150 Ohm resistor to ground, the 5V rail, and a separate line to the Arduino inputs. The Arduino has an ethernet shield to communicate with the greater internet.

SmartThings Button 2

Each button controls a different light (I have three bulbs total currently), the red and green switches will eventually be used to turn all the lights on or off but this hasn't been implemented yet.

Code-wise I've made use of the Arduino ethernet library to handle all of the networking and the HTTP request directly:

#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>
#include <SPI.h>

int BUTTON_DESK_LOWER= 7;
int BUTTON_DESK_UPPER = 8;
int BUTTON_SLIDING = 9;

char server[] = "graph.api.smartthings.com";

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress ip(192,168,0,174);

EthernetClient client;

void setup()
{
  Serial.begin(9600);
   while (!Serial) {
    ;
  }
  
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    Ethernet.begin(mac, ip);
  }
 
  delay(1000);
  
  pinMode(BUTTON_DESK_LOWER,INPUT);
  pinMode(BUTTON_DESK_UPPER,INPUT);
  pinMode(BUTTON_SLIDING,INPUT);
}

void loop()
{
  if(digitalRead(BUTTON_DESK_LOWER) == HIGH)
  {
    if (client.connect(server, 80)) 
    {
      Serial.println("connected");
      client.println("GET /api/smartapps/installations/REPLACE HTTP/1.1");
      client.println("Host: graph.api.smartthings.com");
      client.println("User-Agent: Mozilla/5.0");
      client.println("Connection: close");
      client.println();
      
      delay(5000);
 
      client.stop();
     } 
    else 
    {
      Serial.println("connection failed");
    }
  }
  if(digitalRead(BUTTON_DESK_UPPER) == HIGH)
  {
    if (client.connect(server, 80)) 
    {
      Serial.println("connected");
      client.println("GET /api/smartapps/installations/REPLACE HTTP/1.1");
      client.println("Host: graph.api.smartthings.com");
      client.println("User-Agent: Mozilla/5.0");
      client.println("Connection: close");
      client.println();
      
      delay(5000);
 
      client.stop();
     } 
    else 
    {
      Serial.println("connection failed");
    }
  }
  if(digitalRead(BUTTON_SLIDING) == HIGH)
  {
    if (client.connect(server, 80)) 
    {
      Serial.println("connected");
      client.println("GET /api/smartapps/installations/REPLACE HTTP/1.1");
      client.println("Host: graph.api.smartthings.com");
      client.println("User-Agent: Mozilla/5.0");
      client.println("Connection: close");
      client.println();
      
      delay(5000);
 
      client.stop();
     } 
    else 
    {
      Serial.println("connection failed");
    }
  }
}

It is still a bit (see: extremely) rough around the edges but it works! I'm still working on making it look a bit better and finding a way to mount it in some sort of useful position.

If you are interested in reusing the code you are welcome to - just replace the REPLACE strings with the token, switch ID and action with your own and change the button inputs to the inputs you have chosen. The MAC address I used was the default one from the example code (my shield did not have a MAC on it) so you'll probably want to change that and the IP assignment depending on your environment. You can find the repository on Github.