Compare commits

..

23 Commits

Author SHA1 Message Date
Bill Venhaus
1241802315 Modifying 'Home Remote' 2015-10-11 22:38:58 -05:00
Bill Venhaus
0414ae0460 Modifying 'Home Remote' 2015-10-11 22:38:02 -05:00
Bill Venhaus
67006204da Modifying 'Home Remote' 2015-10-11 13:33:03 -05:00
Bill Venhaus
32e3916a85 Modifying 'Home Remote' 2015-10-04 21:53:55 -05:00
Bill Venhaus
dc1071d132 Modifying 'Home Remote' 2015-10-04 21:29:28 -05:00
Bill Venhaus
94f8b4ecfc MSA-599: Web service that to enables communication between the Home Remote app and a SmartThings hub. 2015-10-02 17:53:27 -05:00
bflorian
239f771ac1 Merge pull request #163 from SmartThingsCommunity/hue-mac-check
Handle incorrect mac address reporting
2015-10-02 07:19:52 -07:00
adam
87b6715a00 Handle incorrect mac address reporting 2015-10-02 09:07:06 -05:00
Juan Pablo Risso
d6a96317bf Merge pull request #155 from juano2310/R_hue_bulbs
Hue - Fix bulb discovery
2015-10-01 11:00:46 -04:00
Vinay Rao
6d64212c93 Merge pull request #160 from workingmonk/ge_link_level_fix
AppEngine issue with state syncing handled here.
2015-09-30 15:03:11 -07:00
Vinay Rao
088e746f99 AppEngine issue with state syncing handled here. 2015-09-30 15:00:17 -07:00
Kris Schaller
c26701383e Removing weatherbug first submission because namespace issue 2015-09-30 14:35:29 -07:00
SmartThings, Inc.
0b8f1d0168 Merge pull request #159 from SmartThingsCommunity/MSA-594-2
Merged publication request 'Weather Bug Submission v2'
2015-09-30 16:34:06 -05:00
Kris Schaller
b78337c96b MSA-594: New submission to fix namespace 2015-09-30 16:33:03 -05:00
SmartThings, Inc.
9fcd327da2 Merge pull request #156 from SmartThingsCommunity/MSA-592-1
Merged publication request 'WeatherBug Home Connect'
2015-09-30 16:03:12 -05:00
Edward Dingels
c3ce69994e Modifying 'WeatherBug Home Connect' 2015-09-30 15:07:27 -05:00
Warodom Khamphanchai
5bd03d1914 Merge pull request #143 from kwarodom/zwaveWaterValve
Z-Wave Water Valve: initial device type
2015-09-30 10:51:13 -07:00
Matthew Nohr
950780d30c Merge pull request #153 from mrnohr/crex3460-educational-content-updates
CREX-3460 Update educational DGSE content with new assets
2015-09-29 19:51:45 -05:00
Warodom Khamphanchai
8040ddd6f7 Z-Wave Water Valve: remove fingerprint from fortrezz, automatic refresh when join, remove manufacturerSpecificGet from poll() 2015-09-29 16:21:08 -07:00
Edward Dingels
4863b2345e MSA-592: Allows users to share their thermostat data with WeatherBug. Provides home energy and weather analytics. 2015-09-29 16:45:21 -05:00
Juan Pablo Risso
32b4914ba0 Hue - Fix bulb discovery 2015-09-29 17:16:55 -04:00
Matt Nohr
c76a2e807b CREX-3460 Update educational DGSE content with new assets 2015-09-29 09:46:32 -05:00
Warodom Khamphanchai
617d53da43 Z-Wave Water Valve: initial device type 2015-09-28 14:54:42 -07:00
11 changed files with 1187 additions and 223 deletions

View File

