Device Handler Documentation

I hope I am missing the documentation that explains how to create a new device handler. If anyone knows where it is, I’d sure appreciate a link.

To be honest, I mostly had to reverse-engineer it from the examples. What are you trying to make?

Here’s the basics as it relates to a custom-made device using a shield:

A device handler does two things: it interprets signals from the network and relays them to smartthings, and it takes commands from smartthings and relays them to the device. It’s simpler to start with a pure device -> handler -> smartapp style thing.

Your device handler will get a string, and begin this routine:

def parse(String description) { }

All of your code is in here: your goal is to convert whatever the device sent you into a type of event, and a value for that event.

First, you’ll probably want to turn that string into normal text (much easier to work with), if it’s zigbee, do this:
def value = zigbee.parse(description)?.text

For an example we’re going to use my device handler (because it’s the only one I have written):

My device would relay “signalcommand: [command]” through the zigbee network. The first half would tell me what the signal was , the second half was the signal itself. So the goal is to create a “signalcommand” event, with the value of [command].

You want to strip out the signal type like this:

if (value?.startsWith(“signalcommand: “)) {
def raw = value
raw = raw – “signalcommand: ”

Now, you’ve got a raw value (in my case, always colors but the handler works with anything), and you know it’s a “signalcommand” event. You next relay that to the smartthings cloud.

That’s done by:
result = createEvent(name: “signalcommand”,value: raw)
return result

This created a “signalcommand” event, with the value of raw (whatever command was passed by the device). So, if it sent signalcommand: red, the device handler would create a “signalcommand” event, with a value of “red”. So then, I write an app that listens for signalcommand events, and then does things with them.

Thanks for the intro! I hesitate to divulge my intentions, but here goes. I wanted to make a device type for the Nest thermostat. I’m sure others are messing around with this as well. I don’t expect this to be an acceptable solution to SmartThings or Nest, but I’d imagine Nest is going to complain to me before SmartThings does.

The device type would be completely virtual, so not quite sure if that is even possible. I was going to proxy events via a web service to and from Nest.

Do you know how metrics work? Like the temperature sensors, are they polled by the hub or do the smartsense multis and such just blast an update every so often? If they blast it, then the proxy service will need to be the heartbeat too.

I’m not trying to hijack my own thread, so when I get to playing with the device type again I’ll jabber here for what I discover or any other questions I have. Again, thank you for taking the time to jot down what you’ve discovered.

You won’t hear any complaints out of us. Our multi sensors report every so often with their temp and report when they are in motion. You wouldn’t have to emulate anything of ours to get it to work. There are all types of thermostats and devices, we don’t care who makes them :stuck_out_tongue:

Within the device type you can create your own tile and display on it whatever you would like. The real challenge is how you plan on getting info from the Nest.

Alright then, time to go see if Nest notices me :slight_smile: