mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-20 13:20:53 +00:00
Compare commits
5 Commits
PROD_2016.
...
MSA-1567-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
563c0ed318 | ||
|
|
40acb36009 | ||
|
|
8986c4f5d6 | ||
|
|
3a377ba147 | ||
|
|
8a66742bb5 |
@@ -23,6 +23,7 @@ metadata {
|
|||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
capability "Refresh"
|
capability "Refresh"
|
||||||
capability "Relative Humidity Measurement"
|
capability "Relative Humidity Measurement"
|
||||||
|
capability "Health Check"
|
||||||
|
|
||||||
command "generateEvent"
|
command "generateEvent"
|
||||||
command "raiseSetpoint"
|
command "raiseSetpoint"
|
||||||
@@ -38,6 +39,7 @@ metadata {
|
|||||||
attribute "maxCoolingSetpoint", "number"
|
attribute "maxCoolingSetpoint", "number"
|
||||||
attribute "minCoolingSetpoint", "number"
|
attribute "minCoolingSetpoint", "number"
|
||||||
attribute "deviceTemperatureUnit", "string"
|
attribute "deviceTemperatureUnit", "string"
|
||||||
|
attribute "deviceAlive", "enum", ["true", "false"]
|
||||||
}
|
}
|
||||||
|
|
||||||
tiles {
|
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
|
// parse events into attributes
|
||||||
def parse(String description) {
|
def parse(String description) {
|
||||||
log.debug "Parsing '${description}'"
|
log.debug "Parsing '${description}'"
|
||||||
@@ -164,7 +181,11 @@ def generateEvent(Map results) {
|
|||||||
} else if (name=="humidity") {
|
} else if (name=="humidity") {
|
||||||
isChange = isStateChange(device, name, value.toString())
|
isChange = isStateChange(device, name, value.toString())
|
||||||
event << [value: value.toString(), isStateChange: isChange, displayed: false, unit: "%"]
|
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())
|
isChange = isStateChange(device, name, value.toString())
|
||||||
isDisplayed = isChange
|
isDisplayed = isChange
|
||||||
event << [value: value.toString(), isStateChange: isChange, displayed: isDisplayed]
|
event << [value: value.toString(), isStateChange: isChange, displayed: isDisplayed]
|
||||||
|
|||||||
@@ -84,20 +84,18 @@ def refresh() {
|
|||||||
|
|
||||||
def configure() {
|
def configure() {
|
||||||
log.debug "in configure()"
|
log.debug "in configure()"
|
||||||
return configureHealthCheck()
|
configureHealthCheck()
|
||||||
}
|
}
|
||||||
|
|
||||||
def configureHealthCheck() {
|
def configureHealthCheck() {
|
||||||
Integer hcIntervalMinutes = 12
|
Integer hcIntervalMinutes = 12
|
||||||
|
refresh()
|
||||||
sendEvent(name: "checkInterval", value: hcIntervalMinutes * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
sendEvent(name: "checkInterval", value: hcIntervalMinutes * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
||||||
return refresh()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def updated() {
|
def updated() {
|
||||||
log.debug "in updated()"
|
log.debug "in updated()"
|
||||||
// updated() doesn't have it's return value processed as hub commands, so we have to send them explicitly
|
configureHealthCheck()
|
||||||
def cmds = configureHealthCheck()
|
|
||||||
cmds.each{ sendHubCommand(new physicalgraph.device.HubAction(it)) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def ping() {
|
def ping() {
|
||||||
|
|||||||
@@ -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}"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -842,6 +842,7 @@ private void storeThermostatData(thermostats) {
|
|||||||
minCoolingSetpoint: (stat.settings.coolRangeLow / 10),
|
minCoolingSetpoint: (stat.settings.coolRangeLow / 10),
|
||||||
maxCoolingSetpoint: (stat.settings.coolRangeHigh / 10),
|
maxCoolingSetpoint: (stat.settings.coolRangeHigh / 10),
|
||||||
autoMode: stat.settings.autoHeatCoolFeatureEnabled,
|
autoMode: stat.settings.autoHeatCoolFeatureEnabled,
|
||||||
|
deviceAlive: stat.runtime.connected == true ? "true" : "false",
|
||||||
auxHeatMode: (stat.settings.hasHeatPump) && (stat.settings.hasForcedAir || stat.settings.hasElectric || stat.settings.hasBoiler),
|
auxHeatMode: (stat.settings.hasHeatPump) && (stat.settings.hasForcedAir || stat.settings.hasElectric || stat.settings.hasBoiler),
|
||||||
temperature: (stat.runtime.actualTemperature / 10),
|
temperature: (stat.runtime.actualTemperature / 10),
|
||||||
heatingSetpoint: stat.runtime.desiredHeat / 10,
|
heatingSetpoint: stat.runtime.desiredHeat / 10,
|
||||||
|
|||||||
@@ -381,28 +381,38 @@ def updateDevices() {
|
|||||||
selectors.add("${device.id}")
|
selectors.add("${device.id}")
|
||||||
if (!childDevice) {
|
if (!childDevice) {
|
||||||
// log.info("Adding device ${device.id}: ${device.product}")
|
// log.info("Adding device ${device.id}: ${device.product}")
|
||||||
|
def data = [
|
||||||
|
label: device.label,
|
||||||
|
level: Math.round((device.brightness ?: 1) * 100),
|
||||||
|
switch: device.power,
|
||||||
|
colorTemperature: device.color.kelvin
|
||||||
|
]
|
||||||
if (device.product.capabilities.has_color) {
|
if (device.product.capabilities.has_color) {
|
||||||
childDevice = addChildDevice(app.namespace, "LIFX Color Bulb", device.id, null, ["label": device.label, "completedSetup": true])
|
data["color"] = colorUtil.hslToHex((device.color.hue / 3.6) as int, (device.color.saturation * 100) as int)
|
||||||
|
data["hue"] = device.color.hue / 3.6
|
||||||
|
data["saturation"] = device.color.saturation * 100
|
||||||
|
childDevice = addChildDevice(app.namespace, "LIFX Color Bulb", device.id, null, data)
|
||||||
} else {
|
} else {
|
||||||
childDevice = addChildDevice(app.namespace, "LIFX White Bulb", device.id, null, ["label": device.label, "completedSetup": true])
|
childDevice = addChildDevice(app.namespace, "LIFX White Bulb", device.id, null, data)
|
||||||
}
|
}
|
||||||
|
childDevice?.completedSetup = true
|
||||||
|
} else {
|
||||||
|
if (device.product.capabilities.has_color) {
|
||||||
|
sendEvent(name: "color", value: colorUtil.hslToHex((device.color.hue / 3.6) as int, (device.color.saturation * 100) as int))
|
||||||
|
sendEvent(name: "hue", value: device.color.hue / 3.6)
|
||||||
|
sendEvent(name: "saturation", value: device.color.saturation * 100)
|
||||||
|
}
|
||||||
|
childDevice.sendEvent(name: "label", value: device.label)
|
||||||
|
childDevice.sendEvent(name: "level", value: Math.round((device.brightness ?: 1) * 100))
|
||||||
|
childDevice.sendEvent(name: "switch.setLevel", value: Math.round((device.brightness ?: 1) * 100))
|
||||||
|
childDevice.sendEvent(name: "switch", value: device.power)
|
||||||
|
childDevice.sendEvent(name: "colorTemperature", value: device.color.kelvin)
|
||||||
|
childDevice.sendEvent(name: "model", value: device.product.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device.product.capabilities.has_color) {
|
|
||||||
childDevice.sendEvent(name: "color", value: colorUtil.hslToHex((device.color.hue / 3.6) as int, (device.color.saturation * 100) as int))
|
|
||||||
childDevice.sendEvent(name: "hue", value: device.color.hue / 3.6)
|
|
||||||
childDevice.sendEvent(name: "saturation", value: device.color.saturation * 100)
|
|
||||||
}
|
|
||||||
childDevice.sendEvent(name: "label", value: device.label)
|
|
||||||
childDevice.sendEvent(name: "level", value: Math.round((device.brightness ?: 1) * 100))
|
|
||||||
childDevice.sendEvent(name: "switch.setLevel", value: Math.round((device.brightness ?: 1) * 100))
|
|
||||||
childDevice.sendEvent(name: "switch", value: device.power)
|
|
||||||
childDevice.sendEvent(name: "colorTemperature", value: device.color.kelvin)
|
|
||||||
childDevice.sendEvent(name: "model", value: device.product.name)
|
|
||||||
|
|
||||||
if (state.devices[device.id] == null) {
|
if (state.devices[device.id] == null) {
|
||||||
// State missing, add it and set it to opposite status as current status to provoke event below
|
// State missing, add it and set it to opposite status as current status to provoke event below
|
||||||
state.devices[device.id] = [online: !device.connected]
|
state.devices[device.id] = [online : !device.connected]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state.devices[device.id]?.online && device.connected) {
|
if (!state.devices[device.id]?.online && device.connected) {
|
||||||
|
|||||||
Reference in New Issue
Block a user