Source code for built-in device types?

Anywhere that we can access the SMART code for the built-in device types? I tried to derive a new device type (I named it FluxCapacitor) from the Arduino On/Off (Example) device type, using the source that was linked to in the documentation, but it doesn’t work properly (the on/off functions work, but the “hello” function does not). Whereas if I choose the device type Arduino On/Off (Example) from the list of predefined types, it works. I suspect the code is different between the two, but I have no way of knowing/seeing what the code for the built-in one looks like.

1 Like

Device type code documentation is being written right now. I know we’re behind on that :s but its coming! As for your own code, when in the code editor, hit “Device Type Settings” on the upper right of the edit box. Then click “switch” and hit add custom attribute “greeting” and custom commands “hello” and “goodbye” should look like this:

http://imgur.com/SkVc6Lw

Also, if there is any specific device type code you would like to see let me know and I’ll post it.

Thanks, Andrew - fully understand that it’s early on. Documentation is always tricky when you’re busy innovating! Been there…

Can you give me some quick insights as to two other aspects of device types and related code?

  1. What is the purpose and function of the Map parse(String description) function, and can you explain what’s going on in there in the Arduino example?

  2. What does the syntax ${name} do in the label field for a tile state?

  3. From the Arduino perspective, we’ll likely be polling some sensors & I/O, and wanted to know how to make their status/values available to SmartApps and in the device type default view. Are they attributes? If so, how are they pushed/assigned?

Appreciate the help!

Rick

Hi Rick,

Thanks for bearing with us on the documentation. It is coming.

The parse function is responsible for converting raw messages from the hub (Zigbee or Z-Wave) into events for consumption by the rest of the system. Events are what drive smart apps and the display of device data in the mobile apps. The name of the event dictates the attribute name used to store the value and make it available for display and use by SmartApps. Here’s an annotated version of the Arduino On/Off example that should answer some of your questions:

// The description argument is a string that, for Arduino shields, takes the form:
//
// "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E"
//
// Only the last two bites of that is data. The first part you don't need to worry about
//
def parse(String description) {

    // zigbee.parse() is a utility for handling Zigbe catchall messages like those from the shield
    // if the above catchall message came in as the description, zigbee.parse("description").text
    // would return "on" for the value.
    //
    def value = zigbee.parse(description)?.text

    // This line is setting the attribute name of the event to <code>switch</code> if the value is either <code>on</code> or <code>off</code>. The name
    // of the event determines the attribute name used to store the value.
    //
    def name = value in ["on","off"] ? "switch" : null

    // this line invokes a helper method to create the full event property map. If the name is switch and the
    // value is on then the map (in JSON format) would be:
    //
    // {name:"switch", value:"on", isStateChange:true, displayed:true, linkText:"DeviceName", descriptionText:"DeviceName switch is on"]
    //
    // The descriptionText is what appears in the feed on the mobile apps. If you want something other than the default value, you can
    // specify it in the map passed in to createEvent. The same is true for any of the other fields.
    //
    def result = createEvent(name: name, value: value)

    // return the event map
    return result
}

The ‘${name}’ label field directs the system to use the state name, “on” or “off” in this case, to display on the tile. You can also just put a string in here if you want the tile to display different text. Value tiles also accept a ‘${currentValue}’ entry. Make sure you use single rather than double quotes for these two cases, since the ${} syntax inside of double quotes has a different meaning in Groovy.

The event names determine which attributes are stored and available to SmartApps. You can use attribute names from any of the standard capabilities or you can create your own, custom attribute names. The Device Type Settings page (the one you see when you first create a new device type) is where you specify which capabilities and custom attributes and commands your device supports. This information tells the system what your device can do and allows it to be used by SmartApps.

For example, let’s say you were building an Arduino weather station project that measured temperature and barometric pressure. We have a standard temperature measurement capability but currently don’t have one for barometric pressure, so you would create a new device type and:

  1. Select the Temperature Measurement capability (which defines the attribute temperature)

  2. Add a custom barometricPressure attribute

  3. In the parse() method generate an event with the name temperature containing the temperature value and an event named barometricPressure containing the pressure value. You can create two events at once, if you want to, by returning a list of
    maps from the parse() method.

These values would then be persisted and available for display in device tiles and use by SmartApps. See the Aeon Multisensor sample code for examples of how to display values in a device tile.

Thanks, Bob! Very helpful. A further understanding events and how they interact with everything else would also be useful. Appreciate the feedback!

@bflorian:

Can you please provide the entire list of attributes and methods for the zigbee and zwave object types.

For example, the code sample uses “zigbee.parse()” …

def value = zigbee.parse(description)?.text

Thank-you!?
…CP.

Hey there! Sorry to bump this old topic- I’m currently interested in this and can’t seem to find it anywhere: has this documentation been written yet?

@urman. I have been trying to get some text sent from arduino to ST to print on a tile.
This Code do not show text coming from Arduino. However, there is a built in device type with name “on/off shield example” which show text on tile. Don’t know how to get that done. Ex. “buttonhello” example has a line item “smartthing.send(“fancy”);” with which can show “fancy” in a tile. Can you help get the code which has this functionality.

This is what I found from reading,

Code which go on ST Device : https://gist.github.com/aurman/6546221
Code which go on Sketch : https://gist.github.com/aurman/6862503