Compare commits

..

1 Commits

3 changed files with 199 additions and 150 deletions

View File

@@ -0,0 +1,195 @@
/**
* Climax PSM-29ZBSR - Zigbee - Power Outlet Switch and Energy Meter
*
* 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:
*
* 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.
*
* Thanks to SmartThings and its community!
*
* Product Page: http://www.climax.com.tw/psm29zb-zb.php
* Developer manual https://fccid.io/document.php?id=2553357
*
*/
metadata {
definition (name: "Climax Power Outlet", namespace: "bortuzar", author: "bortuzar") {
capability "Actuator"
capability "Configuration"
capability "Refresh"
capability "Sensor"
capability "Switch"
capability "Power Meter"
fingerprint endpointId: "0x0A", profileId: "0104", inClusters: "0000,0003,0004,0005,0006,0702", outClusters: "0000"
}
// 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 "on", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"turningOff"
state "off", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
state "turningOn", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"turningOff"
state "turningOff", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
}
standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
}
valueTile("power", "device.power", inactiveLabel: false, decoration: "flat") {
state "power", label: '${currentValue} W'
}
//standardTile("configure", "device.power", inactiveLabel: false, decoration: "flat") {
// state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure"
//}
main(["switch", "power"])
details(["switch", "power", "refresh"])
}
}
// Parse incoming device messages to generate events
def parse(String description) {
log.debug "Parse Method Called"
log.trace description
if (description?.startsWith("catchall:")) {
def msg = zigbee.parse(description)
log.trace "data: $msg.data"
} else if (description?.startsWith("read attr -")) {
def descMap = parseDescriptionAsMap(description)
log.debug "Desc Map:"
log.debug descMap
if (descMap.cluster == "0006" && descMap.attrId == "0000") {
name = "switch"
value = descMap.value.endsWith("01") ? "on" : "off"
def result = createEvent(name: name, value: value)
log.debug "Parse returned ${result?.descriptionText}"
return result
} else if(descMap.cluster =="0702" && descMap.attrId == "0400") {
def value = convertHexToInt(descMap.value[-4..-1])/10
// Reading the last 4 characters of the string...Maybe 4 are needed. Needs further test.
// Dividing by 10 as the Divisor is 10000 and unit is kW for the device. AttrId: 0302 and 0300. Simplifying to 10
log.debug value
def name = "power"
def result = createEvent(name: name, value: value)
log.debug "Parse returned ${result?.descriptionText}"
return result
}
} 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
}
}
def on() {
log.debug "On Method called"
sendEvent(name: "switch", value: "on")
"st cmd 0x${device.deviceNetworkId} 1 6 1 {}"
}
def off() {
log.debug "Off Method called"
sendEvent(name: "switch", value: "off")
"st cmd 0x${device.deviceNetworkId} 1 6 0 {}"
}
def refresh() {
log.debug "Refresh Method called";
//read attribute 1024Decimal, translates to 400Hex.
[
"st rattr 0x${device.deviceNetworkId} 1 6 0", "delay 500",
"st rattr 0x${device.deviceNetworkId} 1 0x0702 1024", , "delay 500"
]
}
def configure() {
log.debug "Configure Method called"
String zigbeeId = swapEndianHex(device.hub.zigbeeId)
def configCmds = [
//Switch Reporting
"zcl global send-me-a-report 6 0 0x10 0 3600 {01}", "delay 500",
"send 0x${device.deviceNetworkId} 1 1", "delay 1000",
//bing to cluster 0x006. Switch On-Off
"zdo bind 0x${device.deviceNetworkId} 1 1 6 {${device.zigbeeId}} {}", "delay 1000",
//bind to cluster 0x702. Power Consumption
"zdo bind 0x${device.deviceNetworkId} 1 1 0x0702 {${device.zigbeeId}} {}", "delay 500",
]
return configCmds + refresh() // send refresh cmds as part of config
}
def parseDescriptionAsMap(description) {
(description - "read attr - ").split(",").inject([:]) { map, param ->
def nameAndValue = param.split(":")
map += [(nameAndValue[0].trim()):nameAndValue[1].trim()]
}
}
private hex(value, width=2) {
def s = new BigInteger(Math.round(value).toString()).toString(16)
while (s.size() < width) {
s = "0" + s
}
s
}
private Integer convertHexToInt(hex) {
Integer.parseInt(hex,16)
}
private String swapEndianHex(String hex) {
reverseArray(hex.decodeHex()).encodeHex()
}
private byte[] reverseArray(byte[] array) {
int i = 0;
int j = array.length - 1;
byte tmp;
while (j > i) {
tmp = array[j];
array[j] = array[i];
array[i] = tmp;
j--;
i++;
}
return array
}

