Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * 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. * 2017 */
- metadata {
- definition(name:"Curtains", namespace:"SmartHomeDB", author:"SmartHomeDB: Ray Zheng") {
- capability "Actuator"
- capability "Configuration"
- capability "Refresh"
- //capability "Switch Level"
- capability "WindowShade"
- capability "Switch"
- fingerprint deviceId:"0104", inClusters:"0000, 0001, 0005, 0004, 0102", outClusters:"0019", manufacturer:"SmartHomeDB", model:"093199ff04984948b4c78167c8e7f47e"
- }
- }
- command "levelOpenClose"
- preferences {
- input name:"mode", type:"bool", title:"Set SmartHomeDB Curtain Direction", description:"Reverse Mode ON", required:true, displayDuringSetup:true
- input name: "debugOutput", type: "bool", title: "<b>Enable debug logging?</b>", description: "<br>", defaultValue: true
- }
- def configure() {
- if (debugOutput) log.debug "Configure"
- }
- def updated() {
- if (debugOutput) runIn(1800,logsOff)
- }
- /* Parse incoming device messages to generate events
- specification: windowShade - ENUM ["opening", "partially open", "closed", "open", "closing", "unknown"] <-- these are the only
- values that attribute "windowShade" may contain
- */
- def parse(String description) {
- def parseMap = zigbee.parseDescriptionAsMap(description)
- def event = zigbee.getEvent(description)
- if (debugOutput) log.debug(parseMap)
- try {
- if (parseMap.raw.startsWith("0104")) {
- if (debugOutput) log.debug "Curtain"
- }else if (parseMap.raw.endsWith("0007")) {
- if (debugOutput) log.debug "running…"
- }else if (parseMap.endpoint.endsWith("01")) {
- if (parseMap["cluster"] == "0102" && parseMap["attrId"] == "0008") {
- long theValue = Long.parseLong(parseMap["value"], 16)
- def eventStack = []
- if (debugOutput) log.debug(theValue)
- if (debugOutput) log.debug(mode)
- if (mode == true) {
- if (theValue > 95) {
- if (debugOutput) log.debug "Just Closed"
- eventStack.push(createEvent(name:"windowShade", value:"closed"))
- }else if (theValue < 5) {
- if (debugOutput) log.debug "Just Fully Open"
- eventStack.push(createEvent(name:"windowShade", value:"open"))
- }else {
- if (debugOutput) log.debug "Motion"
- eventStack.push(createEvent(name:"windowShade", value:"unknown"))
- }
- }
- else {
- if (theValue < 5) {
- if (debugOutput) log.debug "Just Fully Open mode null"
- eventStack.push(createEvent(name:"windowShade", value:"open"))
- }else if (theValue > 95) {
- if (debugOutput) log.debug "Just Closed mode null"
- eventStack.push(createEvent(name:"windowShade", value:"closed"))
- }else {
- if (debugOutput) log.debug "In Motion"
- eventStack.push(createEvent(name:"windowShade", value:"unknown"))
- }
- }
- return eventStack
- }
- }else {
- if (debugOutput) log.debug "Unhandled Event - description:${description}, parseMap:${parseMap}, event:${event}"
- }
- if (event["name"] == "switch") {
- if (debugOutput) log.debug("add event: ${event}")
- return createEvent(name:"switch", value:event["value"])
- }
- }catch (Exception e) {
- log.warn e
- }
- }
- def off() { close() }
- def close() {
- if (debugOutput) log.debug "Set Close"
- if (mode == true) {
- zigbee.command(0x0102, 0x00)
- }else {
- zigbee.command(0x0102, 0x01)
- }
- }
- def on() { open() }
- def open() {
- if (debugOutput) log.debug "Set Open"
- if (mode == true) {
- zigbee.command(0x0102, 0x01)
- }else {
- zigbee.command(0x0102, 0x00)
- }
- }
- def setPosition(val) {
- if (debugOutput) log.debug "unImplemented: Set Position $val %"
- }
- def levelOpenClose(val) {
- if (debugOutput) log.debug "unImplemented: Set Level Open/Close"
- }
- def refresh() {
- if (debugOutput) log.debug "refresh()"
- zigbee.command(0x0102, 0x02)
- }
- def logsOff(){
- log.warn "debug logging disabled..."
- device.updateSetting("debugOutput",[value:"false",type:"bool"])
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement