Now that the SmartThings lab has released support for both Sonos wireless speakers and Hue lighting, I decided to build a custom switch using the SmartThings Arduino shield to interact with the system. The goal was to provide physical control over the systems without using a phone or tablet.
In my case, I wanted to be able to quickly:
- Pause/Play all speakers in my house
- Skip the current song
- Turn groups of lights on and off
- Dim the lights (not yet implemented)
The hardware uses a reclaimed project box from the last century with an Arduino UNO and SmartThings shield inside. It includes two pushbuttons, three switches and a knob.
With the hardware put together, the next step was to create a custom Device Handler for the SmartThings cloud and write the SmartApp.
The Device Handler essentially creates a virtual version of the device. It identifies each button and switch in the hardware to provide the basic inputs and outputs used by my SmartApp. The Device Handler also defines the device’s UI that is presented within the SmartThings mobile app.
The SmartApp determines what happens when someone interacts with the hardware. For example, I define which switches will turn things on and off and which ones will call play and pause. The App also defines the UI used to configure the app and map specific switches to specific Sonos and Hue hardware.
Documentation for writing handlers is lacking and this required a good deal of trial and error. In fact, I have not yet been able to hook up the knob within the handler. Once I do, I will post the bits on Github; but, for now if you want to work on something similar, I found this Arduino Code and corresponding Handler Code quite useful.
Another other bit of documentation that came in handy for how to control the Hue and Sonos devices is this list of device types and capabilities.