Compare commits

..

1 Commits

11 changed files with 223 additions and 704 deletions

View File

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

View File

@@ -19,6 +19,7 @@ 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 && (state?.rate != null)) {
if (dimRate) {
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.jpg",
"http://cdn.device-gse.smartthings.com/Outlet/US/OutletUS2.jpg"
"http://cdn.device-gse.smartthings.com/Outlet/US/OutletUS1.png",
"http://cdn.device-gse.smartthings.com/Outlet/US/OutletUS2.png"
])
}
}

View File

@@ -39,9 +39,9 @@ metadata {
preferences {
section {
image(name: 'educationalcontent', multiple: true, images: [
"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"
"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"
])
}
section {

View File

@@ -54,10 +54,10 @@
preferences {
section {
image(name: 'educationalcontent', multiple: true, images: [
"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"
"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"
])
}
section {

View File

@@ -1,124 +0,0 @@
/**
* 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,219 +0,0 @@
/**
* Pipe Freeze Preventer
*
* Copyright 2015 Simon Labrecque
*
* 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: "Pipe Freeze Preventer",
namespace: "simon-labrecque",
author: "Simon Labrecque",
description: "Pipe Freeze Preventer 'turns on' thermostats, by setting them to a configured heating setpoint, when it's been more than X minutes that they've been off. Used to make sure that hot water circulates in the pipes on a controlled schedule to prevent pipes freezing.",
category: "Safety & Security",
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")
preferences {
section("About") {
paragraph textAbout()
}
section("Schedule settings")
{
input "everyXMinutes", "number", title: "Schedule to turn on at least every X minutes", defaultValue: "180"
input "leaveOnForXMinutes", "number", title: "Leave on for X minutes", defaultValue: "5"
input "minOutsideTemp", "text", title: "Outside temperature needs to be X or less for the schedule to run", defaultValue: "-10"
}
section("Thermostats settings"){
input "thermostats", "capability.thermostat", multiple: true, title: "Select Thermostats to monitor and control"
input "setTemperatureToThisToTurnOn", "number", title: "Heating setpoint used to 'turn on' the thermostat", defaultValue: "40"
}
section("Settings to use for Open Weather Map API (used to get outside temperature)"){
input "cityID", "text", title: "City ID", defaultValue: ""
input "apikey", "text", title: "API Key", defaultValue: ""
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
subscribe(thermostats, "thermostatOperatingState", thermostatChange)
schedule("37 * * * * ?", "scheduleCheck")
state.currentlyUnfreezing = false
state.lastOnTime = now() - ((everyXMinutes) * 60 * 1000)
subscribe(app, onAppTouch)
}
def thermostatChange(evt) {
log.debug "thermostatChange: $evt.name: $evt.value"
if(evt.value == "heating") {
state.lastOnTime = now()
}
log.debug "state: " + state.lastOnTime
}
def scheduleCheck() {
log.debug "schedule check, lastOnTime = ${state.lastOnTime}, currentlyUnfreezing = ${state.currentlyUnfreezing}"
if(state.currentlyUnfreezing == false)
{
log.debug "scheduleCheck: calling checkIfNeedToUnfreeze"
checkIfNeedToUnfreeze()
}
else
{
log.debug "scheduleCheck: calling checkIfNeedToReturnToNormal"
checkIfNeedToReturnToNormal()
}
}
def checkIfNeedToReturnToNormal()
{
def unfreezingForInMinutes = ((now() - state.unfreezingSince) / 1000) / 60
log.debug "checkIfNeedToReturnToNormal: we've been unfreezing for " + unfreezingForInMinutes + " minutes"
if(unfreezingForInMinutes > leaveOnForXMinutes)
{
stopUnfreezing()
}
else
{
log.debug "checkIfNeedToReturnToNormal: continuing unfreezing"
}
}
def stopUnfreezing() {
log.debug "stopUnfreezing: setting back thermostats to their original heatingSetPoint"
for (int i = 0; i < thermostats.size(); i++) {
thermostats[i].setHeatingSetpoint(state.tstatHeatingSetpointBackup[i])
}
state.currentlyUnfreezing = false;
state.lastOnTime = now()
}
def checkIfNeedToUnfreeze()
{
def currentOutsideTemperature = getCurrentOutsideTemperature()
BigDecimal minTemperatureDecimal = new BigDecimal(minOutsideTemp)
log.debug "checkIfNeedToUnfreeze: current oustide temperature is " + currentOutsideTemperature + "C, min temperature to run is " + minTemperatureDecimal
if(currentOutsideTemperature > minTemperatureDecimal)
{
log.debug "checkIfNeedToUnfreeze: no need to unfreeze since outside temperature is more than " + minOutsideTemp
return
}
for (tstat in thermostats) {
if(tstat.currentTemperature < tstat.currentHeatingSetpoint)
{
//We suppose that the thermostatOperatingState is heating even tough it wasn't reported
log.debug "checkIfNeedToUnfreeze: assuming that thermostat '" + tstat.label + "' is on since temperature is " + tstat.currentTemperature + " and setpoint is " + tstat.currentHeatingSetpoint
state.lastOnTime = now()
}
}
def minutesSinceLastOnTime = ((now() - state.lastOnTime) / 1000) / 60
log.debug "checkIfNeedToUnfreeze: " + minutesSinceLastOnTime + " minutes since our last unfreeze"
if(minutesSinceLastOnTime < everyXMinutes)
{
log.debug "checkIfNeedToUnfreeze: not turning on because we haven't reached " + everyXMinutes + " minutes yet"
return
}
//It's been more than everyXMinutes, so turning on thermostats
startUnfreezing()
}
def startUnfreezing() {
log.debug "startUnfreezing: starting unfreezing for " + leaveOnForXMinutes + " minutes"
state.currentlyUnfreezing = true
state.unfreezingSince = now()
state.tstatHeatingSetpointBackup = []
for (int i = 0; i < thermostats.size(); i++) {
log.debug "startUnfreezing: setting new heatingSetPoint for tstat " + thermostats[i].label
state.tstatHeatingSetpointBackup.add(thermostats[i].currentHeatingSetpoint)
thermostats[i].setHeatingSetpoint(setTemperatureToThisToTurnOn)
}
log.debug "startUnfreezing: turned on thermostats by setting temp to " + setTemperatureToThisToTurnOn
log.debug "startUnfreezing: tstat heatpoint backup: " + state.tstatHeatingSetpointBackup
log.debug "startUnfreezing: state.currentlyUnfreezing="+state.currentlyUnfreezing
}
BigDecimal getCurrentOutsideTemperature() {
def params = [
uri: 'http://api.openweathermap.org/data/2.5/',
path: 'weather',
contentType: 'application/json',
query: [mode: 'json', units: 'metric', APPID: apikey, id: cityID]
]
def currentTemperature = 0G
try {
httpGet(params) {resp ->
log.debug "resp data: ${resp.data}"
currentTemperature = resp.data.main.temp
}
} catch (e) {
log.error "error: $e"
}
return currentTemperature
}
private def textAbout() {
return '''\
Pipe Freeze Preventer 'turns on' thermostats, by setting them to a configured heating setpoint, \
when it's been more than X minutes that they've been off. Used to make sure that hot water circulates \
in the pipes on a controlled schedule to prevent pipes freezing. \
'''
}
def onAppTouch(event) {
log.debug "onAppTouch: currentlyUnfreezing: ${state.currentlyUnfreezing} lastOnTime:${state.lastOnTime}"
if(state.currentlyUnfreezing == false)
{
log.debug "onAppTouch: calling startUnfreezing()"
startUnfreezing()
}
else
{
log.debug "onAppTouch: calling stopUnfreezing()"
stopUnfreezing()
}
}

View File

@@ -0,0 +1,194 @@
/**
* 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,7 +68,6 @@ def bridgeDiscovery(params=[:])
log.trace "Cleaning old bridges memory"
state.bridges = [:]
state.bridgeRefreshCount = 0
app.updateSetting("selectedHue", "")
}
subscribe(location, null, locationHandler, [filterEvents:false])
@@ -132,24 +131,17 @@ 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 bulboptions = bulbsDiscovered() ?: [:]
def numFound = bulboptions.size() ?: 0
if (numFound == 0)
app.updateSetting("selectedBulbs", "")
def options = bulbsDiscovered() ?: []
def numFound = options.size() ?: 0
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:bulboptions
input "selectedBulbs", "enum", required:false, title:"Select Hue Bulbs (${numFound} found)", multiple:true, options:options
}
section {
def title = getBridgeIP() ? "Hue bridge (${getBridgeIP()})" : "Find bridges"
@@ -231,14 +223,10 @@ Map bulbsDiscovered() {
bulbmap["${key}"] = value
}
}
return bulbmap
bulbmap
}
def bulbListData(evt) {
state.bulbs = evt.jsonData
}
Map getHueBulbs() {
def getHueBulbs() {
state.bulbs = state.bulbs ?: [:]
}
@@ -264,10 +252,7 @@ def updated() {
def initialize() {
log.debug "Initializing"
unsubscribe(bridge)
state.inBulbDiscovery = false
state.bridgeRefreshCount = 0
state.bulbRefreshCount = 0
if (selectedHue) {
addBridge()
addBulbs()
@@ -291,8 +276,9 @@ def uninstalled(){
// Handles events to add new bulbs
def bulbListHandler(hub, data = "") {
def msg = "Bulbs list not processed. Only while in settings menu."
def bulbs = [:]
if (state.inBulbDiscovery) {
log.trace "Here: $hub, $data"
if (state.inBulbDiscovery) {
def bulbs = [:]
def logg = ""
log.trace "Adding bulbs to state..."
state.bridgeProcessedLightList = true
@@ -301,18 +287,15 @@ def bulbListHandler(hub, data = "") {
if (v instanceof Map)
bulbs[k] = [id: k, name: v.name, type: v.type, hub:hub]
}
}
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}"
state.bulbs = bulbs
msg = "${bulbs.size()} bulbs found. $state.bulbs"
}
return msg
}
def addBulbs() {
def bulbs = getHueBulbs()
selectedBulbs?.each { dni ->
selectedBulbs.each { dni ->
def d = getChildDevice(dni)
if(!d) {
def newHueBulb
@@ -430,11 +413,8 @@ def locationHandler(evt) {
}
}
}
} else {
if (d.getDeviceDataByName("networkAddress"))
networkAddress = d.getDeviceDataByName("networkAddress")
else
networkAddress = d.latestState('networkAddress').stringValue
} 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..."
@@ -442,8 +422,7 @@ def locationHandler(evt) {
dstate.port = port
dstate.name = "Philips hue ($ip)"
d.sendEvent(name:"networkAddress", value: host)
d.updateDataValue("networkAddress", host)
}
}
}
}
}
@@ -722,11 +701,6 @@ 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

@@ -1,307 +0,0 @@
/**
* 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}";
}
}