View File

@@ -1,142 +0,0 @@
definition (
name: "Leave home secure",
namespace: "richardneville",
author: "Richard Neville",
description: "Tells us if the doors and windows are open when we go out.",
category: "My Apps",
iconUrl: "http://animl.co.uk/img/SmartThingsLeaveHomeSecure.png",
iconX2Url: "http://animl.co.uk/img/SmartThingsLeaveHomeSecure@2x.png",
iconX3Url: "http://animl.co.uk/img/SmartThingsLeaveHomeSecure@2x.png"
)
preferences {
section("Things to report on") {
input "contactSensorThings", "capability.contactSensor", required: true, multiple: true,
title: "Select which things to watch:"
paragraph "This SmartApp reports if the doors and windows are left open when we go out. The report can be triggered in various ways. v0.1"
}
section("Things to trigger the report") {
input "presenceThings", "capability.presenceSensor", required: false, multiple: true,
title: "Notify when these things leave home:"
input "contactSensorTrigger", "capability.contactSensor", required: false, multiple: true,
title: "Notify when this thing closes:"
input "motionSensorThing", "capability.motionSensor", required: false, multiple: true,
title: "Notify when movement is detected near this thing:"
}
section("Settings") {
input "fullReport", "bool", title: "Full report, even if things are closed?", required: false
input "pushNotification", "bool", title: "Push the message out?", required: false
input("recipients", "contact", title: "Send messages to:") {
input "phone", "phone", title: "Send an SMS to:", description: "Phone Number", required: false
}
paragraph "(If no recipients are selected, app will just send a push notification instead.)"
}
}
def installed() {
initialize()
}
def updated() {
unsubscribe()
initialize()
}
def initialize() {
subscribe(presenceThings, "presence", presenceHandler)
subscribe(contactSensorTrigger, "contact", contactHandler)
subscribe(motionSensorThing, "motion", motionHandler)
/*
subscribe(switchThing, "switch", switchHandler)
*/
}
def presenceHandler(evt) {
if (evt.value == "not present") {
if (allThingsLeftHome()) {
checkIfHouseSecure()
}
}
}
def contactHandler(evt) {
if (evt.value == "closed") {
checkIfHouseSecure()
}
}
def motionHandler(evt) {
if (evt.value == "active") {
// motion detected
checkIfHouseSecure()
} else if (evt.value == "inactive") {
// motion stopped
}
}
/*
def switchHandler(evt) {
if (debugMode) {
checkIfHouseSecure()
}
}
*/
private checkIfHouseSecure() {
for (contactSensorThing in contactSensorThings) {
def sensorState = contactSensorThing.currentState("contact").value
if (sensorState == "open" || fullReport) {
sendMsg("${contactSensorThing.displayName} is ${sensorState}.")
}
}
}
private allThingsLeftHome() {
def result = true
for (presenceThing in presenceThings) {
if (presenceThing.currentPresence == "present") {
// someone is present, so set result to false and terminate the loop.
result = false
break
}
}
return result
}
private sendMsg(msg) {
if (pushNotification) {
// check that contact book is enabled and recipients selected
if (location.contactBookEnabled && recipients) {
sendNotificationToContacts(msg, recipients)
} else if (phone) { // check that the user did select a phone number
sendNotificationEvent("SMS sent to ${phone}")
sendSms(phone, msg)
//sendNotification(msg, [method: "phone", phone: "1234567890"])
} else {
sendPush(msg)
}
} else {
sendNotificationEvent(msg)
}
}
/*
def switchHandler(evt) {
if (evt.value == "on") {
//sendPush("The ${switchThing.displayName} is on!")
} else if (evt.value == "off") {
//sendPush("The ${switchThing.displayName} is off!")
}
}
def contactHandler(evt) {
if (evt.value == "open") {
// contactSensor open
} else if (evt.value == "closed") {
// contactSensor closed
}
}
*/

View File

@@ -50,7 +50,7 @@ preferences {
}
section("Send Notifications?") {
input("recipients", "contact", title: "Send notifications to") {
input "phone", "phone", title: "Send an SMS to this number?", required:false
input "phone", "phone", title: "Send an SMS to this number?"
}
}
@@ -266,9 +266,7 @@ def sendAway(msg) {
}
else {
sendPush(msg)
if(phone){
sendSms(phone, msg)
}
sendSms(phone, msg)
}
}
@@ -282,9 +280,7 @@ def sendHome(msg) {
}
else {
sendPush(msg)
if(phone){
sendSms(phone, msg)
}
sendSms(phone, msg)
}
}
@@ -343,4 +339,4 @@ private getTimeIntervalLabel() {
private hideOptionsSection() {
(starting || ending || days || modes) ? false: true
}
}