Skip to content

Instantly share code, notes, and snippets.

@tbeseda
Last active February 8, 2017 21:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tbeseda/802c609df007f25a77c5 to your computer and use it in GitHub Desktop.
Save tbeseda/802c609df007f25a77c5 to your computer and use it in GitHub Desktop.

Visualize data from a SmartThings sensor with Dweet and Freeboard

My SmartThings multisensor is a great little piece of technology. It reports, in real time, motion, temperature, and open/close state of my back door. The iOS app is slick, too, but I wanted a way to view it from my computer and have access to historical data.
Enter Dweet and Freeboard from Buglabs.

The SmartThings SmartApp and Dweet

There's actually no setup required on Dweet (but be sure to check out their nifty demo). It just starts eating data and making it available for use via HTTP/JSON!

To create a SmartApp you neeed to be a SmartThings developer (free and simple process). Then the app is built in the SmartThings web-based IDE, and installed directly to your SmartThings system.

  • Create a new SmartApp
  • Edit the code of your project and paste in the dweet.groovy file below
    • You can leave the license info and definition section at the top if you'd like
  • Click Save
  • Select your SmartThings hub location (i.e. "Home") in the right sidebar
  • Fill in your preferences
    • Select a physical device that has a temperature sensor
    • Enter any string you want to dweet as
  • Click Install

A simulator tile of that device should appear.
A developer console will pop up. Check for any red errors.
If there are no errors, your device should have dweeted! You can confirm by visiting http://dweet.io/follow/THE-NAME-YOU-CHOSE-EARLIER and see some JSON like:

{
  "contact": "closed",
  "degrees": 68,
  "unit": "F"
}

The device will continue to dweet when the temperature or contact change.

Freeboard.io

Let's add the dweeted data to a slick (free!) dashboard from Freeboard.io.
Set up a free account, and walk through the tutorial.
Now make a gauge for the sensor's temperature:

  • Add a Dweet datasource using the "Thing Name" your SmartThings sensor "dweets" as
  • Add a new pane to the Freeboard
  • Add a new widget to the new pane of type "Gauge"
  • Click "+ Datasource" and select your dweet source and its degrees attribute
    • Mine looks like this: datasources["Deck Door"].degrees
  • Save

You should see the current temperature of your sensor in the gauge.

TODO: Add set up for temp sparkline
TODO: Add set up for open/closed indicator light

Footnotes

This is based on @alexking's implementation.
I simply added a datapoint about the "contact" (open/close) attribute of the sensor.

If you're trying to graph values over time, it would be better to set up an interval in your SmartThings SmartApp rather than subscribing to changes in temperature as they may not come in regularly.

Dweets are public by default, so data about your sensor is public. Not a huge deal since you can easily lock them down.

A more adaptable approach may be to create a generic SmartApp that dweets a devices entire status. I'm working on this next.

License

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

/**
* Dweet
*
* This is free and unencumbered software released into the public domain.
* http://unlicense.org
*/
preferences {
section("When this thing changes ") {
input "item", "capability.temperatureMeasurement", title : "Temperature Sensors"
}
section("Dweet as...") {
input "handle", "text", title : "Enter a name to dweet from..."
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
// Subscribe for future dweeting
subscribe(item, "temperature", dweet)
subscribe(item, "contact", dweet)
dweet()
}
// Send the dweet
def dweet(evt) {
httpGet([
uri : "http://dweet.io/",
path : "dweet/for/" + handle,
query : [
"contact" : item.currentValue('contact'),
"degrees" : item.currentValue('temperature'),
"unit" : "F"
],
success: { response ->
log.debug "Request was successful, $response"
}
])
}
@jheising
Copy link

Thanks @tbeseda! Great writeup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment