-
-
Save danlieberman/5845fd624eff26f917ab to your computer and use it in GitHub Desktop.
SmartThings Status Board Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Status Board Service | |
*/ | |
preferences { | |
section("Allow application to report on these things...") { | |
input "temperatureSensors", "capability.temperatureMeasurement", title: "Which Temperature Sensors?", multiple: true, required: false | |
} | |
} | |
mappings { | |
path( "/jsonTest" ) { | |
action: [ | |
GET: "jsonOutputTest" | |
] | |
} | |
} | |
def installed() { | |
log.debug settings | |
} | |
def updated() { | |
log.debug settings | |
} | |
def jsonOutputTest() { | |
def dataSequenceList = []; | |
settings["temperatureSensors"]?.collect { | |
def dataPoints = [] | |
def myEvents = it.events(max: 30) | |
/*def myEventsSorted = myEvents.sort() { d -> | |
[ 'h:mm a', 'H:mm' ].findResult { fmt -> | |
try { | |
Date.parse( fmt, d ).time | |
} catch( e ) {} | |
} | |
}*/ | |
def myEventsReverse = myEvents.reverse() | |
myEventsReverse.collect { eventItem -> | |
if ( eventItem.value != "active" && eventItem.value != "inactive" ) { | |
//def myTime = eventItem.date.format( "HH:mm:ss" ) | |
def myCalendar = Calendar.getInstance( location.timeZone ) | |
myCalendar.setTimeInMillis( eventItem.date.time ) | |
dataPoints.add( [title: myCalendar.format( "HH:mm:ss"), value: eventItem.value ] ) | |
} | |
} | |
def dataSequence = [ title: it.displayName, datapoints: dataPoints ] | |
dataSequenceList.add( dataSequence ) | |
} | |
def graphObject = [ | |
graph: [ | |
title: "SmartThings Temperature Sensors", | |
type: "line", | |
refreshEveryNSeconds : 150, | |
yAxis: [minValue: 50, maxValue: 80], | |
datasequences: dataSequenceList | |
] | |
] | |
return graphObject | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment