Compare commits

..

1 Commits

Author SHA1 Message Date
UCIC
0f3c29bc91 MSA-1435: Create connection between Ubi device and Smartthings device. 2016-08-07 17:30:17 -05:00
6 changed files with 611 additions and 143 deletions

View File

@@ -64,10 +64,8 @@ metadata {
}
standardTile("switch", "device.switch", width: 1, height: 1, canChangeIcon: true) {
state "on", label: '${name}', action: "switch.off", icon: "st.Electronics.electronics16", backgroundColor: "#79b821", nextState:"turningOff"
state "turningOff", label:'TURNING OFF', icon:"st.Electronics.electronics16", backgroundColor:"#ffffff"
state "off", label: '${name}', action: "switch.on", icon: "st.Electronics.electronics16", backgroundColor: "#ffffff", nextState:"turningOn"
state "turningOn", label:'TURNING ON', icon:"st.Electronics.electronics16", backgroundColor:"#79b821"
state "off", label: '${name}', action: "switch.on", icon: "st.Electronics.electronics16", backgroundColor: "#ffffff"
state "on", label: '${name}', action: "switch.off", icon: "st.Electronics.electronics16", backgroundColor: "#79b821"
}
valueTile("1", "device.station1", decoration: "flat", canChangeIcon: false) {
state "station1", label:'${currentValue}', action:"preset1"
@@ -749,16 +747,8 @@ def cb_boseSetInput(xml, input) {
*/
def boseSetPowerState(boolean enable) {
log.info "boseSetPowerState(${enable})"
// Fix to get faster update of power status back from speaker after sending on/off
// Instead of queuing the command to be sent after the refresh send it directly via sendHubCommand
// Note: This is a temporary hack that should be replaced by a re-design of the
// DTH to use sendHubCommand for all commands
sendHubCommand(bosePOST("/key", "<key state=\"press\" sender=\"Gabbo\">POWER</key>"))
sendHubCommand(bosePOST("/key", "<key state=\"release\" sender=\"Gabbo\">POWER</key>"))
sendHubCommand(boseGET("/now_playing"))
if (enable) {
queueCallback('nowPlaying', "cb_boseConfirmPowerOn", 5)
}
queueCallback('nowPlaying', "cb_boseSetPowerState", enable ? "POWERON" : "POWEROFF")
return boseRefreshNowPlaying()
}
/**
@@ -797,11 +787,10 @@ def cb_boseSetPowerState(xml, state) {
*/
def cb_boseConfirmPowerOn(xml, tries) {
def result = []
def attempt = tries as Integer
log.warn "boseConfirmPowerOn() attempt #$attempt"
if (xml.attributes()['source'] == "STANDBY" && attempt > 0) {
log.warn "boseConfirmPowerOn() attempt #" + tries
if (xml.attributes()['source'] == "STANDBY" && tries > 0) {
result << boseRefreshNowPlaying()
queueCallback('nowPlaying', "cb_boseConfirmPowerOn", attempt-1)
queueCallback('nowPlaying', "cb_boseConfirmPowerOn", tries-1)
}
return result
}

View File

@@ -20,7 +20,6 @@ metadata {
capability "Switch"
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006"
fingerprint profileId: "0104", inClusters: "0000, 0003, 0006", outClusters: "0003, 0006, 0019, 0406", manufacturer: "Leviton", model: "ZSS-10", deviceJoinName: "Leviton Switch"
}
// simulator metadata

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2016 SmartThings
* 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:
@@ -11,133 +11,100 @@
* for the specific language governing permissions and limitations under the License.
*
*/
/*
* Capabilities
* - Battery
* - Configuration
* - Refresh
* - Switch
* - Valve
*/
metadata {
definition (name: "ZigBee Valve", namespace: "smartthings", author: "SmartThings") {
capability "Actuator"
capability "Battery"
capability "Configuration"
capability "Power Source"
capability "Refresh"
capability "Valve"
definition (name: "Zigbee Valve", namespace: "smartthings", author: "SmartThings") {
capability "Battery"
capability "Configuration"
capability "Refresh"
capability "Switch"
capability "Valve"
fingerprint profileId: "0104", inClusters: "0000, 0001, 0003, 0006, 0020, 0B02, FC02", outClusters: "0019", manufacturer: "WAXMAN", model: "leakSMART Water Valve v2.10", deviceJoinName: "leakSMART Valve"
fingerprint profileId: "0104", inClusters: "0000, 0001, 0003, 0004, 0005, 0006, 0008, 000F, 0020, 0B02", outClusters: "0003, 0019", manufacturer: "WAXMAN", model: "House Water Valve - MDL-TBD", deviceJoinName: "Waxman House Water Valve"
}
fingerprint profileId: "0104", inClusters: "0000,0001,0003,0004,0005,0020,0006,0B02", outClusters: "0003"
}
// simulator metadata
simulator {
// status messages
status "on": "on/off: 1"
status "off": "on/off: 0"
// simulator metadata
simulator {
// status messages
status "on": "on/off: 1"
status "off": "on/off: 0"
// reply messages
reply "zcl on-off on": "on/off: 1"
reply "zcl on-off off": "on/off: 0"
}
// reply messages
reply "zcl on-off on": "on/off: 1"
reply "zcl on-off off": "on/off: 0"
}
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: "#53a7c0", nextState:"closing"
attributeState "closing", label: '${name}', action: "valve.open", icon: "st.valves.water.closed", backgroundColor: "#e86d13", nextState:"opening"
}
tileAttribute ("powerSource", key: "SECONDARY_CONTROL") {
attributeState "powerSource", label:'Power Source: ${currentValue}'
}
}
valueTile("battery", "device.battery", inactiveLabel:false, decoration:"flat", width:2, height:2) {
state "battery", label:'${currentValue}% battery', unit:""
}
standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
}
main(["valve"])
details(["valve", "battery", "refresh"])
}
// UI tile definitions
tiles {
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "off", label: 'closed', action: "switch.on", icon: "st.Outdoor.outdoor16", backgroundColor: "#e86d13"
state "on", label: 'open', action: "switch.off", icon: "st.Outdoor.outdoor16", backgroundColor: "#53a7c0"
}
main "switch"
details(["switch"])
}
}
private getCLUSTER_BASIC() { 0x0000 }
private getBASIC_ATTR_POWER_SOURCE() { 0x0007 }
private getCLUSTER_POWER() { 0x0001 }
private getPOWER_ATTR_BATTERY_PERCENTAGE_REMAINING() { 0x0021 }
private getTYPE_U8() { 0x20 }
private getTYPE_ENUM8() { 0x30 }
// Parse incoming device messages to generate events
def parse(String description) {
log.debug "description is $description"
def event = zigbee.getEvent(description)
if (event) {
if(event.name == "switch") {
event.name = "contact" //0006 cluster in valve is tied to contact
if(event.value == "on") {
event.value = "open"
}
else if(event.value == "off") {
event.value = "closed"
}
}
sendEvent(event)
}
else {
def descMap = zigbee.parseDescriptionAsMap(description)
if (descMap.clusterInt == CLUSTER_BASIC && descMap.attrInt == BASIC_ATTR_POWER_SOURCE){
def value = descMap.value
if (value == "01" || value == "02") {
sendEvent(name: "powerSource", value: "Mains")
}
else if (value == "03") {
sendEvent(name: "powerSource", value: "Battery")
}
else if (value == "04") {
sendEvent(name: "powerSource", value: "DC")
}
else {
sendEvent(name: "powerSource", value: "Unknown")
}
}
else if (descMap.clusterInt == CLUSTER_POWER && descMap.attrInt == POWER_ATTR_BATTERY_PERCENTAGE_REMAINING) {
event.name = "battery"
event.value = Math.round(Integer.parseInt(descMap.value, 16) / 2)
sendEvent(event)
}
else {
log.warn "DID NOT PARSE MESSAGE for description : $description"
log.debug descMap
}
}
log.info description
if (description?.startsWith("catchall:")) {
def value = name == "switch" ? (description?.endsWith(" 1") ? "on" : "off") : null
def result = createEvent(name: name, value: value)
def msg = zigbee.parse(description)
log.debug "Parse returned ${result?.descriptionText}"
return result
log.trace msg
log.trace "data: $msg.data"
}
else {
def name = description?.startsWith("on/off: ") ? "switch" : null
def value = name == "switch" ? (description?.endsWith(" 1") ? "on" : "off") : null
def result = createEvent(name: name, value: value)
log.debug "Parse returned ${result?.descriptionText}"
return result
}
}
// Commands to device
def on() {
log.debug "on()"
sendEvent(name: "switch", value: "on")
"st cmd 0x${device.deviceNetworkId} 1 6 1 {}"
}
def off() {
log.debug "off()"
sendEvent(name: "switch", value: "off")
"st cmd 0x${device.deviceNetworkId} 1 6 0 {}"
}
def open() {
zigbee.on()
log.debug "on()"
sendEvent(name: "switch", value: "on")
"st cmd 0x${device.deviceNetworkId} 1 6 1 {}"
}
def close() {
zigbee.off()
log.debug "off()"
sendEvent(name: "switch", value: "off")
"st cmd 0x${device.deviceNetworkId} 1 6 0 {}"
}
def refresh() {
log.debug "refresh called"
zigbee.onOffRefresh() +
zigbee.readAttribute(CLUSTER_BASIC, BASIC_ATTR_POWER_SOURCE) +
zigbee.readAttribute(CLUSTER_POWER, POWER_ATTR_BATTERY_PERCENTAGE_REMAINING) +
zigbee.onOffConfig() +
zigbee.configureReporting(CLUSTER_POWER, POWER_ATTR_BATTERY_PERCENTAGE_REMAINING, TYPE_U8, 600, 21600, 1) +
zigbee.configureReporting(CLUSTER_BASIC, BASIC_ATTR_POWER_SOURCE, TYPE_ENUM8, 5, 21600, 1)
log.debug "sending refresh command"
"st rattr 0x${device.deviceNetworkId} 1 6 0"
}
def configure() {
log.debug "Configuring Reporting and Bindings."
zigbee.onOffConfig() +
zigbee.configureReporting(CLUSTER_POWER, POWER_ATTR_BATTERY_PERCENTAGE_REMAINING, TYPE_U8, 600, 21600, 1) +
zigbee.configureReporting(CLUSTER_BASIC, BASIC_ATTR_POWER_SOURCE, TYPE_ENUM8, 5, 21600, 1) +
zigbee.onOffRefresh() +
zigbee.readAttribute(CLUSTER_BASIC, BASIC_ATTR_POWER_SOURCE) +
zigbee.readAttribute(CLUSTER_POWER, POWER_ATTR_BATTERY_PERCENTAGE_REMAINING)
"zdo bind 0x${device.deviceNetworkId} 1 1 6 {${device.zigbeeId}} {}"
}