@@ -34,8 +34,8 @@ metadata {
preferences {
section {
image(name: 'educationalcontent', multiple: true, images: [
"http://cdn.device-gse.smartthings.com/Arrival/Arrival1.png",
"http://cdn.device-gse.smartthings.com/Arrival/Arrival2.png"
"http://cdn.device-gse.smartthings.com/Arrival/Arrival1.jpg",
"http://cdn.device-gse.smartthings.com/Arrival/Arrival2.jpg"
])
}
}

View File

@@ -19,7 +19,6 @@ metadata {
capability "Sensor"
fingerprint deviceId: "0x1000", inClusters: "0x25,0x72,0x86,0x71,0x22,0x70"
fingerprint deviceId: "0x1006", inClusters: "0x25"
}
// simulator metadata

View File

@@ -317,7 +317,7 @@ def setLevel(value) {
state.trigger = "setLevel"
state.lvl = "${level}"
if (dimRate) {
if (dimRate && (state?.rate != null)) {
cmds << "st cmd 0x${device.deviceNetworkId} 1 8 4 {${level} ${state.rate}}"
}
else {

View File

@@ -48,8 +48,8 @@ metadata {
preferences {
section {
image(name: 'educationalcontent', multiple: true, images: [
"http://cdn.device-gse.smartthings.com/Outlet/US/OutletUS1.png",
"http://cdn.device-gse.smartthings.com/Outlet/US/OutletUS2.png"
"http://cdn.device-gse.smartthings.com/Outlet/US/OutletUS1.jpg",
"http://cdn.device-gse.smartthings.com/Outlet/US/OutletUS2.jpg"
])
}
}

View File

@@ -39,9 +39,9 @@ metadata {
preferences {
section {
image(name: 'educationalcontent', multiple: true, images: [
"http://cdn.device-gse.smartthings.com/Motion/Motion1.png",
"http://cdn.device-gse.smartthings.com/Motion/Motion2.png",
"http://cdn.device-gse.smartthings.com/Motion/Motion3.png"
"http://cdn.device-gse.smartthings.com/Motion/Motion1.jpg",
"http://cdn.device-gse.smartthings.com/Motion/Motion2.jpg",
"http://cdn.device-gse.smartthings.com/Motion/Motion3.jpg"
])
}
section {

View File

@@ -54,10 +54,10 @@
preferences {
section {
image(name: 'educationalcontent', multiple: true, images: [
"http://cdn.device-gse.smartthings.com/Multi/Multi1.png",
"http://cdn.device-gse.smartthings.com/Multi/Multi2.png",
"http://cdn.device-gse.smartthings.com/Multi/Multi3.png",
"http://cdn.device-gse.smartthings.com/Multi/Multi4.png"
"http://cdn.device-gse.smartthings.com/Multi/Multi1.jpg",
"http://cdn.device-gse.smartthings.com/Multi/Multi2.jpg",
"http://cdn.device-gse.smartthings.com/Multi/Multi3.jpg",
"http://cdn.device-gse.smartthings.com/Multi/Multi4.jpg"
])
}
section {

View File

@@ -0,0 +1,124 @@
/**
* Copyright 2015 SmartThings
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
metadata {
definition (name: "Z-Wave Water Valve", namespace: "smartthings", author: "SmartThings") {
capability "Actuator"
capability "Valve"
capability "Polling"
capability "Refresh"
capability "Sensor"
fingerprint deviceId: "0x1006", inClusters: "0x25"
}
// simulator metadata
simulator {
status "open": "command: 2503, payload: FF"
status "close": "command: 2503, payload: 00"
// reply messages
reply "2001FF,delay 100,2502": "command: 2503, payload: FF"
reply "200100,delay 100,2502": "command: 2503, payload: 00"
}
// tile definitions
tiles(scale: 2) {
multiAttributeTile(name:"valve", type: "generic", width: 6, height: 4, canChangeIcon: true){
tileAttribute ("device.contact", key: "PRIMARY_CONTROL") {
attributeState "open", label: '${name}', action: "valve.close", icon: "st.valves.water.open", backgroundColor: "#53a7c0", nextState:"closing"
attributeState "closed", label: '${name}', action: "valve.open", icon: "st.valves.water.closed", backgroundColor: "#e86d13", nextState:"opening"
attributeState "opening", label: '${name}', action: "valve.close", icon: "st.valves.water.open", backgroundColor: "#ffe71e"
attributeState "closing", label: '${name}', action: "valve.open", icon: "st.valves.water.closed", backgroundColor: "#ffe71e"
}
}
standardTile("refresh", "device.contact", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
main "valve"
details(["valve","refresh"])
}
}
def updated() {
response(refresh())
}
def parse(String description) {
log.trace "parse description : $description"
def result = null
def cmd = zwave.parse(description, [0x20: 1])
if (cmd) {
result = createEvent(zwaveEvent(cmd))
}
log.debug "Parse returned ${result?.descriptionText}"
return result
}
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
def value = cmd.value == 0xFF ? "open" : cmd.value == 0x00 ? "closed" : "unknown"
[name: "contact", value: value, descriptionText: "$device.displayName valve is $value"]
}
def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) { //TODO should show MSR when device is discovered
log.debug "manufacturerId: ${cmd.manufacturerId}"
log.debug "manufacturerName: ${cmd.manufacturerName}"
log.debug "productId: ${cmd.productId}"
log.debug "productTypeId: ${cmd.productTypeId}"
def msr = String.format("%04X-%04X-%04X", cmd.manufacturerId, cmd.productTypeId, cmd.productId)
updateDataValue("MSR", msr)
[descriptionText: "$device.displayName MSR: $msr", isStateChange: false]
}
def zwaveEvent(physicalgraph.zwave.commands.deviceresetlocallyv1.DeviceResetLocallyNotification cmd) {
[descriptionText: cmd.toString(), isStateChange: true, displayed: true]
}
def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
def value = cmd.value == 0xFF ? "open" : cmd.value == 0x00 ? "closed" : "unknown"
[name: "contact", value: value, descriptionText: "$device.displayName valve is $value"]
}
def zwaveEvent(physicalgraph.zwave.Command cmd) {
[:] // Handles all Z-Wave commands we aren't interested in
}
def open() {
delayBetween([
zwave.basicV1.basicSet(value: 0xFF).format(),
zwave.switchBinaryV1.switchBinaryGet().format()
],10000) //wait for a water valve to be completely opened
}
def close() {
delayBetween([
zwave.basicV1.basicSet(value: 0x00).format(),
zwave.switchBinaryV1.switchBinaryGet().format()
],10000) //wait for a water valve to be completely closed
}
def poll() {
zwave.switchBinaryV1.switchBinaryGet().format()
}
def refresh() {
log.debug "refresh() is called"
def commands = [zwave.switchBinaryV1.switchBinaryGet().format()]
if (getDataValue("MSR") == null) {
commands << zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
}
delayBetween(commands,100)
}

View File

@@ -1,194 +0,0 @@
/**
* Hello Home Cube
*
* Copyright 2015 skp19
*
*
*/
/************
* Metadata *
************/
definition(
name: "Hello Home Cube",
namespace: "skp19",
author: "skp19",
description: "Run a Hello Home action by rotating a cube containing a SmartSense Multi",
category: "SmartThings Labs",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/App-LightUpMyWorld.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/App-LightUpMyWorld@2x.png"
)
import groovy.json.JsonSlurper
/**********
* Setup *
**********/
preferences {
page(name: "mainPage", title: "", nextPage: "scenesPage", uninstall: true) {
section("Use the orientation of this cube") {
input "cube", "capability.threeAxis", required: false, title: "SmartSense Multi sensor"
}
section([title: " ", mobileOnly:true]) {
label title: "Assign a name", required: false
mode title: "Set for specific mode(s)", required: false
}
}
page(name: "scenesPage", title: "Scenes", install: true, uninstall: true)
}
def scenesPage() {
log.debug "scenesPage()"
def sceneId = getOrientation()
dynamicPage(name:"scenesPage") {
def phrases = location.helloHome?.getPhrases()*.label
section {
phrases.sort()
input name: "homeAction1", type: "enum", title: "${1}. ${sceneName(1)}${sceneId==1 ? ' (current)' : ''}", required: false, options: phrases
input name: "homeAction2", type: "enum", title: "${2}. ${sceneName(2)}${sceneId==2 ? ' (current)' : ''}", required: false, options: phrases
input name: "homeAction3", type: "enum", title: "${3}. ${sceneName(3)}${sceneId==3 ? ' (current)' : ''}", required: false, options: phrases
input name: "homeAction4", type: "enum", title: "${4}. ${sceneName(4)}${sceneId==4 ? ' (current)' : ''}", required: false, options: phrases
input name: "homeAction5", type: "enum", title: "${5}. ${sceneName(5)}${sceneId==5 ? ' (current)' : ''}", required: false, options: phrases
input name: "homeAction6", type: "enum", title: "${6}. ${sceneName(6)}${sceneId==6 ? ' (current)' : ''}", required: false, options: phrases
}
section {
href "scenesPage", title: "Refresh", description: ""
}
}
}
/*************************
* Installation & update *
*************************/
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
subscribe cube, "threeAxis", positionHandler
}
/******************
* Event handlers *
******************/
def positionHandler(evt) {
def sceneId = getOrientation(evt.xyzValue)
log.trace "orientation: $sceneId"
if (sceneId != state.lastActiveSceneId) {
runHomeAction(sceneId)
}
else {
log.trace "No status change"
}
state.lastActiveSceneId = sceneId
}
/******************
* Helper methods *
******************/
private Boolean sceneIsDefined(sceneId) {
def tgt = "onoff_${sceneId}".toString()
settings.find{it.key.startsWith(tgt)} != null
}
private updateSetting(name, value) {
app.updateSetting(name, value)
settings[name] = value
}
private runHomeAction(sceneId) {
log.trace "runHomeAction($sceneId)"
//RUN HELLO HOME ACTION
def homeAction
if (sceneId == 1) {
homeAction = homeAction1
}
if (sceneId == 2) {
homeAction = homeAction2
}
if (sceneId == 3) {
homeAction = homeAction3
}
if (sceneId == 4) {
homeAction = homeAction4
}
if (sceneId == 5) {
homeAction = homeAction5
}
if (sceneId == 6) {
homeAction = homeAction6
}
if (homeAction) {
location.helloHome.execute(homeAction)
log.trace "Running Home Action: $homeAction"
}
else {
log.trace "No Home Action Defined for Current State"
}
}
private getOrientation(xyz=null) {
final threshold = 250
def value = xyz ?: cube.currentValue("threeAxis")
def x = Math.abs(value.x) > threshold ? (value.x > 0 ? 1 : -1) : 0
def y = Math.abs(value.y) > threshold ? (value.y > 0 ? 1 : -1) : 0
def z = Math.abs(value.z) > threshold ? (value.z > 0 ? 1 : -1) : 0
def orientation = 0
if (z > 0) {
if (x == 0 && y == 0) {
orientation = 1
}
}
else if (z < 0) {
if (x == 0 && y == 0) {
orientation = 2
}
}
else {
if (x > 0) {
if (y == 0) {
orientation = 3
}
}
else if (x < 0) {
if (y == 0) {
orientation = 4
}
}
else {
if (y > 0) {
orientation = 5
}
else if (y < 0) {
orientation = 6
}
}
}
orientation
}
private sceneName(num) {
final names = ["UNDEFINED","One","Two","Three","Four","Five","Six"]
settings."sceneName${num}" ?: "Scene ${names[num]}"
}

View File

@@ -68,6 +68,7 @@ def bridgeDiscovery(params=[:])
log.trace "Cleaning old bridges memory"
state.bridges = [:]
state.bridgeRefreshCount = 0
app.updateSetting("selectedHue", "")
}
subscribe(location, null, locationHandler, [filterEvents:false])
@@ -131,17 +132,24 @@ def bulbDiscovery() {
state.bulbRefreshCount = bulbRefreshCount + 1
def refreshInterval = 3
state.inBulbDiscovery = true
def bridge = null
if (selectedHue) {
bridge = getChildDevice(selectedHue)
subscribe(bridge, "bulbList", bulbListData)
}
state.bridgeRefreshCount = 0
def options = bulbsDiscovered() ?: []
def numFound = options.size() ?: 0
def bulboptions = bulbsDiscovered() ?: [:]
def numFound = bulboptions.size() ?: 0
if (numFound == 0)
app.updateSetting("selectedBulbs", "")
if((bulbRefreshCount % 3) == 0) {
discoverHueBulbs()
}
return dynamicPage(name:"bulbDiscovery", title:"Bulb Discovery Started!", nextPage:"", refreshInterval:refreshInterval, install:true, uninstall: true) {
section("Please wait while we discover your Hue Bulbs. Discovery can take five minutes or more, so sit back and relax! Select your device below once discovered.") {
input "selectedBulbs", "enum", required:false, title:"Select Hue Bulbs (${numFound} found)", multiple:true, options:options
input "selectedBulbs", "enum", required:false, title:"Select Hue Bulbs (${numFound} found)", multiple:true, options:bulboptions
}
section {
def title = getBridgeIP() ? "Hue bridge (${getBridgeIP()})" : "Find bridges"
@@ -223,10 +231,14 @@ Map bulbsDiscovered() {
bulbmap["${key}"] = value
}
}
bulbmap
return bulbmap
}
def getHueBulbs() {
def bulbListData(evt) {
state.bulbs = evt.jsonData
}
Map getHueBulbs() {
state.bulbs = state.bulbs ?: [:]
}
@@ -252,7 +264,10 @@ def updated() {
def initialize() {
log.debug "Initializing"
unsubscribe(bridge)
state.inBulbDiscovery = false
state.bridgeRefreshCount = 0
state.bulbRefreshCount = 0
if (selectedHue) {
addBridge()
addBulbs()
@@ -276,9 +291,8 @@ def uninstalled(){
// Handles events to add new bulbs
def bulbListHandler(hub, data = "") {
def msg = "Bulbs list not processed. Only while in settings menu."
log.trace "Here: $hub, $data"
if (state.inBulbDiscovery) {
def bulbs = [:]
def bulbs = [:]
if (state.inBulbDiscovery) {
def logg = ""
log.trace "Adding bulbs to state..."
state.bridgeProcessedLightList = true
@@ -287,15 +301,18 @@ def bulbListHandler(hub, data = "") {
if (v instanceof Map)
bulbs[k] = [id: k, name: v.name, type: v.type, hub:hub]
}
state.bulbs = bulbs
msg = "${bulbs.size()} bulbs found. $state.bulbs"
}
}
def bridge = null
if (selectedHue)
bridge = getChildDevice(selectedHue)
bridge.sendEvent(name: "bulbList", value: hub, data: bulbs, isStateChange: true, displayed: false)
msg = "${bulbs.size()} bulbs found. ${bulbs}"
return msg
}
def addBulbs() {
def bulbs = getHueBulbs()
selectedBulbs.each { dni ->
selectedBulbs?.each { dni ->
def d = getChildDevice(dni)
if(!d) {
def newHueBulb
@@ -413,8 +430,11 @@ def locationHandler(evt) {
}
}
}
} else {
networkAddress = d.latestState('networkAddress').stringValue
} else {
if (d.getDeviceDataByName("networkAddress"))
networkAddress = d.getDeviceDataByName("networkAddress")
else
networkAddress = d.latestState('networkAddress').stringValue
log.trace "Host: $host - $networkAddress"
if(host != networkAddress) {
log.debug "Device's port or ip changed for device $d..."
@@ -422,7 +442,8 @@ def locationHandler(evt) {
dstate.port = port
dstate.name = "Philips hue ($ip)"
d.sendEvent(name:"networkAddress", value: host)
}
d.updateDataValue("networkAddress", host)
}
}
}
}
@@ -701,6 +722,11 @@ private getBridgeIP() {
if (host == null || host == "") {
def serialNumber = selectedHue
def bridge = getHueBridges().find { it?.value?.serialNumber?.equalsIgnoreCase(serialNumber) }?.value
if (!bridge) {
//failed because mac address sent from hub is wrong and doesn't match the hue's real mac address and serial number
//in this case we will look up the bridge by comparing the incorrect mac addresses
bridge = getHueBridges().find { it?.value?.mac?.equalsIgnoreCase(serialNumber) }?.value
}
if (bridge?.ip && bridge?.port) {
if (bridge?.ip.contains("."))
host = "${bridge?.ip}:${bridge?.port}"

View File

@@ -0,0 +1,702 @@
/**
* Home Remote
*
* Copyright 2015 The Home Remote
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
definition(
name: "Home Remote",
namespace: "thehomeremote.homeremote",
author: "The Home Remote",
description: "Web service that enables communication between the Home Remote app and a SmartThings hub.",
category: "My Apps",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
oauth: [displayName: "The Home Remote", displayLink: "http://thehomeremote.com/"])
preferences {
section() {
input "accelerationSensors", "capability.accelerationSensor",title: "Acceleration Sensors", multiple: true, required: false
input "alarms", "capability.alarm",title: "Alarms", multiple: true, required: false
input "batteries", "capability.battery",title: "Batteries", multiple: true, required: false
input "beacons", "capability.beacon",title: "Beacons", multiple: true, required: false
input "buttonGroup", "capability.button",title: "Buttons", multiple: true, required: false
input "carbonMonoxideDetectors", "capability.carbonMonoxideDetector",title: "CO Detectors", multiple: true, required: false
input "colorControls", "capability.colorControl",title: "Color Lights", multiple: true, required: false
input "contactSensors", "capability.contactSensor",title: "Contact Sensors", multiple: true, required: false
input "doorControls", "capability.doorControl",title: "Door Controllers", multiple: true, required: false
input "energyMeters", "capability.energyMeter",title: "Energy Meters", multiple: true, required: false
input "illuminanceMeasurements", "capability.illuminanceMeasurement",title: "Illuminance Sensors", multiple: true, required: false
input "imageCaptures", "capability.imageCapture",title: "Cameras", multiple: true, required: false
input "locks", "capability.lock",title: "Locks", multiple: true, required: false
input "mediaControllers", "capability.mediaController",title: "Media Controllers", multiple: true, required: false
input "momentaries", "capability.momentary",title: "Momentary Buttons", multiple: true, required: false
input "motionSensors", "capability.motionSensor",title: "Motion Sensors", multiple: true, required: false
input "musicPlayers", "capability.musicPlayer",title: "Music Players", multiple: true, required: false
input "powerMeters", "capability.powerMeter",title: "Power Meters", multiple: true, required: false
input "presenceSensors", "capability.presenceSensor",title: "Presence Sensors", multiple: true, required: false
input "relativeHumidityMeasurements", "capability.relativeHumidityMeasurement",title: "Humidity Sensors", multiple: true, required: false
input "relaySwitches", "capability.relaySwitch",title: "Relays", multiple: true, required: false
input "signalStrengths", "capability.signalStrength",title: "Signal Strengths", multiple: true, required: false
input "sleepSensors", "capability.sleepSensor",title: "Sleep Sensors", multiple: true, required: false
input "smokeDetectors", "capability.smokeDetector",title: "Smoke Detectors", multiple: true, required: false
input "speechSyntheses", "capability.speechSynthesis",title: "Speech Syntheses", multiple: true, required: false
input "stepSensors", "capability.stepSensor",title: "Step Sensors", multiple: true, required: false
input "switches", "capability.switch",title: "Switches", multiple: true, required: false
input "switchLevels", "capability.switchLevel",title: "Dimmers", multiple: true, required: false
input "temperatureMeasurements", "capability.temperatureMeasurement",title: "Temperature Sensors", multiple: true, required: false
input "thermostats", "capability.thermostat",title: "Thermostats", multiple: true, required: false
input "threeAxes", "capability.threeAxis",title: "Three axis Sensors", multiple: true, required: false
input "tones", "capability.tone",title: "Tones", multiple: true, required: false
input "touchSensors", "capability.touchSensor",title: "Touch Sensors", multiple: true, required: false
input "valves", "capability.valve",title: "Valves", multiple: true, required: false
input "waterSensors", "capability.waterSensor",title: "Water Sensors", multiple: true, required: false
}
}
mappings {
path("/GetCurrentValues") {
action: [
GET: "getCurrentValues"
]
}
path("/GetCurrentValuesWithDisplayName") {
action: [
GET: "getCurrentValuesWithDisplayName"
]
}
path("/ExecuteCommand") {
action: [
PUT: "executeCommand"
]
}
}
def getCurrentValues() {
def resp = []
accelerationSensors.each {
resp << [id: it.id, capability: "AccelerationSensor", attribute: "acceleration", value: it.currentValue("acceleration")]
}
alarms.each {
resp << [id: it.id, capability: "Alarm", attribute: "alarm", value: it.currentValue("alarm")]
}
batteries.each {
resp << [id: it.id, capability: "Battery", attribute: "battery", value: it.currentValue("battery")]
}
beacons.each {
resp << [id: it.id, capability: "Beacon", attribute: "presence", value: it.currentValue("presence")]
}
buttonGroup.each {
resp << [id: it.id, capability: "Button", attribute: "button", value: it.currentValue("button")]
}
carbonMonoxideDetectors.each {
resp << [id: it.id, capability: "CarbonMonoxideDetector", attribute: "carbonMonoxide", value: it.currentValue("carbonMonoxide")]
}
colorControls.each {
resp << [id: it.id, capability: "ColorControl", attribute: "hue", value: it.currentValue("hue")]
}
colorControls.each {
resp << [id: it.id, capability: "ColorControl", attribute: "saturation", value: it.currentValue("saturation")]
}
colorControls.each {
resp << [id: it.id, capability: "ColorControl", attribute: "color", value: it.currentValue("color")]
}
contactSensors.each {
resp << [id: it.id, capability: "ContactSensor", attribute: "contact", value: it.currentValue("contact")]
}
doorControls.each {
resp << [id: it.id, capability: "DoorControl", attribute: "door", value: it.currentValue("door")]
}
energyMeters.each {
resp << [id: it.id, capability: "EnergyMeter", attribute: "energy", value: it.currentValue("energy")]
}
illuminanceMeasurements.each {
resp << [id: it.id, capability: "IlluminanceMeasurement", attribute: "illuminance", value: it.currentValue("illuminance")]
}
imageCaptures.each {
resp << [id: it.id, capability: "ImageCapture", attribute: "image", value: it.currentValue("image")]
}
locks.each {
resp << [id: it.id, capability: "Lock", attribute: "lock", value: it.currentValue("lock")]
}
mediaControllers.each {
resp << [id: it.id, capability: "MediaController", attribute: "activities", value: it.currentValue("activities")]
}
mediaControllers.each {
resp << [id: it.id, capability: "MediaController", attribute: "currentActivity", value: it.currentValue("currentActivity")]
}
motionSensors.each {
resp << [id: it.id, capability: "MotionSensor", attribute: "motion", value: it.currentValue("motion")]
}
musicPlayers.each {
resp << [id: it.id, capability: "MusicPlayer", attribute: "status", value: it.currentValue("status")]
}
musicPlayers.each {
resp << [id: it.id, capability: "MusicPlayer", attribute: "level", value: it.currentValue("level")]
}
musicPlayers.each {
resp << [id: it.id, capability: "MusicPlayer", attribute: "trackDescription", value: it.currentValue("trackDescription")]
}
musicPlayers.each {
resp << [id: it.id, capability: "MusicPlayer", attribute: "trackData", value: it.currentValue("trackData")]
}
musicPlayers.each {
resp << [id: it.id, capability: "MusicPlayer", attribute: "mute", value: it.currentValue("mute")]
}
powerMeters.each {
resp << [id: it.id, capability: "PowerMeter", attribute: "power", value: it.currentValue("power")]
}
presenceSensors.each {
resp << [id: it.id, capability: "PresenceSensor", attribute: "presence", value: it.currentValue("presence")]
}
relativeHumidityMeasurements.each {
resp << [id: it.id, capability: "RelativeHumidityMeasurement", attribute: "humidity", value: it.currentValue("humidity")]
}
relaySwitches.each {
resp << [id: it.id, capability: "RelaySwitch", attribute: "switch", value: it.currentValue("switch")]
}
signalStrengths.each {
resp << [id: it.id, capability: "SignalStrength", attribute: "lqi", value: it.currentValue("lqi")]
}
signalStrengths.each {
resp << [id: it.id, capability: "SignalStrength", attribute: "rssi", value: it.currentValue("rssi")]
}
sleepSensors.each {
resp << [id: it.id, capability: "SleepSensor", attribute: "sleeping", value: it.currentValue("sleeping")]
}
smokeDetectors.each {
resp << [id: it.id, capability: "SmokeDetector", attribute: "smoke", value: it.currentValue("smoke")]
}
stepSensors.each {
resp << [id: it.id, capability: "StepSensor", attribute: "steps", value: it.currentValue("steps")]
}
stepSensors.each {
resp << [id: it.id, capability: "StepSensor", attribute: "goal", value: it.currentValue("goal")]
}
switches.each {
resp << [id: it.id, capability: "Switch", attribute: "switch", value: it.currentValue("switch")]
}
switchLevels.each {
resp << [id: it.id, capability: "SwitchLevel", attribute: "level", value: it.currentValue("level")]
}
temperatureMeasurements.each {
resp << [id: it.id, capability: "TemperatureMeasurement", attribute: "temperature", value: it.currentValue("temperature")]
}
thermostats.each {
resp << [id: it.id, capability: "Thermostat", attribute: "temperature", value: it.currentValue("temperature")]
}
thermostats.each {
resp << [id: it.id, capability: "Thermostat", attribute: "heatingSetpoint", value: it.currentValue("heatingSetpoint")]
}
thermostats.each {
resp << [id: it.id, capability: "Thermostat", attribute: "coolingSetpoint", value: it.currentValue("coolingSetpoint")]
}
thermostats.each {
resp << [id: it.id, capability: "Thermostat", attribute: "thermostatSetpoint", value: it.currentValue("thermostatSetpoint")]
}
thermostats.each {
resp << [id: it.id, capability: "Thermostat", attribute: "thermostatMode", value: it.currentValue("thermostatMode")]
}
thermostats.each {
resp << [id: it.id, capability: "Thermostat", attribute: "thermostatFanMode", value: it.currentValue("thermostatFanMode")]
}
thermostats.each {
resp << [id: it.id, capability: "Thermostat", attribute: "thermostatOperatingState", value: it.currentValue("thermostatOperatingState")]
}
threeAxes.each {
resp << [id: it.id, capability: "ThreeAxis", attribute: "threeAxis", value: it.currentValue("threeAxis")]
}
touchSensors.each {
resp << [id: it.id, capability: "TouchSensor", attribute: "touch", value: it.currentValue("touch")]
}
valves.each {
resp << [id: it.id, capability: "Valve", attribute: "contact", value: it.currentValue("contact")]
}
waterSensors.each {
resp << [id: it.id, capability: "WaterSensor", attribute: "water", value: it.currentValue("water")]
}
return resp
}
def getCurrentValuesWithDisplayName() {
def resp = []
accelerationSensors.each {
resp << [id: it.id, displayName: it.displayName, capability: "AccelerationSensor", attribute: "acceleration", value: it.currentValue("acceleration")]
}
alarms.each {
resp << [id: it.id, displayName: it.displayName, capability: "Alarm", attribute: "alarm", value: it.currentValue("alarm")]
}
batteries.each {
resp << [id: it.id, displayName: it.displayName, capability: "Battery", attribute: "battery", value: it.currentValue("battery")]
}
beacons.each {
resp << [id: it.id, displayName: it.displayName, capability: "Beacon", attribute: "presence", value: it.currentValue("presence")]
}
buttonGroup.each {
resp << [id: it.id, displayName: it.displayName, capability: "Button", attribute: "button", value: it.currentValue("button")]
}
carbonMonoxideDetectors.each {
resp << [id: it.id, displayName: it.displayName, capability: "CarbonMonoxideDetector", attribute: "carbonMonoxide", value: it.currentValue("carbonMonoxide")]
}
colorControls.each {
resp << [id: it.id, displayName: it.displayName, capability: "ColorControl", attribute: "hue", value: it.currentValue("hue")]
}
colorControls.each {
resp << [id: it.id, displayName: it.displayName, capability: "ColorControl", attribute: "saturation", value: it.currentValue("saturation")]
}
colorControls.each {
resp << [id: it.id, displayName: it.displayName, capability: "ColorControl", attribute: "color", value: it.currentValue("color")]
}
contactSensors.each {
resp << [id: it.id, displayName: it.displayName, capability: "ContactSensor", attribute: "contact", value: it.currentValue("contact")]
}
doorControls.each {
resp << [id: it.id, displayName: it.displayName, capability: "DoorControl", attribute: "door", value: it.currentValue("door")]
}
energyMeters.each {
resp << [id: it.id, displayName: it.displayName, capability: "EnergyMeter", attribute: "energy", value: it.currentValue("energy")]
}
illuminanceMeasurements.each {
resp << [id: it.id, displayName: it.displayName, capability: "IlluminanceMeasurement", attribute: "illuminance", value: it.currentValue("illuminance")]
}
imageCaptures.each {
resp << [id: it.id, displayName: it.displayName, capability: "ImageCapture", attribute: "image", value: it.currentValue("image")]
}
locks.each {
resp << [id: it.id, displayName: it.displayName, capability: "Lock", attribute: "lock", value: it.currentValue("lock")]
}
mediaControllers.each {
resp << [id: it.id, displayName: it.displayName, capability: "MediaController", attribute: "activities", value: it.currentValue("activities")]
}
mediaControllers.each {
resp << [id: it.id, displayName: it.displayName, capability: "MediaController", attribute: "currentActivity", value: it.currentValue("currentActivity")]
}
motionSensors.each {
resp << [id: it.id, displayName: it.displayName, capability: "MotionSensor", attribute: "motion", value: it.currentValue("motion")]
}
musicPlayers.each {
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "status", value: it.currentValue("status")]
}
musicPlayers.each {
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "level", value: it.currentValue("level")]
}
musicPlayers.each {
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "trackDescription", value: it.currentValue("trackDescription")]
}
musicPlayers.each {
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "trackData", value: it.currentValue("trackData")]
}
musicPlayers.each {
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "mute", value: it.currentValue("mute")]
}
powerMeters.each {
resp << [id: it.id, displayName: it.displayName, capability: "PowerMeter", attribute: "power", value: it.currentValue("power")]
}
presenceSensors.each {
resp << [id: it.id, displayName: it.displayName, capability: "PresenceSensor", attribute: "presence", value: it.currentValue("presence")]
}
relativeHumidityMeasurements.each {
resp << [id: it.id, displayName: it.displayName, capability: "RelativeHumidityMeasurement", attribute: "humidity", value: it.currentValue("humidity")]
}
relaySwitches.each {
resp << [id: it.id, displayName: it.displayName, capability: "RelaySwitch", attribute: "switch", value: it.currentValue("switch")]
}
signalStrengths.each {
resp << [id: it.id, displayName: it.displayName, capability: "SignalStrength", attribute: "lqi", value: it.currentValue("lqi")]
}
signalStrengths.each {
resp << [id: it.id, displayName: it.displayName, capability: "SignalStrength", attribute: "rssi", value: it.currentValue("rssi")]
}
sleepSensors.each {
resp << [id: it.id, displayName: it.displayName, capability: "SleepSensor", attribute: "sleeping", value: it.currentValue("sleeping")]
}
smokeDetectors.each {
resp << [id: it.id, displayName: it.displayName, capability: "SmokeDetector", attribute: "smoke", value: it.currentValue("smoke")]
}
stepSensors.each {
resp << [id: it.id, displayName: it.displayName, capability: "StepSensor", attribute: "steps", value: it.currentValue("steps")]
}
stepSensors.each {
resp << [id: it.id, displayName: it.displayName, capability: "StepSensor", attribute: "goal", value: it.currentValue("goal")]
}
switches.each {
resp << [id: it.id, displayName: it.displayName, capability: "Switch", attribute: "switch", value: it.currentValue("switch")]
}
switchLevels.each {
resp << [id: it.id, displayName: it.displayName, capability: "SwitchLevel", attribute: "level", value: it.currentValue("level")]
}
temperatureMeasurements.each {
resp << [id: it.id, displayName: it.displayName, capability: "TemperatureMeasurement", attribute: "temperature", value: it.currentValue("temperature")]
}
thermostats.each {
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "temperature", value: it.currentValue("temperature")]
}
thermostats.each {
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "heatingSetpoint", value: it.currentValue("heatingSetpoint")]
}
thermostats.each {
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "coolingSetpoint", value: it.currentValue("coolingSetpoint")]
}
thermostats.each {
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "thermostatSetpoint", value: it.currentValue("thermostatSetpoint")]
}
thermostats.each {
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "thermostatMode", value: it.currentValue("thermostatMode")]
}
thermostats.each {
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "thermostatFanMode", value: it.currentValue("thermostatFanMode")]
}
thermostats.each {
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "thermostatOperatingState", value: it.currentValue("thermostatOperatingState")]
}
threeAxes.each {
resp << [id: it.id, displayName: it.displayName, capability: "ThreeAxis", attribute: "threeAxis", value: it.currentValue("threeAxis")]
}
touchSensors.each {
resp << [id: it.id, displayName: it.displayName, capability: "TouchSensor", attribute: "touch", value: it.currentValue("touch")]
}
valves.each {
resp << [id: it.id, displayName: it.displayName, capability: "Valve", attribute: "contact", value: it.currentValue("contact")]
}
waterSensors.each {
resp << [id: it.id, displayName: it.displayName, capability: "WaterSensor", attribute: "water", value: it.currentValue("water")]
}
return resp
}
def getDevices(capability){
def result
switch (capability) {
case "Alarm":
result = alarms
break
case "ColorControl":
result = colorControls
break
case "DoorControl":
result = doorControls
break
case "ImageCapture":
result = imageCaptures
break
case "Lock":
result = locks
break
case "MediaController":
result = mediaControllers
break
case "Momentary":
result = momentaries
break
case "MusicPlayer":
result = musicPlayers
break
case "RelaySwitch":
result = relaySwitches
break
case "SpeechSynthesis":
result = speechSyntheses
break
case "Switch":
result = switches
break
case "SwitchLevel":
result = switchLevels
break
case "Thermostat":
result = thermostats
break
case "ThermostatCoolingSetpoint":
result = thermostatCoolingSetpoints
break
case "ThermostatFanMode":
result = thermostatFanModes
break
case "ThermostatHeatingSetpoint":
result = thermostatHeatingSetpoints
break
case "ThermostatMode":
result = thermostatModes
break
case "Tone":
result = tones
break
case "Valve":
result = valves
break
default:
result = valves
}
return result
}
def getDoorControlCommand(value){
def result
switch (value) {
case "closed":
result = "close"
break
case "open":
result = "open"
break
default:
result = value
}
return result
}
def getLockCommand(value){
def result
switch (value) {
case "locked":
result = "lock"
break
case "unlocked":
result = "unlock"
break
default:
result = value
}
return result
}
def getMuteCommand(value){
def result
switch (value) {
case "muted":
result = "mute"
break
case "unmuted":
result = "unmute"
break
default:
result = value
}
return result
}
def getContactCommand(value){
def result
switch (value) {
case "closed":
result = "close"
break
case "open":
result = "open"
break
default:
result = value
}
return result
}
def getThermostatFanModeCommand(value){
def result
switch (value) {
case "on":
result = "fanOn"
break
case "auto":
result = "fanAuto"
break
case "circulate":
result = "fanCirculate"
break
default:
result = value
}
return result
}
void executeCommand() {
// use the built-in request object to get the command parameter
def deviceId = request.JSON?.deviceId
def capability = request.JSON?.capability
def attribute = request.JSON?.attribute
def value = request.JSON?.value
if (deviceId) {
def devices = getDevices(capability)
def command
def valueIsParameter = false
switch (attribute) {
case "hue":
command = "setHue"
valueIsParameter = true
break
case "saturation":
command = "setSaturation"
valueIsParameter = true
break
case "color":
command = "setColor"
valueIsParameter = true
break
case "level":
command = "setLevel"
valueIsParameter = true
break
case "heatingSetpoint":
command = "setHeatingSetpoint"
valueIsParameter = true
break
case "coolingSetpoint":
command = "setCoolingSetpoint"
valueIsParameter = true
break
case "currentActivity":
command = "startActivity"
valueIsParameter = true
break
case "door":
command = getDoorControlCommand(value)
break
case "lock":
command = getLockCommand(value)
break
case "mute":
command = getMuteCommand(value)
break
case "thermostatFanMode":
command = getThermostatFanModeCommand(value)
break
case "thermostatMode":
if (value == "emergency heat") {
command = "emergencyHeat"
}
break
case "contact":
command = getContactCommand(value)
break
default:
command = value
}
// check that the switch supports the specified command
// If not, return an error using httpError, providing a HTTP status code.
devices.each {
if (it.id == deviceId) {
if (!it.hasCommand(command)) {
httpError(501, "$command is not a valid command for all devices specified")
}
if(valueIsParameter){
it."$command"(value)
}
else{
it."$command"()
}
}
}
}
}
def installed() {}
def updated() {}

View File

@@ -0,0 +1,307 @@
/**
* WeatherBug Home
*
* Copyright 2015 WeatherBug
*
*/
definition(
name: "WeatherBug Home",
namespace: "WeatherBug",
author: "WeatherBug Home",
description: "WeatherBug Home",
category: "My Apps",
iconUrl: "http://stg.static.myenergy.enqa.co/apps/wbhc/v2/images/weatherbughomemedium.png",
iconX2Url: "http://stg.static.myenergy.enqa.co/apps/wbhc/v2/images/weatherbughomemedium.png",
iconX3Url: "http://stg.static.myenergy.enqa.co/apps/wbhc/v2/images/weatherbughome.png",
oauth: [displayName: "WeatherBug Home", displayLink: "http://weatherbughome.com/"])
preferences {
section("Select thermostats") {
input "thermostatDevice", "capability.thermostat", multiple: true
}
}
mappings {
path("/appInfo") { action: [ GET: "getAppInfo" ] }
path("/getLocation") { action: [ GET: "getLoc" ] }
path("/currentReport/:id") { action: [ GET: "getCurrentReport" ] }
path("/setTemp/:temp/:id") { action: [ POST: "setTemperature", GET: "setTemperature" ] }
}
/**
* This API call will be leveraged by a WeatherBug Home Service to retrieve
* data from the installed SmartApp, including the location data, and
* a list of the devices that were authorized to be accessed. The WeatherBug
* Home Service will leverage this data to represent the connected devices as well as their
* location and associated the data with a WeatherBug user account.
* Privacy Policy: http://weatherbughome.com/privacy/
* @return Location, including id, latitude, longitude, zip code, and name, and the list of devices
*/
def getAppInfo() {
def devices = thermostatDevice
def lat = location.latitude
def lon = location.longitude
if(!(devices instanceof Collection))
{
devices = [devices]
}
return [
Id: UUID.randomUUID().toString(),
Code: 200,
ErrorMessage: null,
Result: [ "Devices": devices,
"Location":[
"Id": location.id,
"Latitude":lat,
"Longitude":lon,
"ZipCode":location.zipCode,
"Name":location.name
]
]
]
}
/**
* This API call will be leveraged by a WeatherBug Home Service to retrieve
* location data from the installed SmartApp. The WeatherBug
* Home Service will leverage this data to associate the location to a WeatherBug Home account
* Privacy Policy: http://weatherbughome.com/privacy/
*
* @return Location, including id, latitude, longitude, zip code, and name
*/
def getLoc() {
return [
Id: UUID.randomUUID().toString(),
Code: 200,
ErrorMessage: null,
Result: [
"Id": location.id,
"Latitude":location.latitude,
"Longitude":location.longitude,
"ZipCode":location.zipCode,
"Name":location.name]
]
}
/**
* This API call will be leveraged by a WeatherBug Home Service to retrieve
* thermostat data and store it for display to a WeatherBug user.
* Privacy Policy: http://weatherbughome.com/privacy/
*
* @param id The id of the device to get data for
* @return Thermostat data including temperature, set points, running modes, and operating states
*/
def getCurrentReport() {
log.debug "device id parameter=" + params.id
def unixTime = (int)((new Date().getTime() / 1000))
def device = thermostatDevice.find{ it.id == params.id}
if(device == null)
{
return [
Id: UUID.randomUUID().toString(),
Code: 404,
ErrorMessage: "Device not found. id=" + params.id,
Result: null
]
}
return [
Id: UUID.randomUUID().toString(),
Code: 200,
ErrorMessage: null,
Result: [
DeviceId: device.id,
LocationId: location.id,
ReportType: 2,
ReportList: [
[Key: "Temperature", Value: GetOrDefault(device, "temperature")],
[Key: "ThermostatSetpoint", Value: GetOrDefault(device, "thermostatSetpoint")],
[Key: "CoolingSetpoint", Value: GetOrDefault(device, "coolingSetpoint")],
[Key: "HeatingSetpoint", Value: GetOrDefault(device, "heatingSetpoint")],
[Key: "ThermostatMode", Value: GetOrDefault(device, "thermostatMode")],
[Key: "ThermostatFanMode", Value: GetOrDefault(device, "thermostatFanMode")],
[Key: "ThermostatOperatingState", Value: GetOrDefault(device, "thermostatOperatingState")]
],
UnixTime: unixTime
]
]
}
/**
* This API call will be leveraged by a WeatherBug Home Service to set
* the thermostat setpoint.
* Privacy Policy: http://weatherbughome.com/privacy/
*
* @param id The id of the device to set
* @return Indication of whether the operation succeeded or failed
def setTemperature() {
log.debug "device id parameter=" + params.id
def device = thermostatDevice.find{ it.id == params.id}
if(device != null)
{
def mode = device.latestState('thermostatMode').stringValue
def value = params.temp as Integer
log.trace "Suggested temperature: $value, $mode"
if ( mode == "cool")
device.setCoolingSetpoint(value)
else if ( mode == "heat")
device.setHeatingSetpoint(value)
return [
Id: UUID.randomUUID().toString(),
Code: 200,
ErrorMessage: null,
Result: null
]
}
return [
Id: UUID.randomUUID().toString(),
Code : 404,
ErrorMessage: "Device not found. id=" + params.id,
Result: null
]
}
*/
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
/**
* The updated event will be pushed to a WeatherBug Home Service to notify the system to take appropriate action.
* Data that will be sent includes the list of devices, and location data
* Privacy Policy: http://weatherbughome.com/privacy/
*/
def updated() {
log.debug "Updated with settings: ${settings}"
log.debug "Updated with state: ${state}"
log.debug "Updated with location ${location} ${location.id} ${location.name}"
unsubscribe()
initialize()
def postParams = [
uri: 'https://smartthingsrec.api.earthnetworks.com/api/v1/receive/smartapp/update',
body: [
"Devices": devices,
"Location":[
"Id": location.id,
"Latitude":location.latitude,
"Longitude":location.longitude,
"ZipCode":location.zipCode,
"Name":location.name
]
]
]
sendToWeatherBug(postParams)
}
/*
* Subscribe to changes on the thermostat attributes
*/
def initialize() {
log.trace "initialize enter"
subscribe(thermostatDevice, "heatingSetpoint", pushLatest)
subscribe(thermostatDevice, "coolingSetpoint", pushLatest)
subscribe(thermostatDevice, "thermostatSetpoint", pushLatest)
subscribe(thermostatDevice, "thermostatMode", pushLatest)
subscribe(thermostatDevice, "thermostatFanMode", pushLatest)
subscribe(thermostatDevice, "thermostatOperatingState", pushLatest)
subscribe(thermostatDevice, "temperature", pushLatest)
}
/**
* The uninstall event will be pushed to a WeatherBug Home Service to notify the system to take appropriate action.
* Data that will be sent includes the list of devices, and location data
* Privacy Policy: http://weatherbughome.com/privacy/
*/
def uninstalled() {
log.trace "uninstall entered"
def postParams = [
uri: 'https://smartthingsrec.api.earthnetworks.com/api/v1/receive/smartapp/delete',
body: [
"Devices": devices,
"Location":[
"Id": location.id,
"Latitude":location.latitude,
"Longitude":location.longitude,
"ZipCode":location.zipCode,
"Name":location.name
]
]
]
sendToWeatherBug(postParams)
}
/**
* This method will push the latest thermostat data to the WeatherBug Home Service so it can store
* and display the data to the WeatherBug user. Data pushed includes the thermostat data as well
* as location id.
* Privacy Policy: http://weatherbughome.com/privacy/
*/
def pushLatest(evt) {
def unixTime = (int)((new Date().getTime() / 1000))
def device = thermostatDevice.find{ it.id == evt.deviceId}
def postParams = [
uri: 'https://smartthingsrec.api.earthnetworks.com/api/v1/receive',
body: [
DeviceId: evt.deviceId,
LocationId: location.id,
ReportType: 2,
ReportList: [
[Key: "Temperature", Value: GetOrDefault(device, "temperature")],
[Key: "ThermostatSetpoint", Value: GetOrDefault(device, "thermostatSetpoint")],
[Key: "CoolingSetpoint", Value: GetOrDefault(device, "coolingSetpoint")],
[Key: "HeatingSetpoint", Value: GetOrDefault(device, "heatingSetpoint")],
[Key: "ThermostatMode", Value: GetOrDefault(device, "thermostatMode")],
[Key: "ThermostatFanMode", Value: GetOrDefault(device, "thermostatFanMode")],
[Key: "ThermostatOperatingState", Value: GetOrDefault(device, "thermostatOperatingState")]
],
UnixTime: unixTime
]
]
log.debug postParams
sendToWeatherBug(postParams)
}
/*
* This method attempts to get the value of a device attribute, but if an error occurs null is returned
* @return The device attribute value, or null
*/
def GetOrDefault(device, attrib)
{
def val
try{
val = device.latestValue(attrib)
}catch(ex)
{
log.debug "Failed to get attribute " + attrib + " from device " + device
val = null
}
return val
}
/*
* Convenience method that sends data to WeatherBug, logging any exceptions that may occur
* Privacy Policy: http://weatherbughome.com/privacy/
*/
def sendToWeatherBug(postParams)
{
try{
log.debug postParams
httpPostJson(postParams) { resp ->
resp.headers.each {
log.debug "${it.name} : ${it.value}"
}
log.debug "response contentType: ${resp.contentType}"
log.debug "response data: ${resp.data}"
}
log.debug "Communication with WeatherBug succeeded";
}catch(ex)
{
log.debug "Communication with WeatherBug failed.\n${ex}";
}
}