Compare commits

..

1 Commits

5 changed files with 249 additions and 62 deletions

View File

@@ -3,6 +3,7 @@
*
* Author: SmartThings
*/
// for the UI
metadata {
// Automatically generated. Make future change here.
@@ -27,10 +28,10 @@ metadata {
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:"#79b821", nextState:"turningOff"
attributeState "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff"
attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
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)"
@@ -43,16 +44,10 @@ metadata {
}
}
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff"
state "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
state "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff"
state "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
}
controlTile("colorTempSliderControl", "device.colorTemperature", "slider", width: 4, height: 2, inactiveLabel: false, range:"(2000..6500)") {
state "colorTemperature", action:"color temperature.setColorTemperature"
}
valueTile("colorTemp", "device.colorTemperature", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "colorTemperature", label: '${currentValue} K'
}
@@ -60,29 +55,12 @@ metadata {
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.switch", height: 2, width: 2, inactiveLabel: false, decoration: "flat") {
standardTile("refresh", "device.refresh", height: 2, width: 2, inactiveLabel: false, decoration: "flat") {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
}
controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 2, inactiveLabel: false, range:"(0..100)") {
state "level", action:"switch level.setLevel"
}
valueTile("level", "device.level", inactiveLabel: false, decoration: "flat") {
state "level", label: 'Level ${currentValue}%'
}
controlTile("saturationSliderControl", "device.saturation", "slider", height: 1, width: 2, inactiveLabel: false) {
state "saturation", action:"color control.setSaturation"
}
valueTile("saturation", "device.saturation", inactiveLabel: false, decoration: "flat") {
state "saturation", label: 'Sat ${currentValue} '
}
controlTile("hueSliderControl", "device.hue", "slider", height: 1, width: 2, inactiveLabel: false) {
state "hue", action:"color control.setHue"
}
valueTile("hue", "device.hue", inactiveLabel: false, decoration: "flat") {
state "hue", label: 'Hue ${currentValue} '
}
main(["switch"])
main(["rich-control"])
details(["rich-control", "colorTempSliderControl", "colorTemp", "reset", "refresh"])
}
}
@@ -127,34 +105,34 @@ void nextLevel() {
void setLevel(percent) {
log.debug "Executing 'setLevel'"
parent.setLevel(this, percent)
sendEvent(name: "level", value: percent)
sendEvent(name: "level", value: percent, descriptionText: "Level has changed to ${percent}%")
}
void setSaturation(percent) {
log.debug "Executing 'setSaturation'"
parent.setSaturation(this, percent)
sendEvent(name: "saturation", value: percent)
sendEvent(name: "saturation", value: percent, displayed: false)
}
void setHue(percent) {
log.debug "Executing 'setHue'"
parent.setHue(this, percent)
sendEvent(name: "hue", value: percent)
sendEvent(name: "hue", value: percent, displayed: false)
}
void setColor(value) {
log.debug "setColor: ${value}, $this"
parent.setColor(this, value)
if (value.hue) { sendEvent(name: "hue", value: value.hue)}
if (value.saturation) { sendEvent(name: "saturation", value: value.saturation)}
if (value.hue) { sendEvent(name: "hue", value: value.hue, displayed: false)}
if (value.saturation) { sendEvent(name: "saturation", value: value.saturation, displayed: false)}
if (value.hex) { sendEvent(name: "color", value: value.hex)}
if (value.level) { sendEvent(name: "level", value: value.level)}
if (value.switch) { sendEvent(name: "switch", value: value.switch)}
if (value.level) { sendEvent(name: "level", value: value.level, descriptionText: "Level has changed to ${value.level}%")}
sendEvent(name: "switch", value: "on")
}
void reset() {
log.debug "Executing 'reset'"
def value = [level:100, hex:"#90C638", saturation:56, hue:23]
def value = [level:100, saturation:56, hue:23]
setAdjustedColor(value)
parent.poll()
}

View File

@@ -36,13 +36,6 @@ metadata {
}
}
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff"
state "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
state "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff"
state "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
}
controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 2, inactiveLabel: false, range:"(0..100)") {
state "level", action:"switch level.setLevel"
}
@@ -51,7 +44,7 @@ metadata {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
}
main(["switch"])
main(["rich-control"])
details(["rich-control", "refresh"])
}
}

