The holiday season is upon us again and what better way to celebrate than with an excessive amount of blinking lights? Originally, I set out to build an 8 channel Christmas light controller, but it would need to go on the roof, and climbing on the roof to manage it would be both inconvenient and dangerous. Inspired by Acumen Solutions’ Bartendro, a Salesforce-powered drink machine I saw at Dreamforce ‘13, I thought to leverage the world’s most powerful platform, Salesforce, to create Connected Christmas Lights that can be easily managed from anywhere in the world.

The Internet of Things continues to grow!

Using an Arduino Yun, a SainSmart 8-Channel Relay Module, a number of outlets, and some 14 gauge wire, I managed to build a contraption worthy of the most festive occasions. I was able to create an Arduino Sketch for the Yun to control the relays as well as handle incoming REST web service requests (see the sample code).

First I configured my web service endpoint in Salesforce under Remote Site Settings. Then I created a custom object. Next I developed a basic Apex class to handle the outbound web service calls to the Arduino.

Now when I change the picklist value on my object, an Apex trigger (see below) is invoked which executes the callout method. I added timer functionality and a scheduled job to process light control actions at specified times so that my lights turn on and off on a schedule. I created an email service to allow me to turn the lights on, off, and to flash mode via email.

And the best part about this, when I’m away from my house, I can control my lights using Salesforce1 on my mobile device. To make this happen, I leveraged Chatter Publisher Actions.

Apex Trigger

trigger MerryChristmasTrigger on Christmas_Light__c (before insert, before update) { //This is demo code. It will not handle for than 10 records. // Always callout on new records if (trigger.isInsert){ for (Christmas_Light__c c : trigger.new) { ChristmasLights.doCallout(c.Action__c); } } // Call out if the Action__c field has changed if (trigger.isUpdate) { for (Christmas_Light__c c : trigger.new) { if (c.Action__c != System.Trigger.oldMap.get(c.Id).Action__c) { ChristmasLights.doCallout(c.Action__c); } } } } public class MerryChristmasUtil { @Future(callout=true) public static void doCallout(string action){ string URL = 'http://myIPAddress/arduino/' + action + '/go'; Http h = new Http(); HttpRequest req = new HttpRequest(); req.setTimeout(30000); req.setEndpoint(url); req.setMethod('GET'); h.send(req); } }

In the Age of information, we believe this is just a glimpse into the possibilities that the “Internet of things” can provide. More of our things are becoming connected, allowing us to control them from virtually anywhere, even Marc Benioff’s toothbrush. Christmas lights are just a fun example–the possibilities are limited only by your creativity.

At Internet Creations we’re thrilled to be able to help businesses leverage Salesforce1 to interconnect their products, services, and customers like they never thought possible.