Compare commits

...

5 Commits

Author SHA1 Message Date
Iancu Tudorel
563c0ed318 MSA-1567: Broadlink LAN interface 2016-11-03 14:13:50 -05:00
Vinay Rao
40acb36009 Merge pull request #1423 from SmartThingsCommunity/staging
Rolling down staging to master
2016-11-02 16:50:04 -07:00
dsainteclaire
8986c4f5d6 Merge pull request #1411 from dsainteclaire/DVCSMP-2179-added-device-watch-to-ecobee
DVCSMP-2179 added device watch for ecobee based on the code from lyric
2016-11-02 14:26:24 -07:00
David Sainte-Claire
3a377ba147 added code formatting based on pull request comments 2016-11-01 23:07:27 -07:00
David Sainte-Claire
8a66742bb5 added device watch implementation for ecobee based on the code from lyric 2016-11-01 13:30:35 -07:00
3 changed files with 133 additions and 1 deletions

View File

@@ -23,6 +23,7 @@ metadata {
capability "Sensor"
capability "Refresh"
capability "Relative Humidity Measurement"
capability "Health Check"
command "generateEvent"
command "raiseSetpoint"
@@ -38,6 +39,7 @@ metadata {
attribute "maxCoolingSetpoint", "number"
attribute "minCoolingSetpoint", "number"
attribute "deviceTemperatureUnit", "string"
attribute "deviceAlive", "enum", ["true", "false"]
}
tiles {
@@ -120,6 +122,21 @@ metadata {
}
void installed() {
// The device refreshes every 5 minutes by default so if we miss 2 refreshes we can consider it offline
// Using 12 minutes because in testing, device health team found that there could be "jitter"
sendEvent(name: "checkInterval", value: 60 * 12, data: [protocol: "cloud", hubHardwareId: device.hub.hardwareID], displayed: false)
}
// Device Watch will ping the device to proactively determine if the device has gone offline
// If the device was online the last time we refreshed, trigger another refresh as part of the ping.
def ping() {
def isAlive = device.currentValue("deviceAlive") == "true" ? true : false
if (isAlive) {
refresh()
}
}
// parse events into attributes
def parse(String description) {
log.debug "Parsing '${description}'"
@@ -164,7 +181,11 @@ def generateEvent(Map results) {
} else if (name=="humidity") {
isChange = isStateChange(device, name, value.toString())
event << [value: value.toString(), isStateChange: isChange, displayed: false, unit: "%"]
} else {
} else if (name == "deviceAlive") {
isChange = isStateChange(device, name, value.toString())
event['isStateChange'] = isChange
event['displayed'] = false
} else {
isChange = isStateChange(device, name, value.toString())
isDisplayed = isChange
event << [value: value.toString(), isStateChange: isChange, displayed: isDisplayed]

View File

@@ -0,0 +1,110 @@
/**
* Broadlink RM
*
* Copyright 2016 Beckyr
*
* 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: "Broadlink LAN interface",
namespace: "smartthings",
author: "Beckyr",
description: "Control Broadlink RM Devices using Hub and LAN",
category: "Convenience",
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")
{
appSetting "BLURL"
appSetting "BLMac"
}
import groovy.json.*
preferences {
page(name: "Page1", title: "Broadlink Switch Importer", install: true, uninstall: true){
section("Make sure you have entered ayour local URL:port for the RM Plugin Bridge, along with the broadlink mac address, into the app settings") {
// input "switchDevices", "device.broadlink", title: "devices to use", multiple: true
}
}}
def installed() {
initialize()
}
def updated() {
initialize()
}
//For now this only works with one hub.
def initialize() {
subscribe(location, null, lanResponseHandler, [filterEvents:false])
def url1=appSettings.BLURL.toString()
def hubaction = new physicalgraph.device.HubAction(
method: "GET",
path: "/codes",
headers: [HOST: "${url1}"],
)
sendHubCommand(hubaction)
}
def lanResponseHandler(evt) {
def macID=appSettings.BLMac.toString()
def urlID=appSettings.BLURL.toString()
def myhubId = location.hubs[0].id
log.debug "hub id is ${myhubId}"
log.debug "In response handler"
def description = evt.description
def parsedEvent = parseLanMessage(description)
def text = parsedEvent.body
def json = new JsonSlurper().parseText(text)
json.each {
def codename = "$it.name"
codename=codename.toLowerCase()
if(codename == "on") {
def DevID = "BL-$it.remoteName"
try {
def existing = getChildDevice("${DevID}")
if(!existing) {
log.debug "adding device $it.remoteName with $codename"
def d = addChildDevice("smartthings", "broadlinkSwitch", "${DevID}", location.hubs[0].id, [label:"$it.remoteName", name:"$it.remoteName", completedSetup: true])
d.sendEvent(name:"BLmac", value:macID)
d.sendEvent(name:"BLURL", value: urlID)
d.sendEvent(name:"onCodeID", value: "${it.id}")
}
else {
existing.sendEvent(name: "onCodeID", value: "${it.id}")
}
} catch (e) {
log.error "Error creating device: ${e}"
}
}
if(codename == "off") {
def DevID = "BL-$it.remoteName"
try {
def existing = getChildDevice("${DevID}")
if(!existing) {
def d = addChildDevice("smartthings", "broadlinkSwitch", "${DevID}", location.hubs[0].id, [label:"$it.remoteName", name:"$it.remoteName", completedSetup: true])
d.sendEvent(name: "BLmac", value: macID)
d.sendEvent(name:"BLURL", value: urlID)
d.sendEvent(name: "offCodeID", value: "${it.id}")
}
else {
existing.sendEvent(name: "offCodeID", value: "${it.id}")
}
} catch (e) {
log.error "Error creating device: ${e}"
}
}
}
def children = getChildDevices()
children.each {
log.debug "device name: ${it.name}, URL: ${it.currentValue('BLURL')}, mac: ${it.currentValue('BLmac')}, onCodeID: ${it.currentOnCodeID}), offCodeID: ${it.currentOffCodeID}"
}
}

View File

@@ -842,6 +842,7 @@ private void storeThermostatData(thermostats) {
minCoolingSetpoint: (stat.settings.coolRangeLow / 10),
maxCoolingSetpoint: (stat.settings.coolRangeHigh / 10),
autoMode: stat.settings.autoHeatCoolFeatureEnabled,
deviceAlive: stat.runtime.connected == true ? "true" : "false",
auxHeatMode: (stat.settings.hasHeatPump) && (stat.settings.hasForcedAir || stat.settings.hasElectric || stat.settings.hasBoiler),
temperature: (stat.runtime.actualTemperature / 10),
heatingSetpoint: stat.runtime.desiredHeat / 10,