View File

@@ -24,24 +24,17 @@ definition(
iconX3Url: "http://www.gidjit.com/appicon@3x.png",
oauth: [displayName: "Gidjit", displayLink: "www.gidjit.com"])
preferences(oauthPage: "deviceAuthorization") {
// deviceAuthorization page is simply the devices to authorize
page(name: "deviceAuthorization", title: "Device Authorization", nextPage: "instructionPage",
install: false, uninstall: true) {
section ("Allow Gidjit to have access, thereby allowing you to quickly control and monitor your following devices. Privacy Policy can be found at http://priv.gidjit.com/privacy.html") {
input "switches", "capability.switch", title: "Control/Monitor your switches", multiple: true, required: false
input "thermostats", "capability.thermostat", title: "Control/Monitor your thermostats", multiple: true, required: false
input "windowShades", "capability.windowShade", title: "Control/Monitor your window shades", multiple: true, required: false //windowShade
}
}
page(name: "instructionPage", title: "Device Discovery", install: true) {
section() {
paragraph "Now the process is complete return to the Devices section of the Detected Screen. From there and you can add actions to each of your device panels, including launching SmartThings routines."
}
}
preferences {
section ("Allow Gidjit to have access, there by allowing you to quickly control and monitor the following devices") {
input "switches", "capability.switch", title: "Control/Monitor your switches", multiple: true, required: false
input "thermostats", "capability.thermostat", title: "Control/Monitor your thermostats", multiple: true, required: false
input "windowShades", "capability.windowShade", title: "Control/Monitor your window shades", multiple: true, required: false //windowShade
//input "bulbs", "capability.colorControl", title: "Control your lights", multiple: true, required: false //windowShade
}
}
mappings {
path("/structureinfo") {
action: [

View File

@@ -0,0 +1,520 @@
/**
* Ubi
*
* Copyright 2016 UCIC
*
* 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: "Ubi",
namespace: "ucic.io",
author: "UCIC",
description: "Connect Ubi with SmartThings",
category: "SmartThings Labs",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/ubi-app-icn.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/ubi-app-icn@2x.png",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Partner/ubi-app-icn@2x.png",
oauth: true)
preferences {
section("Allow a web application to control these things...") {
input name: "switches", type: "capability.switch", title: "Which Switches?", multiple: true, required: false
input name: "motions", type: "capability.motionSensor", title: "Which Motion Sensors?", multiple: true, required: false
input name: "locks", type: "capability.lock", title: "Which Locks?", multiple: true, required: false
input name: "contactSensors", type: "capability.contactSensor", title: "Which Contact Sensors?", multiple: true, required: false
input name: "presenceSensors", type: "capability.presenceSensor", title: "Which Presence Sensors?", multiple: true, required: false
}
}
mappings {
path("/list") {
action: [
GET: "listAll"
]
}
path("/events/:id") {
action: [
GET: "showEvents"
]
}
path("/switches") {
action: [
GET: "listSwitches",
PUT: "updateSwitches",
POST: "updateSwitches"
]
}
path("/switches/:id") {
action: [
GET: "showSwitch",
PUT: "updateSwitch",
POST: "updateSwitch"
]
}
path("/switches/subscriptions") {
//log.debug "switches added"
action: [
POST: "addSwitchSubscription"
]
}
path("/switches/subscriptions/:id") {
action: [
DELETE: "removeSwitchSubscription",
GET: "removeSwitchSubscription"
]
}
path("/motionSensors") {
action: [
GET: "listMotions",
PUT: "updateMotions",
POST: "updateMotions"
]
}
path("/motionSensors/:id") {
action: [
GET: "showMotion",
PUT: "updateMotion",
POST: "updateMotion"
]
}
path("/motionSensors/subscriptions") {
//log.debug "motionSensors added"
action: [
POST: "addMotionSubscription"
]
}
path("/motionSensors/subscriptions/:id") {
//log.debug "motionSensors Deleted"
action: [
DELETE: "removeMotionSubscription",
GET: "removeMotionSubscription"
]
}
path("/locks") {
action: [
GET: "listLocks",
PUT: "updateLock",
POST: "updateLock"
]
}
path("/locks/:id") {
action: [
GET: "showLock",
PUT: "updateLock",
POST: "updateLock"
]
}
path("/locks/subscriptions") {
action: [
POST: "addLockSubscription"
]
}
path("/locks/subscriptions/:id") {
action: [
DELETE: "removeLockSubscription",
GET: "removeLockSubscription"
]
}
path("/contactSensors") {
action: [
GET: "listContactSensors",
PUT: "updateContactSensor",
POST: "updateContactSensor"
]
}
path("/contactSensors/:id") {
action: [
GET: "showContactSensor",
PUT: "updateContactSensor",
POST: "updateContactSensor"
]
}
path("/contactSensors/subscriptions") {
log.debug "contactSensors/subscriptions"
action: [
POST: "addContactSubscription"
]
}
path("/contactSensors/subscriptions/:id") {
action: [
DELETE: "removeContactSensorSubscription",
GET: "removeContactSensorSubscription"
]
}
path("/presenceSensors") {
action: [
GET: "listPresenceSensors",
PUT: "updatePresenceSensor",
POST: "updatePresenceSensor"
]
}
path("/presenceSensors/:id") {
action: [
GET: "showPresenceSensor",
PUT: "updatePresenceSensor",
POST: "updatePresenceSensor"
]
}
path("/presenceSensors/subscriptions") {
//log.debug "PresenceSensors/subscriptions"
action: [
POST: "addPresenceSubscription"
]
}
path("/presenceSensors/subscriptions/:id") {
action: [
DELETE: "removePresenceSensorSubscription",
GET: "removePresenceSensorSubscription"
]
}
path("/state") {
action: [
GET: "currentState"
]
}
path("/phrases") {
action: [
GET: "listPhrases"
]
}
path("/phrases/:phraseName") {
action: [
GET: "executePhrase",
POST: "executePhrase",
]
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
//unsubscribe()
initialize()
}
def initialize() {
// TODO: subscribe to attributes, devices, locations, etc.
log.debug "initialize, do nothing..."
}
def listAll() {
listSwitches() + listMotions() + listLocks() + listContactSensors() + listPresenceSensors()
}
def listContactSensors() {
contactSensors.collect { device(it, "contactSensor") }
}
void updateContactSensors() {
updateAll(contactSensors)
}
def showContactSensor() {
show(contactSensors, "contact")
}
void updateContactSensor() {
update(contactSensors)
}
def addContactSubscription() {
log.debug "addContactSensorSubscription, params: ${params}"
addSubscription(contactSensors, "contact")
}
def removeContactSensorSubscription() {
removeSubscription(contactSensors)
}
def listPresenceSensors() {
presenceSensors.collect { device(it, "presenceSensor") }
}
void updatePresenceSensors() {
updateAll(presenceSensors)
}
def showPresenceSensor() {
show(presenceSensors, "presence")
}
void updatePresenceSensor() {
update(presenceSensors)
}
def addPresenceSubscription() {
log.debug "addPresenceSensorSubscription, params: ${params}"
addSubscription(presenceSensors, "presence")
}
def removePresenceSensorSubscription() {
removeSubscription(presenceSensors)
}
def listSwitches() {
switches.collect { device(it, "switch") }
}
void updateSwitches() {
updateAll(switches)
}
def showSwitch() {
show(switches, "switch")
}
void updateSwitch() {
update(switches)
}
def addSwitchSubscription() {
log.debug "addSwitchSubscription, params: ${params}"
addSubscription(switches, "switch")
}
def removeSwitchSubscription() {
removeSubscription(switches)
}
def listMotions() {
motions.collect { device(it, "motionSensor") }
}
void updateMotions() {
updateAll(motions)
}
def showMotion() {
show(motions, "motion")
}
void updateMotion() {
update(motions)
}
def addMotionSubscription() {
addSubscription(motions, "motion")
}
def removeMotionSubscription() {
removeSubscription(motions)
}
def listLocks() {
locks.collect { device(it, "lock") }
}
void updateLocks() {
updateAll(locks)
}
def showLock() {
show(locks, "lock")
}
void updateLock() {
update(locks)
}
def addLockSubscription() {
addSubscription(locks, "lock")
}
def removeLockSubscription() {
removeSubscription(locks)
}
/*
def motionOpenHandler(evt) {
//log.trace "$evt.value: $evt, $settings"
log.debug "$motions was active, sending push message to user"
//sendPush("Your ${contact1.label ?: contact1.name} was opened")
httpPostJson(uri: "http://automatesolutions.ca/test.php", path: '', body: [evt: [value: "motionSensor Active"]]) {
log.debug "Event data successfully posted"
}
}
def contactOpenHandler(evt) {
//log.trace "$evt.value: $evt, $settings"
log.debug "$contactSensors was opened, sending push message to user"
//sendPush("Your ${contact1.label ?: contact1.name} was opened")
httpPostJson(uri: "http://automatesolutions.ca/test.php", path: '', body: [evt: [value: "ContactSensor Opened"]]) {
log.debug "Event data successfully posted"
}
}
*/
def deviceHandler(evt) {
log.debug "~~~~~TEST~~~~~~"
def deviceInfo = state[evt.deviceId]
if (deviceInfo)
{
httpPostJson(uri: deviceInfo.callbackUrl, path: '', body: [evt: [value: evt.value]]) {
log.debug "Event data successfully posted"
}
}
else
{
log.debug "No subscribed device found"
}
}
def currentState() {
state
}
def showStates() {
def device = (switches + motions + locks).find { it.id == params.id }
if (!device)
{
httpError(404, "Switch not found")
}
else
{
device.events(params)
}
}
def listPhrases() {
location.helloHome.getPhrases().label
}
def executePhrase() {
def phraseName = params.phraseName
if (phraseName)
{
location.helloHome.execute(phraseName)
log.debug "executed phrase: $phraseName"
}
else
{
httpError(404, "Phrase not found")
}
}
private void updateAll(devices) {
def command = request.JSON?.command
if (command)
{
command = command.toLowerCase()
devices."$command"()
}
}
private void update(devices) {
log.debug "update, request: ${request.JSON}, params: ${params}, devices: $devices.id"
//def command = request.JSON?.command
def command = params.command
if (command)
{
command = command.toLowerCase()
def device = devices.find { it.id == params.id }
if (!device)
{
httpError(404, "Device not found")
}
else
{
device."$command"()
}
}
}
private show(devices, type) {
def device = devices.find { it.id == params.id }
if (!device)
{
httpError(404, "Device not found")
}
else
{
def attributeName = type
def s = device.currentState(attributeName)
[id: device.id, label: device.displayName, value: s?.value, unitTime: s?.date?.time, type: type]
}
}
private addSubscription(devices, attribute) {
//def deviceId = request.JSON?.deviceId
//def callbackUrl = request.JSON?.callbackUrl
log.debug "addSubscription, params: ${params}"
def deviceId = params.deviceId
def callbackUrl = params.callbackUrl
def myDevice = devices.find { it.id == deviceId }
if (myDevice)
{
if (state[deviceId])
{
log.debug "Switch subscription already exists, unsubcribing"
unsubscribe(myDevice)
}
log.debug "Adding switch subscription" + callbackUrl
state[deviceId] = [callbackUrl: callbackUrl]
log.debug "Added state: $state"
subscribe(myDevice, attribute, deviceHandler)
}
}
private removeSubscription(devices) {
def deviceId = params.id
def device = devices.find { it.id == deviceId }
if (device)
{
log.debug "Removing $device.displayName subscription"
state.remove(device.id)
unsubscribe(device)
}
}
private device(it, type) {
it ? [id: it.id, label: it.displayName, type: type] : null
}