Showing posts tagged with smartthings

in arduino, project, zigbee, smartthings, electronics

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.

in home automation, zigbee, zwave, smartthings

If you've known me for more than a few moments you'll know one of my favorite uses of tech is home automation. I believe one's home should work for them and that living in a smart home should be intuitative and...well, smart! I've recently decided to make my home a bit smarter with some gear from SmartThings.

My first foray into home automation was the Nest thermostat. There have been a few (at least one) revision of the Nest since I purchased mine, but I have to say its some incredibly simple, intuitive tech. Set it like you normally would and it eventually learns what you want and just does it. The web / smart phone app is also great for the lazy (see: me) who don't want to have to get up to change the temperature. I eventually purchased a Nest protect as well - while not as feature rich (I mean, its a smoke detector, what can it really do?) as the thermostat, I still think its a great addition to my "smart home".

I recently decided to expand beyond the Nest ecosystem and purchased a SmartThings hub. The SmartThings hub the Zigbee and Z-Wave protocols to connect with a wide range of sensors, locks, lights and other cool stuff. I made use of the Zigbee protocol in my weather station, it worked flawlessly so I was eager to use it for something more.

Overall, I'm very impressed with the SmartThings hub - its simple and gets out of the way when it needs to, but offers some pretty great features when you want them. I purchased a Ecolink door sensor along with my SmartThings hub - I wanted to use it to monitor the front door of my home. The setup was a little painful, I suspect this is because this was a third party product and not a SmartThings...thing, but with the help of the great SmartThings community I had the sensor all connected and mounted on the door in no time.

Once the sensor is connected, you do everything else through the app for your smartphone. You can set up a wide array of rules and conditions to receive notifications and do things with other smart things. For example - the SmartThings hub uses your smartphone as a presence detector by default (it uses it to determine if you are present), with that information you can then say "Turn on the lights when I get home and it is after sunset". If you also added a lock, you could say "Unlock the door when I get home and turn on the lights if its after sunset". You can purchase other presence sensors for other members of your household, so you can change things up depending on who is arriving or departing.

These features are great, but they are not what sold me on this particular ecosystem - it was SmartThings decided use of standards for interoperability as well as their fairly extensive development platform.

SmartThings is currently employing Zigbee and Z-Wave interoperability standards, meaning that any other compliant device should work with the platform as well. You don't have to buy SmartThings things exclusively - in fact, it feels like they encourage you to shop around. This is great for us as consumers because we can probably find lower prices elsewhere, but also great for the smart home industry - we don't need closed ecosystems, we need platforms that are compliant with standards so things can work with eachother. Selling somebody a closed platform is difficult, but selling somebody a platform that is standards compliant and open should be a no brainer.

Beyond the open platform, SmartThings also has a nice open development platform so you can do neat things with the triggers and data your sensors record. I haven't had a ton of time to experiment with this, but I did get a taste in researching how I could connect the aforementioned Nest and Nest Protect to my hub - it involved a defining a custom device, but the community had already figured all of this out long before I purchased my hub so I just had to copy and paste.

I'm super excited for the future of home automation - I think it is an excellent use of technology that will really make things look very futuristic very quick. The implications of having a home that reacts to your needs and desires is a revolution - I can't wait!