View File

@@ -203,7 +203,7 @@ private List parseContactMessage(String description) {
parts.each { part ->
part = part.trim()
if (part.startsWith('contactState:')) {
results.addAll(getContactResult(part, description))
results << getContactResult(part, description)
}
else if (part.startsWith('accelerationState:')) {
results << getAccelerationResult(part, description)
@@ -316,7 +316,7 @@ private List getContactResult(part, description) {
results
}
private Map getAccelerationResult(part, description) {
private getAccelerationResult(part, description) {
def name = "acceleration"
def value = part.endsWith("1") ? "active" : "inactive"
def linkText = getLinkText(device)
@@ -335,7 +335,7 @@ private Map getAccelerationResult(part, description) {
]
}
private Map getTempResult(part, description) {
private getTempResult(part, description) {
def name = "temperature"
def temperatureScale = getTemperatureScale()
def value = zigbee.parseSmartThingsTemperatureValue(part, "temp: ", temperatureScale)
@@ -360,7 +360,7 @@ private Map getTempResult(part, description) {
]
}
private Map getXyzResult(results, description) {
private getXyzResult(results, description) {
def name = "threeAxis"
def value = "${results.x},${results.y},${results.z}"
def linkText = getLinkText(device)
@@ -379,7 +379,7 @@ private Map getXyzResult(results, description) {
]
}
private Map getBatteryResult(part, description) {
private 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 name = "battery"
def value = zigbee.parseSmartThingsBatteryValue(part, batteryDivisor)
@@ -400,7 +400,7 @@ private Map getBatteryResult(part, description) {
]
}
private Map getRssiResult(part, description, lastHop=false) {
private getRssiResult(part, description, lastHop=false) {
def name = lastHop ? "lastHopRssi" : "rssi"
def valueString = part.split(":")[1].trim()
def value = (Integer.parseInt(valueString) - 128).toString()
@@ -431,7 +431,7 @@ private Map getRssiResult(part, description, lastHop=false) {
* Note: To make the signal strength indicator more accurate, we could combine
* LQI with RSSI.
*/
private Map getLqiResult(part, description, lastHop=false) {
private getLqiResult(part, description, lastHop=false) {
def name = lastHop ? "lastHopLqi" : "lqi"
def valueString = part.split(":")[1].trim()
def percentageOf = 255

View File

@@ -0,0 +1,159 @@
/**
* InfluxdbShipper
*
* Copyright 2016 Prune - prune@lecentre.net
*
* 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.
*
* Description :
* This application listen to sensors and send the result metric to an Influxdb 0.9.x or newer server.
* It is NOT compatible with Influxdb 0.8.x
*
* Check Influxdb docs at
* https://docs.influxdata.com/influxdb/v0.10/introduction/
*
* Usage :
* select sensors you want to monitor
* enter your InfluxDB URL with full informations :
*
* <host>:<port>
*
* Ex : www.myserver.ca:8086/write
*
* It is strongly encouraged to use HTTPS and a login/password as your Influxdb server need to be open to the world
*/
definition(
name: "InfluxdbShipper",
namespace: "Prune",
author: "Prune",
description: "stream metrics to Influxdb",
category: "My Apps",
iconUrl: "http://lkhill.com/wp/wp-content/uploads/2015/10/influxdb-logo.png",
iconX2Url: "http://lkhill.com/wp/wp-content/uploads/2015/10/influxdb-logo.png",
iconX3Url: "http://lkhill.com/wp/wp-content/uploads/2015/10/influxdb-logo.png")
preferences {
section("Log devices...") {
input "temperatures", "capability.temperatureMeasurement", title: "Temperatures", required:false, multiple: true
input "humidity", "capability.relativeHumidityMeasurement", title: "Humidity", required:false, multiple: true
input "contacts", "capability.contactSensor", title: "Doors open/close", required: false, multiple: true
input "motions", "capability.motionSensor", title: "Motions", required: false, multiple: true
input "presence", "capability.presenceSensor", title: "Presence", required: false, multiple: true
input "switches", "capability.switch", title: "Switches", required: false, multiple: true
input "energy", "capability.energyMeter", title: "Energy", required: false, multiple: true
input "smoke", "capability.smokeDetector", title: "Smoke", required: false, multiple: true
}
section ("Influxdb URL...") {
input "influxdb_url", "text", title: "Influxdb URL"
input "influxdb_proto", "enum", title: "Protocol (http or https)", options: ["HTTP", "HTTPS"]
input "influxdb_db", "text", title: "Influxdb DB"
input "influxdb_login", "text", title: "Influxdb Login"
input "influxdb_password", "password", title: "Influxdb Password"
}
}
def installed() {
initialize()
}
def updated() {
unsubscribe()
initialize()
}
def initialize() {
/*subscribe(temperatures, "temperature", handleTemperatureEvent)
subscribe(contacts, "contact", handleContactEvent)
subscribe(accelerations, "acceleration", handleAccelerationEvent)
subscribe(motions, "motion", handleMotionEvent)
subscribe(presence, "presence", handlePresenceEvent)
subscribe(switches, "switch", handleSwitchEvent)
log.debug "Done subscribing to events"
*/
//log.debug "temperatures: ${temperatures[0].name} = ${temperatures[0].currentState("temperature").value}"
// Send data every 5 mins
runEvery5Minutes(updateCurrentStats)
}
/*
Push data to Influx
*/
def updateCurrentStats() {
//log.debug "Logging to Influxdb ${influxdb_url}"
// Builds the URL that will be sent to Influxdb
def full_url = "${influxdb_proto}://${influxdb_url}/write?db=${influxdb_db}"
if (influxdb_login != "") {
full_url += "&u=${influxdb_login}&p=${influxdb_password}"
}
def full_body=""
temperatures.eachWithIndex{ val, idx ->
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
full_body += "temp,sensor=${sensorName} value=${val.currentState("temperature").value} \n"
}
contacts.eachWithIndex{ val, idx ->
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
// 0=closed, 1=open
def contactState = val.currentState("contact").value == "open" ? 1 : 0
full_body += "contact,sensor=${sensorName} value=${contactState} \n"
}
humidity.eachWithIndex{ val, idx ->
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
full_body += "humidity,sensor=${sensorName} value=${val.currentState("humidity").value} \n"
}
motions.eachWithIndex{ val, idx ->
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
// 0=no motion, 1=motion detected
def motionState = val.currentState("motion").value == "active" ? 1 : 0
full_body += "motion,sensor=${sensorName} value=${motionState} \n"
}
presence.eachWithIndex{ val, idx ->
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
// 0=no presence, 1=present
def presenceState = val.currentState("presence").value == "present" ? 1 : 0
full_body += "presence,sensor=${sensorName} value=${presenceState} \n"
}
switches.eachWithIndex{ val, idx ->
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
// 0=off, 1=on
def switchState = val.currentState("switch").value == "on" ? 1 : 0
full_body += "switch,sensor=${sensorName} value=${switchState} \n"
}
energy.eachWithIndex{ val, idx ->
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
full_body += "energy,sensor=${sensorName} value=${val.currentState("energy").value} \n"
}
smoke.eachWithIndex{ val, idx ->
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
// 0="clear" 1="detected" 2="tested"
def smokeState = val.currentState("smoke").value == "detected" ? 1 : 0
full_body += "smoke,sensor=${sensorName} value=${smokeState} \n"
}
def params = [
uri: full_url,
body: full_body
]
try {
// Make the HTTP request using httpGet()
log.debug "Calling $params"
httpPost(params) { resp -> // This is how we define the "return data". Can also use $it.
log.debug "response data: ${resp.data}"
}
} catch (e) {
log.error "something went wrong: $e"
}
}

View File

@@ -24,7 +24,7 @@ definition(
category: "SmartThings Labs",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/hue.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/hue@2x.png",
//singleInstance: true
singleInstance: true
)
preferences {
@@ -643,21 +643,25 @@ def setColorTemperature(childDevice, huesettings) {
def setColor(childDevice, huesettings) {
log.debug "Executing 'setColor($huesettings)'"
def hue = Math.min(Math.round(huesettings.hue * 65535 / 100), 65535)
def sat = Math.min(Math.round(huesettings.saturation * 255 / 100), 255)
def hue = null
def sat = null
def xy = null
if (huesettings.hex) {
xy = getHextoXY(huesettings.hex)
} else if (huesettings.hue && huesettings.saturation) {
hue = Math.min(Math.round(huesettings.hue * 65535 / 100), 65535)
sat = Math.min(Math.round(huesettings.saturation * 255 / 100), 255)
}
def alert = huesettings.alert ? huesettings.alert : "none"
def transition = huesettings.transition ? huesettings.transition : 4
def value = [sat: sat, hue: hue, alert: alert, transitiontime: transition]
def value = [xy: xy, sat: sat, hue: hue, alert: alert, transitiontime: transition, on: true]
if (huesettings.level != null) {
if (huesettings.level == 1) value.bri = 1 else value.bri = Math.min(Math.round(huesettings.level * 255 / 100), 255)
value.on = value.bri > 0
}
if (huesettings.switch) {
value.on = huesettings.switch == "on"
}
log.debug "sending command $value"
put("lights/${getId(childDevice)}/state", value)
}
@@ -743,6 +747,59 @@ private getBridgeIP() {
return host
}
private getHextoXY(String colorStr) {
// For the hue bulb the corners of the triangle are:
// -Red: 0.675, 0.322
// -Green: 0.4091, 0.518
// -Blue: 0.167, 0.04
def cred = Integer.valueOf( colorStr.substring( 1, 3 ), 16 )
def cgreen = Integer.valueOf( colorStr.substring( 3, 5 ), 16 )
def cblue = Integer.valueOf( colorStr.substring( 5, 7 ), 16 )
double[] normalizedToOne = new double[3];
normalizedToOne[0] = (cred / 255);
normalizedToOne[1] = (cgreen / 255);
normalizedToOne[2] = (cblue / 255);
float red, green, blue;
// Make red more vivid
if (normalizedToOne[0] > 0.04045) {
red = (float) Math.pow(
(normalizedToOne[0] + 0.055) / (1.0 + 0.055), 2.4);
} else {
red = (float) (normalizedToOne[0] / 12.92);
}
// Make green more vivid
if (normalizedToOne[1] > 0.04045) {
green = (float) Math.pow((normalizedToOne[1] + 0.055)
/ (1.0 + 0.055), 2.4);
} else {
green = (float) (normalizedToOne[1] / 12.92);
}
// Make blue more vivid
if (normalizedToOne[2] > 0.04045) {
blue = (float) Math.pow((normalizedToOne[2] + 0.055)
/ (1.0 + 0.055), 2.4);
} else {
blue = (float) (normalizedToOne[2] / 12.92);
}
float X = (float) (red * 0.649926 + green * 0.103455 + blue * 0.197109);
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 x = X / (X + Y + Z);
float y = Y / (X + Y + Z);
double[] xy = new double[2];
xy[0] = x;
xy[1] = y;
return xy;
}
private Integer convertHexToInt(hex) {
Integer.parseInt(hex,16)
}