mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-04-05 06:13:08 +01:00
Compare commits
1 Commits
MSA-1551-6
...
MSA-1537-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
23756d3f88 |
@@ -1,148 +0,0 @@
|
|||||||
metadata {
|
|
||||||
// Automatically generated. Make future change here.
|
|
||||||
definition (name: "MY Zigbee Dimmer255", namespace: "smartthings", author: "SmartThings") {
|
|
||||||
capability "Actuator"
|
|
||||||
capability "Switch"
|
|
||||||
capability "Sensor"
|
|
||||||
capability "Switch Level"
|
|
||||||
capability "Refresh"
|
|
||||||
|
|
||||||
fingerprint profileId: "0104", inClusters: "0000,0003,0006,0008", outClusters: "0019"
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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"
|
|
||||||
}
|
|
||||||
|
|
||||||
// UI tile definitions
|
|
||||||
tiles {
|
|
||||||
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
|
|
||||||
state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
|
|
||||||
state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
|
|
||||||
}
|
|
||||||
standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
|
|
||||||
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
|
|
||||||
}
|
|
||||||
controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 3, inactiveLabel: false) {
|
|
||||||
state "level", action:"switch level.setLevel"
|
|
||||||
}
|
|
||||||
valueTile("level", "device.level", inactiveLabel: false, decoration: "flat") {
|
|
||||||
state "level", label:'${currentValue} %', unit:"%", backgroundColor:"#ffffff"
|
|
||||||
}
|
|
||||||
|
|
||||||
main "switch"
|
|
||||||
details (["switch","refresh","level","levelSliderControl"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse incoming device messages to generate events
|
|
||||||
def parse(String description) {
|
|
||||||
/*if (description?.startsWith("catchall: 0104 000A")) {
|
|
||||||
log.debug "Dropping catchall for SmartPower Outlet"
|
|
||||||
return []
|
|
||||||
}*/
|
|
||||||
log.trace description
|
|
||||||
if (description?.startsWith("catchall:")) {
|
|
||||||
def msg = zigbee.parse(description)
|
|
||||||
log.trace msg
|
|
||||||
log.trace "data: $msg.data"
|
|
||||||
if(msg.command == 0x01){
|
|
||||||
if(msg.clusterId == 0x0006 && msg.data[0] == 0x00 && msg.data[1] == 0x00){
|
|
||||||
def name = "switch"
|
|
||||||
def value = (msg.data[4] != 0 ? "on" : "off")
|
|
||||||
log.debug"name:$name,value:$value"
|
|
||||||
def result = createEvent(name: name, value: value)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}else if(msg.command == 0x0b && msg.clusterId == 0x0006){
|
|
||||||
def name = "switch"
|
|
||||||
def value = (msg.data[0] != 0 ? "on" : "off")
|
|
||||||
log.debug"name:$name,value:$value"
|
|
||||||
def result = createEvent(name: name, value: value)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}else if(description?.startsWith("read attr")){
|
|
||||||
def descMap = parseDescriptionAsMap(description)
|
|
||||||
log.debug "Read attr: $description"
|
|
||||||
if(descMap.cluster == "0008" && descMap.attrId == "0000"){
|
|
||||||
def name = "level"
|
|
||||||
def value = Integer.parseInt(descMap.value, 16)
|
|
||||||
value = Math.round(value * 100/255)
|
|
||||||
log.debug"name:$name,value:$value"
|
|
||||||
def result = createEvent(name: name, value: value)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}/*else {
|
|
||||||
log.debug "parse description: $description"
|
|
||||||
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
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
def parseDescriptionAsMap(description) {
|
|
||||||
(description - "read attr - ").split(",").inject([:]) { map, param ->
|
|
||||||
def nameAndValue = param.split(":")
|
|
||||||
map += [(nameAndValue[0].trim()):nameAndValue[1].trim()]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def refresh() {
|
|
||||||
log.debug "refresh()"
|
|
||||||
def cmds = []
|
|
||||||
cmds << "st rattr 0x${device.deviceNetworkId} 1 0x0006 0x0000"
|
|
||||||
cmds << "delay 200"
|
|
||||||
cmds << "st rattr 0x${device.deviceNetworkId} 1 0x0008 0x0000"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commands to device
|
|
||||||
def on() {
|
|
||||||
log.debug "on()"
|
|
||||||
def cmds = []
|
|
||||||
cmds << "st cmd 0x${device.deviceNetworkId} 1 6 1 {}"
|
|
||||||
cmds << "delay 5000"
|
|
||||||
cmds << "st rattr 0x${device.deviceNetworkId} 1 0x0008 0x0000"
|
|
||||||
}
|
|
||||||
|
|
||||||
def off() {
|
|
||||||
log.debug "off()"
|
|
||||||
def cmds = []
|
|
||||||
cmds << "st cmd 0x${device.deviceNetworkId} 1 6 0 {}"
|
|
||||||
cmds << "delay 5000"
|
|
||||||
cmds << "st rattr 0x${device.deviceNetworkId} 1 0x0008 0x0000"
|
|
||||||
}
|
|
||||||
|
|
||||||
def setLevel(value) {
|
|
||||||
log.trace "setLevel($value)"
|
|
||||||
def cmds = []
|
|
||||||
|
|
||||||
if (value == 0) {
|
|
||||||
sendEvent(name: "switch", value: "off")
|
|
||||||
//cmds << "st cmd 0x${device.deviceNetworkId} 1 6 0 {}"
|
|
||||||
}
|
|
||||||
else if (device.latestValue("switch") == "off") {
|
|
||||||
sendEvent(name: "switch", value: "on")
|
|
||||||
//cmds << "st cmd 0x${device.deviceNetworkId} 1 6 1 {}"
|
|
||||||
|
|
||||||
}
|
|
||||||
//def transitionTime = Math.round(Math.abs(((device.currentValue("level")?:0) as int) - (value as int))*0.3)
|
|
||||||
//def transitionTime2 = hexString(transitionTime>>8)
|
|
||||||
//def transitionTime1 = hexString(transitionTime%256)
|
|
||||||
sendEvent(name: "level", value: value)
|
|
||||||
def level = hexString(Math.round(value * 255/100))
|
|
||||||
cmds << "st cmd 0x${device.deviceNetworkId} 1 8 4 {${level} FFFF}"
|
|
||||||
cmds << "delay 5000"
|
|
||||||
cmds << "st rattr 0x${device.deviceNetworkId} 1 0x0008 0x0000"
|
|
||||||
|
|
||||||
log.debug cmds
|
|
||||||
cmds
|
|
||||||
}
|
|
||||||
@@ -11,9 +11,6 @@
|
|||||||
* for the specific language governing permissions and limitations under the License.
|
* for the specific language governing permissions and limitations under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import groovy.transform.Field
|
|
||||||
|
|
||||||
@Field Boolean hasConfiguredHealthCheck = false
|
|
||||||
|
|
||||||
metadata {
|
metadata {
|
||||||
definition (name: "ZLL Dimmer Bulb", namespace: "smartthings", author: "SmartThings") {
|
definition (name: "ZLL Dimmer Bulb", namespace: "smartthings", author: "SmartThings") {
|
||||||
@@ -24,7 +21,6 @@ metadata {
|
|||||||
capability "Refresh"
|
capability "Refresh"
|
||||||
capability "Switch"
|
capability "Switch"
|
||||||
capability "Switch Level"
|
capability "Switch Level"
|
||||||
capability "Health Check"
|
|
||||||
|
|
||||||
//fingerprint profileId: "C05E", inClusters: "0000, 0003, 0004, 0005, 0006, 0008, 1000", outClusters: "0000,0019"
|
//fingerprint profileId: "C05E", inClusters: "0000, 0003, 0004, 0005, 0006, 0008, 1000", outClusters: "0000,0019"
|
||||||
fingerprint profileId: "C05E", inClusters: "0000, 0003, 0004, 0005, 0006, 0008, 1000", outClusters: "0019"
|
fingerprint profileId: "C05E", inClusters: "0000, 0003, 0004, 0005, 0006, 0008, 1000", outClusters: "0019"
|
||||||
@@ -100,38 +96,7 @@ def poll() {
|
|||||||
refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* PING is used by Device-Watch in attempt to reach the Device
|
|
||||||
* */
|
|
||||||
def ping() {
|
|
||||||
return zigbee.levelRefresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
def healthPoll() {
|
|
||||||
log.debug "healthPoll()"
|
|
||||||
def cmds = refresh()
|
|
||||||
cmds.each{ sendHubCommand(new physicalgraph.device.HubAction(it))}
|
|
||||||
}
|
|
||||||
|
|
||||||
def configureHealthCheck() {
|
|
||||||
Integer hcIntervalMinutes = 12
|
|
||||||
if (!hasConfiguredHealthCheck) {
|
|
||||||
log.debug "Configuring Health Check, Reporting"
|
|
||||||
unschedule("healthPoll")
|
|
||||||
runEvery5Minutes("healthPoll")
|
|
||||||
// Device-Watch allows 2 check-in misses from device
|
|
||||||
sendEvent(name: "checkInterval", value: hcIntervalMinutes * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
|
||||||
hasConfiguredHealthCheck = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def configure() {
|
def configure() {
|
||||||
log.debug "configure()"
|
log.debug "Configuring Reporting and Bindings."
|
||||||
zigbee.onOffConfig() + zigbee.levelConfig() + zigbee.onOffRefresh() + zigbee.levelRefresh()
|
zigbee.onOffConfig() + zigbee.levelConfig() + zigbee.onOffRefresh() + zigbee.levelRefresh()
|
||||||
configureHealthCheck()
|
|
||||||
}
|
|
||||||
|
|
||||||
def updated() {
|
|
||||||
log.debug "updated()"
|
|
||||||
configureHealthCheck()
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,6 @@
|
|||||||
* for the specific language governing permissions and limitations under the License.
|
* for the specific language governing permissions and limitations under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import groovy.transform.Field
|
|
||||||
|
|
||||||
@Field Boolean hasConfiguredHealthCheck = false
|
|
||||||
|
|
||||||
metadata {
|
metadata {
|
||||||
definition (name: "ZLL White Color Temperature Bulb", namespace: "smartthings", author: "SmartThings") {
|
definition (name: "ZLL White Color Temperature Bulb", namespace: "smartthings", author: "SmartThings") {
|
||||||
@@ -25,7 +22,6 @@ metadata {
|
|||||||
capability "Refresh"
|
capability "Refresh"
|
||||||
capability "Switch"
|
capability "Switch"
|
||||||
capability "Switch Level"
|
capability "Switch Level"
|
||||||
capability "Health Check"
|
|
||||||
|
|
||||||
attribute "colorName", "string"
|
attribute "colorName", "string"
|
||||||
command "setGenericName"
|
command "setGenericName"
|
||||||
@@ -100,41 +96,9 @@ def poll() {
|
|||||||
zigbee.onOffRefresh() + zigbee.levelRefresh() + zigbee.colorTemperatureRefresh()
|
zigbee.onOffRefresh() + zigbee.levelRefresh() + zigbee.colorTemperatureRefresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* PING is used by Device-Watch in attempt to reach the Device
|
|
||||||
* */
|
|
||||||
def ping() {
|
|
||||||
return zigbee.levelRefresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
def healthPoll() {
|
|
||||||
log.debug "healthPoll()"
|
|
||||||
def cmds = zigbee.onOffRefresh() + zigbee.levelRefresh()
|
|
||||||
cmds.each{ sendHubCommand(new physicalgraph.device.HubAction(it))}
|
|
||||||
}
|
|
||||||
|
|
||||||
def configureHealthCheck() {
|
|
||||||
Integer hcIntervalMinutes = 12
|
|
||||||
if (!hasConfiguredHealthCheck) {
|
|
||||||
log.debug "Configuring Health Check, Reporting"
|
|
||||||
unschedule("healthPoll")
|
|
||||||
runEvery5Minutes("healthPoll")
|
|
||||||
// Device-Watch allows 2 check-in misses from device
|
|
||||||
sendEvent(name: "checkInterval", value: hcIntervalMinutes * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
|
||||||
hasConfiguredHealthCheck = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def configure() {
|
def configure() {
|
||||||
log.debug "configure()"
|
log.debug "Configuring Reporting and Bindings."
|
||||||
configureHealthCheck()
|
|
||||||
zigbee.onOffConfig() + zigbee.levelConfig() + zigbee.colorTemperatureConfig() + zigbee.onOffRefresh() + zigbee.levelRefresh() + zigbee.colorTemperatureRefresh()
|
zigbee.onOffConfig() + zigbee.levelConfig() + zigbee.colorTemperatureConfig() + zigbee.onOffRefresh() + zigbee.levelRefresh() + zigbee.colorTemperatureRefresh()
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
def updated() {
|
|
||||||
log.debug "updated()"
|
|
||||||
configureHealthCheck()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def setColorTemperature(value) {
|
def setColorTemperature(value) {
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
/**
|
||||||
|
* My SmartThings API App
|
||||||
|
*
|
||||||
|
* Copyright 2016 EM
|
||||||
|
*
|
||||||
|
* 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: "EM SmartThings API App",
|
||||||
|
namespace: "smartthing-em",
|
||||||
|
author: "Keval Parekh",
|
||||||
|
description: "This app will show the status of door sensors. ",
|
||||||
|
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",
|
||||||
|
oauth: true)
|
||||||
|
|
||||||
|
|
||||||
|
preferences(oauthPage: "deviceAuthorization") {
|
||||||
|
page(name: "deviceAuthorization"){
|
||||||
|
section("Allow Endpoint to Control These Things...") {
|
||||||
|
input "doorsensors", "capability.contactSensor", title: "Which Door?", multiple: true, required: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mappings {
|
||||||
|
//Doors
|
||||||
|
path("/doorsensors") {
|
||||||
|
action: [
|
||||||
|
GET: "listDoorSensors"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/doorsensors/:id") {
|
||||||
|
action: [
|
||||||
|
GET: "showDoorSensor"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/doorsensors/:id/:events") {
|
||||||
|
action: [
|
||||||
|
GET: "showDoorSensorEvents"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def installed() {
|
||||||
|
log.debug "Installed with settings: ${settings}"
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
def updated() {
|
||||||
|
log.debug "Updated with settings: ${settings}"
|
||||||
|
unsubscribe()
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
def initialize() {
|
||||||
|
subscribe(doorsensors, "contact.closed", DoorSensorDeviceHandler)
|
||||||
|
subscribe(doorsensors, "contact.open", DoorSensorDeviceHandler)
|
||||||
|
}
|
||||||
|
|
||||||
|
//Handler for door sensor
|
||||||
|
def DoorSensorDeviceHandler(evt){
|
||||||
|
log.debug "Door status changed to ${evt.value}"
|
||||||
|
//This URL will notify user for door sensor change event
|
||||||
|
httpPost(uri: "http://vps49294.vps.ovh.ca/fcall/webservice/smart_home/smart_home_user_notifications.php?deviceId=${evt.deviceId}&deviceValue=${evt.value}&isoDate=${evt.isoDate}")
|
||||||
|
{
|
||||||
|
resp -> log.debug "response data: ${resp.data}"
|
||||||
|
log.debug evt.name+" Event data successfully posted"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Door Sensor Methods
|
||||||
|
|
||||||
|
//This method will get all door sensors
|
||||||
|
def listDoorSensors() {
|
||||||
|
doorsensors?.collect{[type: "door", id: it.id, name: it.displayName, status: it.currentValue('contact')]}?.sort{it.name}
|
||||||
|
}
|
||||||
|
|
||||||
|
//This method will get detail for specified door sensor
|
||||||
|
def showDoorSensor() {
|
||||||
|
show(doorsensors, "contact")
|
||||||
|
}
|
||||||
|
|
||||||
|
//This method will fetch the event for specified door sensor
|
||||||
|
def showDoorSensorEvents() {
|
||||||
|
log.debug "called....."
|
||||||
|
getEvents(doorsensors, "status")
|
||||||
|
}
|
||||||
|
|
||||||
|
private show(devices, type) {
|
||||||
|
def device = devices.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
def attributeName = type == "motionSensor" ? "motion" : type
|
||||||
|
def s = device.currentState(attributeName)
|
||||||
|
[id: device.id, label: device.displayName, value: s?.value, unitTime: s?.date?.time, type: type]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getEvents(devices, type) {
|
||||||
|
log.debug " events data requested.."
|
||||||
|
def device = devices.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
def events = device.eventsSince(new Date() - 364)
|
||||||
|
events = events.findAll{it.name == type}
|
||||||
|
def result = events.collect{item(device, it)}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private item(device, s) {
|
||||||
|
device && s ? [uid: s.id, device_id: device.id, label: device.displayName, name: s.name, value: s.value, date: s.date] : null
|
||||||
|
}
|
||||||
|
|
||||||
|
private device(it, type) {
|
||||||
|
it ? [id: it.id, label: it.label, type: type] : null
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user