This is a sample application to control LIFX WiFi Bulb using SmartThings. LIFX can only be controlled within local network, as of now we cannot control LIFX from outside the network. One solution to control from outside network is to use an intermediate local server which listens for commands and control the bulb locally. There an official LIFX Ruby SDK. There are also some unofficial node.js library which can control the LIFX bulb, on such library is Lifxjs.
To communicate to the local server from outside the network, we can use MQTT, Server Sent Events, etcâ€¦ For this demo I am using MQTT. Eclipse foundation is maintaining a Sandbox MQTT Server for development purpose. We can use MQTT clients to publish and subscribe messages, there is also one HTTP Bridge which provides RESTful APIs to send and receive messages. This is very useful service, we just need to call REST services and we can easily manage the messages. For this one I am using the REST APIs.
In this demo, I created a SmartThings Custom Device type LIFX with â€˜Switchâ€™ capability. Whenever the switch turns on the application calls the MQTT HTTP Bridge service and publishes a message with topic â€œlifxcmdâ€ and payload command=â€™1â€™ and when it turns off publish with payload command=â€™0â€™. The local node.js server listens for this topic and whenever it receives it turns the bulb on/off.
This is a pretty straight forward to control the bulb. Currently I only implemented on/off functionality but planning to incorporate more in near future.
Here is a demo video of the application in action (sorry, no audio). http://www.youtube.com/watch?v=5D6cQRWK3Yc
Happy LIFX and SmartThings coding 🙂