mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-18 13:20:53 +00:00
Compare commits
33 Commits
MSA-985-1
...
MSA-1108-2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1736caebfe | ||
|
|
0fa363fa1a | ||
|
|
0c5840087b | ||
|
|
a6ee53641f | ||
|
|
c6818c8c2b | ||
|
|
6ac174c2f3 | ||
|
|
eb8d5ed4c9 | ||
|
|
7b5d618de8 | ||
|
|
c024e09fb8 | ||
|
|
e5841fb3cb | ||
|
|
805b870447 | ||
|
|
fe92f7ad19 | ||
|
|
10245315ee | ||
|
|
0b239d4686 | ||
|
|
9374290d64 | ||
|
|
ffcacb9da5 | ||
|
|
c45129170a | ||
|
|
53406ada8e | ||
|
|
ffd0dd1545 | ||
|
|
5c1236a21a | ||
|
|
0911651f71 | ||
|
|
9cc92b1987 | ||
|
|
1e27dc1824 | ||
|
|
4bf3679942 | ||
|
|
c714720578 | ||
|
|
281fc939ac | ||
|
|
633bef2ac5 | ||
|
|
a8357e7644 | ||
|
|
024a6cb698 | ||
|
|
62a965d90b | ||
|
|
515b268374 | ||
|
|
a103d437c2 | ||
|
|
bdd88deb99 |
@@ -7,9 +7,10 @@ apply plugin: 'smartthings-hipchat'
|
|||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "com.smartthings.deployment:executable-deployment-scripts:1.0.3"
|
classpath "com.smartthings.deployment:executable-deployment-scripts:1.0.6"
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
jcenter()
|
jcenter()
|
||||||
maven {
|
maven {
|
||||||
credentials {
|
credentials {
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ deployment:
|
|||||||
develop:
|
develop:
|
||||||
branch: master
|
branch: master
|
||||||
commands:
|
commands:
|
||||||
- ./gradlew deployArchives -PsmartThingsArtifactoryUserName=$ARTIFACTORY_USERNAME -PsmartThingsArtifactoryPassword=$ARTIFACTORY_PASSWORD -Ps3BucketName=$S3_BUCKET_NAME_PREPROD_DEV
|
- ./gradlew deployArchives -PsmartThingsArtifactoryUserName=$ARTIFACTORY_USERNAME -PsmartThingsArtifactoryPassword=$ARTIFACTORY_PASSWORD -Ps3Buckets="$S3_BUCKETS_DEV"
|
||||||
- ./gradlew hipchatSendNotification -PsmartThingsArtifactoryUserName=$ARTIFACTORY_USERNAME -PsmartThingsArtifactoryPassword=$ARTIFACTORY_PASSWORD -Pbranch=$CIRCLE_BRANCH
|
- ./gradlew hipchatSendNotification -PsmartThingsArtifactoryUserName=$ARTIFACTORY_USERNAME -PsmartThingsArtifactoryPassword=$ARTIFACTORY_PASSWORD -Pbranch=$CIRCLE_BRANCH
|
||||||
- ./gradlew hipchatShareFile -PsmartThingsArtifactoryUserName=$ARTIFACTORY_USERNAME -PsmartThingsArtifactoryPassword=$ARTIFACTORY_PASSWORD
|
- ./gradlew hipchatShareFile -PsmartThingsArtifactoryUserName=$ARTIFACTORY_USERNAME -PsmartThingsArtifactoryPassword=$ARTIFACTORY_PASSWORD
|
||||||
|
|
||||||
stage:
|
stage:
|
||||||
branch: staging
|
branch: staging
|
||||||
commands:
|
commands:
|
||||||
- ./gradlew deployArchives -PsmartThingsArtifactoryUserName=$ARTIFACTORY_USERNAME -PsmartThingsArtifactoryPassword=$ARTIFACTORY_PASSWORD -Ps3BucketName=$S3_BUCKET_NAME_PREPROD_STAGING
|
- ./gradlew deployArchives -PsmartThingsArtifactoryUserName=$ARTIFACTORY_USERNAME -PsmartThingsArtifactoryPassword=$ARTIFACTORY_PASSWORD -Ps3Buckets="$S3_BUCKETS_STAGE"
|
||||||
- ./gradlew hipchatSendNotification -PsmartThingsArtifactoryUserName=$ARTIFACTORY_USERNAME -PsmartThingsArtifactoryPassword=$ARTIFACTORY_PASSWORD -Pbranch=$CIRCLE_BRANCH
|
- ./gradlew hipchatSendNotification -PsmartThingsArtifactoryUserName=$ARTIFACTORY_USERNAME -PsmartThingsArtifactoryPassword=$ARTIFACTORY_PASSWORD -Pbranch=$CIRCLE_BRANCH
|
||||||
- ./gradlew hipchatShareFile -PsmartThingsArtifactoryUserName=$ARTIFACTORY_USERNAME -PsmartThingsArtifactoryPassword=$ARTIFACTORY_PASSWORD
|
- ./gradlew hipchatShareFile -PsmartThingsArtifactoryUserName=$ARTIFACTORY_USERNAME -PsmartThingsArtifactoryPassword=$ARTIFACTORY_PASSWORD
|
||||||
|
|||||||
227
devicetypes/smartthings/hue-bloom.src/hue-bloom.groovy
Normal file
227
devicetypes/smartthings/hue-bloom.src/hue-bloom.groovy
Normal file
@@ -0,0 +1,227 @@
|
|||||||
|
/**
|
||||||
|
* Hue Bloom
|
||||||
|
*
|
||||||
|
* Philips Hue Type "Color Light"
|
||||||
|
*
|
||||||
|
* Author: SmartThings
|
||||||
|
*/
|
||||||
|
|
||||||
|
// for the UI
|
||||||
|
metadata {
|
||||||
|
// Automatically generated. Make future change here.
|
||||||
|
definition (name: "Hue Bloom", namespace: "smartthings", author: "SmartThings") {
|
||||||
|
capability "Switch Level"
|
||||||
|
capability "Actuator"
|
||||||
|
capability "Color Control"
|
||||||
|
capability "Switch"
|
||||||
|
capability "Refresh"
|
||||||
|
capability "Sensor"
|
||||||
|
|
||||||
|
command "setAdjustedColor"
|
||||||
|
command "reset"
|
||||||
|
command "refresh"
|
||||||
|
}
|
||||||
|
|
||||||
|
simulator {
|
||||||
|
// TODO: define status and reply messages here
|
||||||
|
}
|
||||||
|
|
||||||
|
tiles (scale: 2){
|
||||||
|
multiAttributeTile(name:"rich-control", type: "lighting", width: 6, height: 4, canChangeIcon: true){
|
||||||
|
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
|
||||||
|
attributeState "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#00A0DC", nextState:"turningOff"
|
||||||
|
attributeState "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#C6C7CC", nextState:"turningOn"
|
||||||
|
attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#00A0DC", nextState:"turningOff"
|
||||||
|
attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#C6C7CC", nextState:"turningOn"
|
||||||
|
}
|
||||||
|
tileAttribute ("device.level", key: "SLIDER_CONTROL") {
|
||||||
|
attributeState "level", action:"switch level.setLevel", range:"(0..100)"
|
||||||
|
}
|
||||||
|
tileAttribute ("device.level", key: "SECONDARY_CONTROL") {
|
||||||
|
attributeState "level", label: 'Level ${currentValue}%'
|
||||||
|
}
|
||||||
|
tileAttribute ("device.color", key: "COLOR_CONTROL") {
|
||||||
|
attributeState "color", action:"setAdjustedColor"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
standardTile("reset", "device.reset", height: 2, width: 2, inactiveLabel: false, decoration: "flat") {
|
||||||
|
state "default", label:"Reset Color", action:"reset", icon:"st.lights.philips.hue-single"
|
||||||
|
}
|
||||||
|
|
||||||
|
standardTile("refresh", "device.refresh", height: 2, width: 2, inactiveLabel: false, decoration: "flat") {
|
||||||
|
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
|
||||||
|
}
|
||||||
|
|
||||||
|
main(["rich-control"])
|
||||||
|
details(["rich-control", "colorTempSliderControl", "colorTemp", "reset", "refresh"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse events into attributes
|
||||||
|
def parse(description) {
|
||||||
|
log.debug "parse() - $description"
|
||||||
|
def results = []
|
||||||
|
|
||||||
|
def map = description
|
||||||
|
if (description instanceof String) {
|
||||||
|
log.debug "Hue Bulb stringToMap - ${map}"
|
||||||
|
map = stringToMap(description)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map?.name && map?.value) {
|
||||||
|
results << createEvent(name: "${map?.name}", value: "${map?.value}")
|
||||||
|
}
|
||||||
|
results
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle commands
|
||||||
|
void on() {
|
||||||
|
log.trace parent.on(this)
|
||||||
|
sendEvent(name: "switch", value: "on")
|
||||||
|
}
|
||||||
|
|
||||||
|
void off() {
|
||||||
|
log.trace parent.off(this)
|
||||||
|
sendEvent(name: "switch", value: "off")
|
||||||
|
}
|
||||||
|
|
||||||
|
void nextLevel() {
|
||||||
|
def level = device.latestValue("level") as Integer ?: 0
|
||||||
|
if (level <= 100) {
|
||||||
|
level = Math.min(25 * (Math.round(level / 25) + 1), 100) as Integer
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
level = 25
|
||||||
|
}
|
||||||
|
setLevel(level)
|
||||||
|
}
|
||||||
|
|
||||||
|
void setLevel(percent) {
|
||||||
|
log.debug "Executing 'setLevel'"
|
||||||
|
if (verifyPercent(percent)) {
|
||||||
|
parent.setLevel(this, percent)
|
||||||
|
sendEvent(name: "level", value: percent, descriptionText: "Level has changed to ${percent}%")
|
||||||
|
sendEvent(name: "switch", value: "on")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setSaturation(percent) {
|
||||||
|
log.debug "Executing 'setSaturation'"
|
||||||
|
if (verifyPercent(percent)) {
|
||||||
|
parent.setSaturation(this, percent)
|
||||||
|
sendEvent(name: "saturation", value: percent, displayed: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setHue(percent) {
|
||||||
|
log.debug "Executing 'setHue'"
|
||||||
|
if (verifyPercent(percent)) {
|
||||||
|
parent.setHue(this, percent)
|
||||||
|
sendEvent(name: "hue", value: percent, displayed: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setColor(value) {
|
||||||
|
log.debug "setColor: ${value}, $this"
|
||||||
|
def events = []
|
||||||
|
def validValues = [:]
|
||||||
|
|
||||||
|
if (verifyPercent(value.hue)) {
|
||||||
|
events << createEvent(name: "hue", value: value.hue, displayed: false)
|
||||||
|
validValues.hue = value.hue
|
||||||
|
}
|
||||||
|
if (verifyPercent(value.saturation)) {
|
||||||
|
events << createEvent(name: "saturation", value: value.saturation, displayed: false)
|
||||||
|
validValues.saturation = value.saturation
|
||||||
|
}
|
||||||
|
if (value.hex != null) {
|
||||||
|
if (value.hex ==~ /^\#([A-Fa-f0-9]){6}$/) {
|
||||||
|
events << createEvent(name: "color", value: value.hex)
|
||||||
|
validValues.hex = value.hex
|
||||||
|
} else {
|
||||||
|
log.warn "$value.hex is not a valid color"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (verifyPercent(value.level)) {
|
||||||
|
events << createEvent(name: "level", value: value.level, descriptionText: "Level has changed to ${value.level}%")
|
||||||
|
validValues.level = value.level
|
||||||
|
}
|
||||||
|
if (value.switch == "off" || (value.level != null && value.level <= 0)) {
|
||||||
|
events << createEvent(name: "switch", value: "off")
|
||||||
|
validValues.switch = "off"
|
||||||
|
} else {
|
||||||
|
events << createEvent(name: "switch", value: "on")
|
||||||
|
validValues.switch = "on"
|
||||||
|
}
|
||||||
|
if (!events.isEmpty()) {
|
||||||
|
parent.setColor(this, validValues)
|
||||||
|
}
|
||||||
|
events.each {
|
||||||
|
sendEvent(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
log.debug "Executing 'reset'"
|
||||||
|
def value = [level:100, saturation:56, hue:23]
|
||||||
|
setAdjustedColor(value)
|
||||||
|
parent.poll()
|
||||||
|
}
|
||||||
|
|
||||||
|
void setAdjustedColor(value) {
|
||||||
|
if (value) {
|
||||||
|
log.trace "setAdjustedColor: ${value}"
|
||||||
|
def adjusted = value + [:]
|
||||||
|
adjusted.hue = adjustOutgoingHue(value.hue)
|
||||||
|
// Needed because color picker always sends 100
|
||||||
|
adjusted.level = null
|
||||||
|
setColor(adjusted)
|
||||||
|
} else {
|
||||||
|
log.warn "Invalid color input"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setColorTemperature(value) {
|
||||||
|
if (value) {
|
||||||
|
log.trace "setColorTemperature: ${value}k"
|
||||||
|
parent.setColorTemperature(this, value)
|
||||||
|
sendEvent(name: "colorTemperature", value: value)
|
||||||
|
sendEvent(name: "switch", value: "on")
|
||||||
|
} else {
|
||||||
|
log.warn "Invalid color temperature"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void refresh() {
|
||||||
|
log.debug "Executing 'refresh'"
|
||||||
|
parent.manualRefresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
def adjustOutgoingHue(percent) {
|
||||||
|
def adjusted = percent
|
||||||
|
if (percent > 31) {
|
||||||
|
if (percent < 63.0) {
|
||||||
|
adjusted = percent + (7 * (percent -30 ) / 32)
|
||||||
|
}
|
||||||
|
else if (percent < 73.0) {
|
||||||
|
adjusted = 69 + (5 * (percent - 62) / 10)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
adjusted = percent + (2 * (100 - percent) / 28)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info "percent: $percent, adjusted: $adjusted"
|
||||||
|
adjusted
|
||||||
|
}
|
||||||
|
|
||||||
|
def verifyPercent(percent) {
|
||||||
|
if (percent == null)
|
||||||
|
return false
|
||||||
|
else if (percent >= 0 && percent <= 100) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
log.warn "$percent is not 0-100"
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* Hue Bulb
|
* Hue Bulb
|
||||||
*
|
*
|
||||||
|
* Philips Hue Type "Extended Color Light"
|
||||||
|
*
|
||||||
* Author: SmartThings
|
* Author: SmartThings
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -69,11 +71,13 @@ metadata {
|
|||||||
def parse(description) {
|
def parse(description) {
|
||||||
log.debug "parse() - $description"
|
log.debug "parse() - $description"
|
||||||
def results = []
|
def results = []
|
||||||
|
|
||||||
def map = description
|
def map = description
|
||||||
if (description instanceof String) {
|
if (description instanceof String) {
|
||||||
log.debug "Hue Bulb stringToMap - ${map}"
|
log.debug "Hue Bulb stringToMap - ${map}"
|
||||||
map = stringToMap(description)
|
map = stringToMap(description)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (map?.name && map?.value) {
|
if (map?.name && map?.value) {
|
||||||
results << createEvent(name: "${map?.name}", value: "${map?.value}")
|
results << createEvent(name: "${map?.name}", value: "${map?.value}")
|
||||||
}
|
}
|
||||||
@@ -103,62 +107,104 @@ void nextLevel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setLevel(percent) {
|
void setLevel(percent) {
|
||||||
log.debug "Executing 'setLevel'"
|
log.debug "Executing 'setLevel'"
|
||||||
parent.setLevel(this, percent)
|
if (verifyPercent(percent)) {
|
||||||
sendEvent(name: "level", value: percent, descriptionText: "Level has changed to ${percent}%")
|
parent.setLevel(this, percent)
|
||||||
|
sendEvent(name: "level", value: percent, descriptionText: "Level has changed to ${percent}%")
|
||||||
|
sendEvent(name: "switch", value: "on")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSaturation(percent) {
|
void setSaturation(percent) {
|
||||||
log.debug "Executing 'setSaturation'"
|
log.debug "Executing 'setSaturation'"
|
||||||
parent.setSaturation(this, percent)
|
if (verifyPercent(percent)) {
|
||||||
sendEvent(name: "saturation", value: percent, displayed: false)
|
parent.setSaturation(this, percent)
|
||||||
|
sendEvent(name: "saturation", value: percent, displayed: false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setHue(percent) {
|
void setHue(percent) {
|
||||||
log.debug "Executing 'setHue'"
|
log.debug "Executing 'setHue'"
|
||||||
parent.setHue(this, percent)
|
if (verifyPercent(percent)) {
|
||||||
sendEvent(name: "hue", value: percent, displayed: false)
|
parent.setHue(this, percent)
|
||||||
|
sendEvent(name: "hue", value: percent, displayed: false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setColor(value) {
|
void setColor(value) {
|
||||||
log.debug "setColor: ${value}, $this"
|
log.debug "setColor: ${value}, $this"
|
||||||
parent.setColor(this, value)
|
def events = []
|
||||||
if (value.hue) { sendEvent(name: "hue", value: value.hue, displayed: false)}
|
def validValues = [:]
|
||||||
if (value.saturation) { sendEvent(name: "saturation", value: value.saturation, displayed: false)}
|
|
||||||
if (value.hex) { sendEvent(name: "color", value: value.hex)}
|
if (verifyPercent(value.hue)) {
|
||||||
if (value.level) { sendEvent(name: "level", value: value.level, descriptionText: "Level has changed to ${value.level}%")}
|
events << createEvent(name: "hue", value: value.hue, displayed: false)
|
||||||
sendEvent(name: "switch", value: "on")
|
validValues.hue = value.hue
|
||||||
|
}
|
||||||
|
if (verifyPercent(value.saturation)) {
|
||||||
|
events << createEvent(name: "saturation", value: value.saturation, displayed: false)
|
||||||
|
validValues.saturation = value.saturation
|
||||||
|
}
|
||||||
|
if (value.hex != null) {
|
||||||
|
if (value.hex ==~ /^\#([A-Fa-f0-9]){6}$/) {
|
||||||
|
events << createEvent(name: "color", value: value.hex)
|
||||||
|
validValues.hex = value.hex
|
||||||
|
} else {
|
||||||
|
log.warn "$value.hex is not a valid color"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (verifyPercent(value.level)) {
|
||||||
|
events << createEvent(name: "level", value: value.level, descriptionText: "Level has changed to ${value.level}%")
|
||||||
|
validValues.level = value.level
|
||||||
|
}
|
||||||
|
if (value.switch == "off" || (value.level != null && value.level <= 0)) {
|
||||||
|
events << createEvent(name: "switch", value: "off")
|
||||||
|
validValues.switch = "off"
|
||||||
|
} else {
|
||||||
|
events << createEvent(name: "switch", value: "on")
|
||||||
|
validValues.switch = "on"
|
||||||
|
}
|
||||||
|
if (!events.isEmpty()) {
|
||||||
|
parent.setColor(this, validValues)
|
||||||
|
}
|
||||||
|
events.each {
|
||||||
|
sendEvent(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
log.debug "Executing 'reset'"
|
log.debug "Executing 'reset'"
|
||||||
def value = [level:100, saturation:56, hue:23]
|
def value = [level:100, saturation:56, hue:23]
|
||||||
setAdjustedColor(value)
|
setAdjustedColor(value)
|
||||||
parent.poll()
|
parent.poll()
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAdjustedColor(value) {
|
void setAdjustedColor(value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
log.trace "setAdjustedColor: ${value}"
|
log.trace "setAdjustedColor: ${value}"
|
||||||
def adjusted = value + [:]
|
def adjusted = value + [:]
|
||||||
adjusted.hue = adjustOutgoingHue(value.hue)
|
adjusted.hue = adjustOutgoingHue(value.hue)
|
||||||
// Needed because color picker always sends 100
|
// Needed because color picker always sends 100
|
||||||
adjusted.level = null
|
adjusted.level = null
|
||||||
setColor(adjusted)
|
setColor(adjusted)
|
||||||
|
} else {
|
||||||
|
log.warn "Invalid color input"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setColorTemperature(value) {
|
void setColorTemperature(value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
log.trace "setColorTemperature: ${value}k"
|
log.trace "setColorTemperature: ${value}k"
|
||||||
parent.setColorTemperature(this, value)
|
parent.setColorTemperature(this, value)
|
||||||
sendEvent(name: "colorTemperature", value: value)
|
sendEvent(name: "colorTemperature", value: value)
|
||||||
}
|
sendEvent(name: "switch", value: "on")
|
||||||
|
} else {
|
||||||
|
log.warn "Invalid color temperature"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh() {
|
void refresh() {
|
||||||
log.debug "Executing 'refresh'"
|
log.debug "Executing 'refresh'"
|
||||||
parent.manualRefresh()
|
parent.manualRefresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
def adjustOutgoingHue(percent) {
|
def adjustOutgoingHue(percent) {
|
||||||
@@ -177,3 +223,14 @@ def adjustOutgoingHue(percent) {
|
|||||||
log.info "percent: $percent, adjusted: $adjusted"
|
log.info "percent: $percent, adjusted: $adjusted"
|
||||||
adjusted
|
adjusted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def verifyPercent(percent) {
|
||||||
|
if (percent == null)
|
||||||
|
return false
|
||||||
|
else if (percent >= 0 && percent <= 100) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
log.warn "$percent is not 0-100"
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* Hue Lux Bulb
|
* Hue Lux Bulb
|
||||||
*
|
*
|
||||||
|
* Philips Hue Type "Dimmable Light"
|
||||||
|
*
|
||||||
* Author: SmartThings
|
* Author: SmartThings
|
||||||
*/
|
*/
|
||||||
// for the UI
|
// for the UI
|
||||||
@@ -23,10 +25,10 @@ metadata {
|
|||||||
tiles(scale: 2) {
|
tiles(scale: 2) {
|
||||||
multiAttributeTile(name:"rich-control", type: "lighting", canChangeIcon: true){
|
multiAttributeTile(name:"rich-control", type: "lighting", canChangeIcon: true){
|
||||||
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
|
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
|
||||||
attributeState "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff"
|
attributeState "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#00A0DC", nextState:"turningOff"
|
||||||
attributeState "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
|
attributeState "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#C6C7CC", nextState:"turningOn"
|
||||||
attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff"
|
attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#00A0DC", nextState:"turningOff"
|
||||||
attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
|
attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#C6C7CC", nextState:"turningOn"
|
||||||
}
|
}
|
||||||
tileAttribute ("device.level", key: "SLIDER_CONTROL") {
|
tileAttribute ("device.level", key: "SLIDER_CONTROL") {
|
||||||
attributeState "level", action:"switch level.setLevel", range:"(0..100)"
|
attributeState "level", action:"switch level.setLevel", range:"(0..100)"
|
||||||
@@ -68,19 +70,24 @@ def parse(description) {
|
|||||||
|
|
||||||
// handle commands
|
// handle commands
|
||||||
void on() {
|
void on() {
|
||||||
parent.on(this)
|
log.trace parent.on(this)
|
||||||
sendEvent(name: "switch", value: "on")
|
sendEvent(name: "switch", value: "on")
|
||||||
}
|
}
|
||||||
|
|
||||||
void off() {
|
void off() {
|
||||||
parent.off(this)
|
log.trace parent.off(this)
|
||||||
sendEvent(name: "switch", value: "off")
|
sendEvent(name: "switch", value: "off")
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLevel(percent) {
|
void setLevel(percent) {
|
||||||
log.debug "Executing 'setLevel'"
|
log.debug "Executing 'setLevel'"
|
||||||
parent.setLevel(this, percent)
|
if (percent != null && percent >= 0 && percent <= 100) {
|
||||||
sendEvent(name: "level", value: percent)
|
parent.setLevel(this, percent)
|
||||||
|
sendEvent(name: "level", value: percent)
|
||||||
|
sendEvent(name: "switch", value: "on")
|
||||||
|
} else {
|
||||||
|
log.warn "$percent is not 0-100"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh() {
|
void refresh() {
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ private List parseContactMessage(String description) {
|
|||||||
parts.each { part ->
|
parts.each { part ->
|
||||||
part = part.trim()
|
part = part.trim()
|
||||||
if (part.startsWith('contactState:')) {
|
if (part.startsWith('contactState:')) {
|
||||||
results << getContactResult(part, description)
|
results.addAll(getContactResult(part, description))
|
||||||
}
|
}
|
||||||
else if (part.startsWith('accelerationState:')) {
|
else if (part.startsWith('accelerationState:')) {
|
||||||
results << getAccelerationResult(part, description)
|
results << getAccelerationResult(part, description)
|
||||||
@@ -316,7 +316,7 @@ private List getContactResult(part, description) {
|
|||||||
results
|
results
|
||||||
}
|
}
|
||||||
|
|
||||||
private getAccelerationResult(part, description) {
|
private Map getAccelerationResult(part, description) {
|
||||||
def name = "acceleration"
|
def name = "acceleration"
|
||||||
def value = part.endsWith("1") ? "active" : "inactive"
|
def value = part.endsWith("1") ? "active" : "inactive"
|
||||||
def linkText = getLinkText(device)
|
def linkText = getLinkText(device)
|
||||||
@@ -335,7 +335,7 @@ private getAccelerationResult(part, description) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
private getTempResult(part, description) {
|
private Map getTempResult(part, description) {
|
||||||
def name = "temperature"
|
def name = "temperature"
|
||||||
def temperatureScale = getTemperatureScale()
|
def temperatureScale = getTemperatureScale()
|
||||||
def value = zigbee.parseSmartThingsTemperatureValue(part, "temp: ", temperatureScale)
|
def value = zigbee.parseSmartThingsTemperatureValue(part, "temp: ", temperatureScale)
|
||||||
@@ -360,7 +360,7 @@ private getTempResult(part, description) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
private getXyzResult(results, description) {
|
private Map getXyzResult(results, description) {
|
||||||
def name = "threeAxis"
|
def name = "threeAxis"
|
||||||
def value = "${results.x},${results.y},${results.z}"
|
def value = "${results.x},${results.y},${results.z}"
|
||||||
def linkText = getLinkText(device)
|
def linkText = getLinkText(device)
|
||||||
@@ -379,7 +379,7 @@ private getXyzResult(results, description) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
private getBatteryResult(part, description) {
|
private Map getBatteryResult(part, description) {
|
||||||
def batteryDivisor = description.split(",").find {it.split(":")[0].trim() == "batteryDivisor"} ? description.split(",").find {it.split(":")[0].trim() == "batteryDivisor"}.split(":")[1].trim() : null
|
def batteryDivisor = description.split(",").find {it.split(":")[0].trim() == "batteryDivisor"} ? description.split(",").find {it.split(":")[0].trim() == "batteryDivisor"}.split(":")[1].trim() : null
|
||||||
def name = "battery"
|
def name = "battery"
|
||||||
def value = zigbee.parseSmartThingsBatteryValue(part, batteryDivisor)
|
def value = zigbee.parseSmartThingsBatteryValue(part, batteryDivisor)
|
||||||
@@ -400,7 +400,7 @@ private getBatteryResult(part, description) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
private getRssiResult(part, description, lastHop=false) {
|
private Map getRssiResult(part, description, lastHop=false) {
|
||||||
def name = lastHop ? "lastHopRssi" : "rssi"
|
def name = lastHop ? "lastHopRssi" : "rssi"
|
||||||
def valueString = part.split(":")[1].trim()
|
def valueString = part.split(":")[1].trim()
|
||||||
def value = (Integer.parseInt(valueString) - 128).toString()
|
def value = (Integer.parseInt(valueString) - 128).toString()
|
||||||
@@ -431,7 +431,7 @@ private getRssiResult(part, description, lastHop=false) {
|
|||||||
* Note: To make the signal strength indicator more accurate, we could combine
|
* Note: To make the signal strength indicator more accurate, we could combine
|
||||||
* LQI with RSSI.
|
* LQI with RSSI.
|
||||||
*/
|
*/
|
||||||
private getLqiResult(part, description, lastHop=false) {
|
private Map getLqiResult(part, description, lastHop=false) {
|
||||||
def name = lastHop ? "lastHopLqi" : "lqi"
|
def name = lastHop ? "lastHopLqi" : "lqi"
|
||||||
def valueString = part.split(":")[1].trim()
|
def valueString = part.split(":")[1].trim()
|
||||||
def percentageOf = 255
|
def percentageOf = 255
|
||||||
|
|||||||
@@ -56,21 +56,17 @@ metadata {
|
|||||||
def parse(String description) {
|
def parse(String description) {
|
||||||
log.debug "description is $description"
|
log.debug "description is $description"
|
||||||
|
|
||||||
def resultMap = zigbee.getKnownDescription(description)
|
def event = zigbee.getEvent(description)
|
||||||
if (resultMap) {
|
if (event) {
|
||||||
log.info resultMap
|
log.info event
|
||||||
if (resultMap.type == "update") {
|
if (event.name == "power") {
|
||||||
log.info "$device updates: ${resultMap.value}"
|
|
||||||
}
|
|
||||||
else if (resultMap.type == "power") {
|
|
||||||
def powerValue
|
|
||||||
if (device.getDataValue("manufacturer") != "OSRAM") { //OSRAM devices do not reliably update power
|
if (device.getDataValue("manufacturer") != "OSRAM") { //OSRAM devices do not reliably update power
|
||||||
powerValue = (resultMap.value as Integer)/10 //TODO: The divisor value needs to be set as part of configuration
|
event.value = (event.value as Integer) / 10 //TODO: The divisor value needs to be set as part of configuration
|
||||||
sendEvent(name: "power", value: powerValue)
|
sendEvent(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sendEvent(name: resultMap.type, value: resultMap.value)
|
sendEvent(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -51,15 +51,9 @@ metadata {
|
|||||||
def parse(String description) {
|
def parse(String description) {
|
||||||
log.debug "description is $description"
|
log.debug "description is $description"
|
||||||
|
|
||||||
def resultMap = zigbee.getKnownDescription(description)
|
def event = zigbee.getEvent(description)
|
||||||
if (resultMap) {
|
if (event) {
|
||||||
log.info resultMap
|
sendEvent(event)
|
||||||
if (resultMap.type == "update") {
|
|
||||||
log.info "$device updates: ${resultMap.value}"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sendEvent(name: resultMap.type, value: resultMap.value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.warn "DID NOT PARSE MESSAGE for description : $description"
|
log.warn "DID NOT PARSE MESSAGE for description : $description"
|
||||||
|
|||||||
@@ -83,32 +83,19 @@ def uninstalled() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def configure() {
|
def configure() {
|
||||||
/*
|
|
||||||
def cmds =
|
def cmds =
|
||||||
zigbee.configSetup("${CLUSTER_DOORLOCK}", "${DOORLOCK_ATTR_LOCKSTATE}",
|
zigbee.configureReporting(CLUSTER_DOORLOCK, DOORLOCK_ATTR_LOCKSTATE,
|
||||||
"${TYPE_ENUM8}", 0, 3600, "{01}") +
|
TYPE_ENUM8, 0, 3600, null) +
|
||||||
zigbee.configSetup("${CLUSTER_POWER}", "${POWER_ATTR_BATTERY_PERCENTAGE_REMAINING}",
|
zigbee.configureReporting(CLUSTER_POWER, POWER_ATTR_BATTERY_PERCENTAGE_REMAINING,
|
||||||
"${TYPE_U8}", 600, 21600, "{01}")
|
TYPE_U8, 600, 21600, 0x01)
|
||||||
*/
|
|
||||||
def zigbeeId = device.zigbeeId
|
|
||||||
def cmds =
|
|
||||||
[
|
|
||||||
"zdo bind 0x${device.deviceNetworkId} 0x${device.endpointId} 1 ${CLUSTER_DOORLOCK} {$zigbeeId} {}", "delay 200",
|
|
||||||
"zcl global send-me-a-report ${CLUSTER_DOORLOCK} ${DOORLOCK_ATTR_LOCKSTATE} ${TYPE_ENUM8} 0 3600 {01}", "delay 200",
|
|
||||||
"send 0x${device.deviceNetworkId} 1 0x${device.endpointId}", "delay 200",
|
|
||||||
|
|
||||||
"zdo bind 0x${device.deviceNetworkId} 0x${device.endpointId} 1 ${CLUSTER_POWER} {$zigbeeId} {}", "delay 200",
|
|
||||||
"zcl global send-me-a-report ${CLUSTER_POWER} ${POWER_ATTR_BATTERY_PERCENTAGE_REMAINING} ${TYPE_U8} 600 21600 {01}", "delay 200",
|
|
||||||
"send 0x${device.deviceNetworkId} 1 0x${device.endpointId}", "delay 200",
|
|
||||||
]
|
|
||||||
log.info "configure() --- cmds: $cmds"
|
log.info "configure() --- cmds: $cmds"
|
||||||
return cmds + refresh() // send refresh cmds as part of config
|
return cmds + refresh() // send refresh cmds as part of config
|
||||||
}
|
}
|
||||||
|
|
||||||
def refresh() {
|
def refresh() {
|
||||||
def cmds =
|
def cmds =
|
||||||
zigbee.refreshData("${CLUSTER_DOORLOCK}", "${DOORLOCK_ATTR_LOCKSTATE}") +
|
zigbee.readAttribute(CLUSTER_DOORLOCK, DOORLOCK_ATTR_LOCKSTATE) +
|
||||||
zigbee.refreshData("${CLUSTER_POWER}", "${POWER_ATTR_BATTERY_PERCENTAGE_REMAINING}")
|
zigbee.readAttribute(CLUSTER_POWER, POWER_ATTR_BATTERY_PERCENTAGE_REMAINING)
|
||||||
log.info "refresh() --- cmds: $cmds"
|
log.info "refresh() --- cmds: $cmds"
|
||||||
return cmds
|
return cmds
|
||||||
}
|
}
|
||||||
@@ -121,34 +108,27 @@ def parse(String description) {
|
|||||||
map = parseReportAttributeMessage(description)
|
map = parseReportAttributeMessage(description)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug "parse() --- Parse returned $map"
|
|
||||||
def result = map ? createEvent(map) : null
|
def result = map ? createEvent(map) : null
|
||||||
|
log.debug "parse() --- returned: $result"
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock capability commands
|
// Lock capability commands
|
||||||
def lock() {
|
def lock() {
|
||||||
//def cmds = zigbee.zigbeeCommand("${CLUSTER_DOORLOCK}", "${DOORLOCK_CMD_LOCK_DOOR}", "{}")
|
def cmds = zigbee.command(CLUSTER_DOORLOCK, DOORLOCK_CMD_LOCK_DOOR)
|
||||||
//log.info "lock() -- cmds: $cmds"
|
log.info "lock() -- cmds: $cmds"
|
||||||
//return cmds
|
return cmds
|
||||||
"st cmd 0x${device.deviceNetworkId} 0x${device.endpointId} ${CLUSTER_DOORLOCK} ${DOORLOCK_CMD_LOCK_DOOR} {}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def unlock() {
|
def unlock() {
|
||||||
//def cmds = zigbee.zigbeeCommand("${CLUSTER_DOORLOCK}", "${DOORLOCK_CMD_UNLOCK_DOOR}", "{}")
|
def cmds = zigbee.command(CLUSTER_DOORLOCK, DOORLOCK_CMD_UNLOCK_DOOR)
|
||||||
//log.info "unlock() -- cmds: $cmds"
|
log.info "unlock() -- cmds: $cmds"
|
||||||
//return cmds
|
return cmds
|
||||||
"st cmd 0x${device.deviceNetworkId} 0x${device.endpointId} ${CLUSTER_DOORLOCK} ${DOORLOCK_CMD_UNLOCK_DOOR} {}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private methods
|
// Private methods
|
||||||
private Map parseReportAttributeMessage(String description) {
|
private Map parseReportAttributeMessage(String description) {
|
||||||
log.trace "parseReportAttributeMessage() --- description: $description"
|
|
||||||
|
|
||||||
Map descMap = zigbee.parseDescriptionAsMap(description)
|
Map descMap = zigbee.parseDescriptionAsMap(description)
|
||||||
|
|
||||||
log.debug "parseReportAttributeMessage() --- descMap: $descMap"
|
|
||||||
|
|
||||||
Map resultMap = [:]
|
Map resultMap = [:]
|
||||||
if (descMap.clusterInt == CLUSTER_POWER && descMap.attrInt == POWER_ATTR_BATTERY_PERCENTAGE_REMAINING) {
|
if (descMap.clusterInt == CLUSTER_POWER && descMap.attrInt == POWER_ATTR_BATTERY_PERCENTAGE_REMAINING) {
|
||||||
resultMap.name = "battery"
|
resultMap.name = "battery"
|
||||||
@@ -156,18 +136,24 @@ private Map parseReportAttributeMessage(String description) {
|
|||||||
if (device.getDataValue("manufacturer") == "Yale") { //Handling issue with Yale locks incorrect battery reporting
|
if (device.getDataValue("manufacturer") == "Yale") { //Handling issue with Yale locks incorrect battery reporting
|
||||||
resultMap.value = Integer.parseInt(descMap.value, 16)
|
resultMap.value = Integer.parseInt(descMap.value, 16)
|
||||||
}
|
}
|
||||||
log.info "parseReportAttributeMessage() --- battery: ${resultMap.value}"
|
|
||||||
}
|
}
|
||||||
else if (descMap.clusterInt == CLUSTER_DOORLOCK && descMap.attrInt == DOORLOCK_ATTR_LOCKSTATE) {
|
else if (descMap.clusterInt == CLUSTER_DOORLOCK && descMap.attrInt == DOORLOCK_ATTR_LOCKSTATE) {
|
||||||
def value = Integer.parseInt(descMap.value, 16)
|
def value = Integer.parseInt(descMap.value, 16)
|
||||||
|
def linkText = getLinkText(device)
|
||||||
resultMap.name = "lock"
|
resultMap.name = "lock"
|
||||||
resultMap.putAll([0:["value":"unknown",
|
if (value == 0) {
|
||||||
"descriptionText":"Not fully locked"],
|
resultMap.value = "unknown"
|
||||||
1:["value":"locked"],
|
resultMap.descriptionText = "${linkText} is not fully locked"
|
||||||
2:["value":"unlocked"]].get(value,
|
} else if (value == 1) {
|
||||||
["value":"unknown",
|
resultMap.value = "locked"
|
||||||
"descriptionText":"Unknown lock state"]))
|
resultMap.descriptionText = "${linkText} is locked"
|
||||||
log.info "parseReportAttributeMessage() --- lock: ${resultMap.value}"
|
} else if (value == 2) {
|
||||||
|
resultMap.value = "unlocked"
|
||||||
|
resultMap.descriptionText = "${linkText} is unlocked"
|
||||||
|
} else {
|
||||||
|
resultMap.value = "unknown"
|
||||||
|
resultMap.descriptionText = "${linkText} is in unknown lock state"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.debug "parseReportAttributeMessage() --- ignoring attribute"
|
log.debug "parseReportAttributeMessage() --- ignoring attribute"
|
||||||
|
|||||||
@@ -51,22 +51,15 @@ metadata {
|
|||||||
// Parse incoming device messages to generate events
|
// Parse incoming device messages to generate events
|
||||||
def parse(String description) {
|
def parse(String description) {
|
||||||
log.debug "description is $description"
|
log.debug "description is $description"
|
||||||
|
def event = zigbee.getEvent(description)
|
||||||
def resultMap = zigbee.getKnownDescription(description)
|
if (event) {
|
||||||
if (resultMap) {
|
if (event.name == "power") {
|
||||||
log.info resultMap
|
|
||||||
if (resultMap.type == "update") {
|
|
||||||
log.info "$device updates: ${resultMap.value}"
|
|
||||||
}
|
|
||||||
else if (resultMap.type == "power") {
|
|
||||||
def powerValue
|
def powerValue
|
||||||
if (device.getDataValue("manufacturer") != "OSRAM") { //OSRAM devices do not reliably update power
|
powerValue = (event.value as Integer)/10 //TODO: The divisor value needs to be set as part of configuration
|
||||||
powerValue = (resultMap.value as Integer)/10 //TODO: The divisor value needs to be set as part of configuration
|
sendEvent(name: "power", value: powerValue)
|
||||||
sendEvent(name: "power", value: powerValue)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sendEvent(name: resultMap.type, value: resultMap.value)
|
sendEvent(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -53,16 +53,9 @@ metadata {
|
|||||||
// Parse incoming device messages to generate events
|
// Parse incoming device messages to generate events
|
||||||
def parse(String description) {
|
def parse(String description) {
|
||||||
log.debug "description is $description"
|
log.debug "description is $description"
|
||||||
|
def event = zigbee.getEvent(description)
|
||||||
def resultMap = zigbee.getKnownDescription(description)
|
if (event) {
|
||||||
if (resultMap) {
|
sendEvent(event)
|
||||||
log.info resultMap
|
|
||||||
if (resultMap.type == "update") {
|
|
||||||
log.info "$device updates: ${resultMap.value}"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sendEvent(name: resultMap.type, value: resultMap.value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.warn "DID NOT PARSE MESSAGE for description : $description"
|
log.warn "DID NOT PARSE MESSAGE for description : $description"
|
||||||
|
|||||||
@@ -73,16 +73,9 @@ metadata {
|
|||||||
// Parse incoming device messages to generate events
|
// Parse incoming device messages to generate events
|
||||||
def parse(String description) {
|
def parse(String description) {
|
||||||
log.debug "description is $description"
|
log.debug "description is $description"
|
||||||
|
def event = zigbee.getEvent(description)
|
||||||
def finalResult = zigbee.getKnownDescription(description)
|
if (event) {
|
||||||
if (finalResult) {
|
sendEvent(event)
|
||||||
log.info finalResult
|
|
||||||
if (finalResult.type == "update") {
|
|
||||||
log.info "$device updates: ${finalResult.value}"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sendEvent(name: finalResult.type, value: finalResult.value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.warn "DID NOT PARSE MESSAGE for description : $description"
|
log.warn "DID NOT PARSE MESSAGE for description : $description"
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ def retypeBasedOnMSR() {
|
|||||||
break
|
break
|
||||||
case "011F-0001-0001": // Schlage motion
|
case "011F-0001-0001": // Schlage motion
|
||||||
case "014A-0001-0001": // Ecolink motion
|
case "014A-0001-0001": // Ecolink motion
|
||||||
|
case "014A-0004-0001": // Ecolink motion +
|
||||||
case "0060-0001-0002": // Everspring SP814
|
case "0060-0001-0002": // Everspring SP814
|
||||||
case "0060-0001-0003": // Everspring HSP02
|
case "0060-0001-0003": // Everspring HSP02
|
||||||
case "011A-0601-0901": // Enerwave ZWN-BPC
|
case "011A-0601-0901": // Enerwave ZWN-BPC
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ private sendDeveloperReq() {
|
|||||||
headers: [
|
headers: [
|
||||||
HOST: host
|
HOST: host
|
||||||
],
|
],
|
||||||
body: [devicetype: "$token-0", username: "$token-0"]], "${selectedHue}"))
|
body: [devicetype: "$token-0"]], "${selectedHue}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
private discoverHueBulbs() {
|
private discoverHueBulbs() {
|
||||||
@@ -289,7 +289,7 @@ def bulbListHandler(hub, data = "") {
|
|||||||
def object = new groovy.json.JsonSlurper().parseText(data)
|
def object = new groovy.json.JsonSlurper().parseText(data)
|
||||||
object.each { k,v ->
|
object.each { k,v ->
|
||||||
if (v instanceof Map)
|
if (v instanceof Map)
|
||||||
bulbs[k] = [id: k, name: v.name, type: v.type, hub:hub]
|
bulbs[k] = [id: k, name: v.name, type: v.type, modelid: v.modelid, hub:hub]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
def bridge = null
|
def bridge = null
|
||||||
@@ -300,6 +300,40 @@ def bulbListHandler(hub, data = "") {
|
|||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private upgradeDeviceType(device, newHueType) {
|
||||||
|
def deviceType = getDeviceType(newHueType)
|
||||||
|
|
||||||
|
// Automatically change users Hue bulbs to correct device types
|
||||||
|
if (deviceType && !(device?.typeName?.equalsIgnoreCase(deviceType))) {
|
||||||
|
log.debug "Update device type: \"$device.label\" ${device?.typeName}->$deviceType"
|
||||||
|
device.setDeviceType(deviceType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getDeviceType(hueType) {
|
||||||
|
// Determine ST device type based on Hue classification of light
|
||||||
|
if (hueType?.equalsIgnoreCase("Dimmable light"))
|
||||||
|
return "Hue Lux Bulb"
|
||||||
|
else if (hueType?.equalsIgnoreCase("Extended Color Light"))
|
||||||
|
return "Hue Bulb"
|
||||||
|
else if (hueType?.equalsIgnoreCase("Color Light"))
|
||||||
|
return "Hue Bloom"
|
||||||
|
else
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private addChildBulb(dni, hueType, name, hub, update=false, device = null) {
|
||||||
|
def deviceType = getDeviceType(hueType)
|
||||||
|
|
||||||
|
if (deviceType) {
|
||||||
|
return addChildDevice("smartthings", deviceType, dni, hub, ["label": name])
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log.warn "Device type $hueType not supported"
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def addBulbs() {
|
def addBulbs() {
|
||||||
def bulbs = getHueBulbs()
|
def bulbs = getHueBulbs()
|
||||||
selectedBulbs?.each { dni ->
|
selectedBulbs?.each { dni ->
|
||||||
@@ -309,11 +343,7 @@ def addBulbs() {
|
|||||||
if (bulbs instanceof java.util.Map) {
|
if (bulbs instanceof java.util.Map) {
|
||||||
newHueBulb = bulbs.find { (app.id + "/" + it.value.id) == dni }
|
newHueBulb = bulbs.find { (app.id + "/" + it.value.id) == dni }
|
||||||
if (newHueBulb != null) {
|
if (newHueBulb != null) {
|
||||||
if (newHueBulb?.value?.type?.equalsIgnoreCase("Dimmable light") ) {
|
d = addChildBulb(dni, newHueBulb?.value?.type, newHueBulb?.value?.name, newHueBulb?.value?.hub)
|
||||||
d = addChildDevice("smartthings", "Hue Lux Bulb", dni, newHueBulb?.value.hub, ["label":newHueBulb?.value.name])
|
|
||||||
} else {
|
|
||||||
d = addChildDevice("smartthings", "Hue Bulb", dni, newHueBulb?.value.hub, ["label":newHueBulb?.value.name])
|
|
||||||
}
|
|
||||||
log.debug "created ${d.displayName} with id $dni"
|
log.debug "created ${d.displayName} with id $dni"
|
||||||
d.refresh()
|
d.refresh()
|
||||||
} else {
|
} else {
|
||||||
@@ -322,16 +352,15 @@ def addBulbs() {
|
|||||||
} else {
|
} else {
|
||||||
//backwards compatable
|
//backwards compatable
|
||||||
newHueBulb = bulbs.find { (app.id + "/" + it.id) == dni }
|
newHueBulb = bulbs.find { (app.id + "/" + it.id) == dni }
|
||||||
d = addChildDevice("smartthings", "Hue Bulb", dni, newHueBulb?.hub, ["label":newHueBulb?.name])
|
d = addChildBulb(dni, "Extended Color Light", newHueBulb?.value?.name, newHueBulb?.value?.hub)
|
||||||
d.refresh()
|
d.refresh()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug "found ${d.displayName} with id $dni already exists, type: '$d.typeName'"
|
log.debug "found ${d.displayName} with id $dni already exists, type: '$d.typeName'"
|
||||||
if (bulbs instanceof java.util.Map) {
|
if (bulbs instanceof java.util.Map) {
|
||||||
|
// Update device type if incorrect
|
||||||
def newHueBulb = bulbs.find { (app.id + "/" + it.value.id) == dni }
|
def newHueBulb = bulbs.find { (app.id + "/" + it.value.id) == dni }
|
||||||
if (newHueBulb?.value?.type?.equalsIgnoreCase("Dimmable light") && d.typeName == "Hue Bulb") {
|
upgradeDeviceType(d, newHueBulb?.value?.type)
|
||||||
d.setDeviceType("Hue Lux Bulb")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -473,7 +502,7 @@ def locationHandler(evt) {
|
|||||||
def bulbs = getHueBulbs()
|
def bulbs = getHueBulbs()
|
||||||
log.debug "Adding bulbs to state!"
|
log.debug "Adding bulbs to state!"
|
||||||
body.each { k,v ->
|
body.each { k,v ->
|
||||||
bulbs[k] = [id: k, name: v.name, type: v.type, hub:parsedEvent.hub]
|
bulbs[k] = [id: k, name: v.name, type: v.type, modelid: v.modelid, hub:parsedEvent.hub]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -657,39 +686,53 @@ def setColorTemperature(childDevice, huesettings) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def setColor(childDevice, huesettings) {
|
def setColor(childDevice, huesettings) {
|
||||||
log.debug "Executing 'setColor($huesettings)'"
|
log.debug "Executing 'setColor($huesettings)'"
|
||||||
|
|
||||||
|
def value = [:]
|
||||||
def hue = null
|
def hue = null
|
||||||
def sat = null
|
def sat = null
|
||||||
def xy = null
|
def xy = null
|
||||||
if (huesettings.hex) {
|
|
||||||
xy = getHextoXY(huesettings.hex)
|
if (huesettings.hex != null) {
|
||||||
} else if (huesettings.hue && huesettings.saturation) {
|
value.xy = getHextoXY(huesettings.hex)
|
||||||
hue = Math.min(Math.round(huesettings.hue * 65535 / 100), 65535)
|
} else {
|
||||||
sat = Math.min(Math.round(huesettings.saturation * 255 / 100), 255)
|
if (huesettings.hue != null)
|
||||||
|
value.hue = Math.min(Math.round(huesettings.hue * 65535 / 100), 65535)
|
||||||
|
if (huesettings.saturation != null)
|
||||||
|
value.sat = Math.min(Math.round(huesettings.saturation * 255 / 100), 255)
|
||||||
}
|
}
|
||||||
def alert = huesettings.alert ? huesettings.alert : "none"
|
|
||||||
def transition = huesettings.transition ? huesettings.transition : 4
|
// Default behavior is to turn light on
|
||||||
|
value.on = true
|
||||||
|
|
||||||
def value = [xy: xy, sat: sat, hue: hue, alert: alert, transitiontime: transition, on: true]
|
if (huesettings.level != null) {
|
||||||
|
if (huesettings.level <= 0)
|
||||||
|
value.on = false
|
||||||
|
else if (huesettings.level == 1)
|
||||||
|
value.bri = 1
|
||||||
|
else
|
||||||
|
value.bri = Math.min(Math.round(huesettings.level * 255 / 100), 255)
|
||||||
|
}
|
||||||
|
value.alert = huesettings.alert ? huesettings.alert : "none"
|
||||||
|
value.transition = huesettings.transition ? huesettings.transition : 4
|
||||||
|
|
||||||
if (huesettings.level != null) {
|
// Make sure to turn off light if requested
|
||||||
if (huesettings.level == 1) value.bri = 1 else value.bri = Math.min(Math.round(huesettings.level * 255 / 100), 255)
|
if (huesettings.switch == "off")
|
||||||
value.on = value.bri > 0
|
value.on = false
|
||||||
}
|
|
||||||
|
|
||||||
log.debug "sending command $value"
|
log.debug "sending command $value"
|
||||||
put("lights/${getId(childDevice)}/state", value)
|
put("lights/${getId(childDevice)}/state", value)
|
||||||
|
return "Color set to $value"
|
||||||
}
|
}
|
||||||
|
|
||||||
def nextLevel(childDevice) {
|
def nextLevel(childDevice) {
|
||||||
def level = device.latestValue("level") as Integer ?: 0
|
def level = device.latestValue("level") as Integer ?: 0
|
||||||
if (level < 100) {
|
if (level < 100) {
|
||||||
level = Math.min(25 * (Math.round(level / 25) + 1), 100) as Integer
|
level = Math.min(25 * (Math.round(level / 25) + 1), 100) as Integer
|
||||||
}
|
} else {
|
||||||
else {
|
level = 25
|
||||||
level = 25
|
}
|
||||||
}
|
setLevel(childDevice,level)
|
||||||
setLevel(childDevice,level)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getId(childDevice) {
|
private getId(childDevice) {
|
||||||
@@ -788,16 +831,14 @@ private getHextoXY(String colorStr) {
|
|||||||
|
|
||||||
// Make green more vivid
|
// Make green more vivid
|
||||||
if (normalizedToOne[1] > 0.04045) {
|
if (normalizedToOne[1] > 0.04045) {
|
||||||
green = (float) Math.pow((normalizedToOne[1] + 0.055)
|
green = (float) Math.pow((normalizedToOne[1] + 0.055) / (1.0 + 0.055), 2.4);
|
||||||
/ (1.0 + 0.055), 2.4);
|
|
||||||
} else {
|
} else {
|
||||||
green = (float) (normalizedToOne[1] / 12.92);
|
green = (float) (normalizedToOne[1] / 12.92);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make blue more vivid
|
// Make blue more vivid
|
||||||
if (normalizedToOne[2] > 0.04045) {
|
if (normalizedToOne[2] > 0.04045) {
|
||||||
blue = (float) Math.pow((normalizedToOne[2] + 0.055)
|
blue = (float) Math.pow((normalizedToOne[2] + 0.055) / (1.0 + 0.055), 2.4);
|
||||||
/ (1.0 + 0.055), 2.4);
|
|
||||||
} else {
|
} else {
|
||||||
blue = (float) (normalizedToOne[2] / 12.92);
|
blue = (float) (normalizedToOne[2] / 12.92);
|
||||||
}
|
}
|
||||||
@@ -806,8 +847,8 @@ private getHextoXY(String colorStr) {
|
|||||||
float Y = (float) (red * 0.234327 + green * 0.743075 + blue * 0.022598);
|
float Y = (float) (red * 0.234327 + green * 0.743075 + blue * 0.022598);
|
||||||
float Z = (float) (red * 0.0000000 + green * 0.053077 + blue * 1.035763);
|
float Z = (float) (red * 0.0000000 + green * 0.053077 + blue * 1.035763);
|
||||||
|
|
||||||
float x = X / (X + Y + Z);
|
float x = (X != 0 ? X / (X + Y + Z) : 0);
|
||||||
float y = Y / (X + Y + Z);
|
float y = (Y != 0 ? Y / (X + Y + Z) : 0);
|
||||||
|
|
||||||
double[] xy = new double[2];
|
double[] xy = new double[2];
|
||||||
xy[0] = x;
|
xy[0] = x;
|
||||||
@@ -824,7 +865,7 @@ def convertBulbListToMap() {
|
|||||||
if (state.bulbs instanceof java.util.List) {
|
if (state.bulbs instanceof java.util.List) {
|
||||||
def map = [:]
|
def map = [:]
|
||||||
state.bulbs.unique {it.id}.each { bulb ->
|
state.bulbs.unique {it.id}.each { bulb ->
|
||||||
map << ["${bulb.id}":["id":bulb.id, "name":bulb.name, "hub":bulb.hub]]
|
map << ["${bulb.id}":["id":bulb.id, "name":bulb.name, "type": bulb.type, "modelid": bulb.modelid, "hub":bulb.hub]]
|
||||||
}
|
}
|
||||||
state.bulbs = map
|
state.bulbs = map
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user