Skip to content

Commit

Permalink
WWST-955 Orvibo Motion Sensor (SmartThingsCommunity#3210)
Browse files Browse the repository at this point in the history
* add Orvibo Motion sensor DTH

add Orvibo Motion sensor DTH referring to Orvibo ZCL info.

* add Orvibo Motion sensor DTH

add Orvibo Motion sensor DTH referring to Orvibo ZCL info.

* update Orvibo motion sensor.

update Orvibo motion sensor.

* remove used code

update Orvibo motion sensor , removed used dth code

* update orvibo dth

update orvibo dth

* add model id for orvibo sensor.

add model id in fingerprint , fixed battery return null bug .

* add ovribo motion sensor install inital state poll

[body]

* using tab installed space .

* remove fake attribute in install function

remove command configrure report .
the orvibo vendor did not support it .
The battery attribute is reported without bind and reporting CFG.
the NXP plan reports the electricity once in 20 minutes.

* optimize the dth code

* remove whitespace
  • Loading branch information
jinkangzhangS authored and greens committed Jul 17, 2018
1 parent 8f88e4c commit fead801
Showing 1 changed file with 140 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* Copyright 2018 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.
* Author : jinkang zhang / [email protected]
* Date : 2018-07-04
*/
import physicalgraph.zigbee.clusters.iaszone.ZoneStatus
import physicalgraph.zigbee.zcl.DataType
metadata {
definition(name: "Orvibo Motion Sensor", namespace: "smartthings", author: "SmartThings", runLocally: false, minHubCoreVersion: '000.017.0012', executeCommandsLocally: false, mnmn: "SmartThings", vid: "generic-motion-2") {
capability "Motion Sensor"
capability "Configuration"
capability "Battery"
capability "Refresh"
capability "Health Check"
capability "Sensor"
fingerprint profileId: "0104", deviceId: "0402", inClusters: "0000,0003,0500,0001", manufacturer: "ORVIBO",model:"895a2d80097f4ae2b2d40500d5e03dcc"
}
simulator {
status "active": "zone status 0x0001 -- extended status 0x00"
for (int i = 0; i <= 100; i += 11) {
status "battery ${i}%": "read attr - raw: 2E6D01000108210020C8, dni: 2E6D, endpoint: 01, cluster: 0001, size: 08, attrId: 0021, encoding: 20, value: ${i}"
}
}
tiles(scale: 2) {
multiAttributeTile(name: "motion", type: "generic", width: 6, height: 4) {
tileAttribute("device.motion", key: "PRIMARY_CONTROL") {
attributeState "active", label: 'motion', icon: "st.motion.motion.active", backgroundColor: "#00A0DC"
attributeState "inactive", label: 'no motion', icon: "st.motion.motion.inactive", backgroundColor: "#cccccc"
}
}
valueTile("battery", "device.battery", decoration: "flat", inactiveLabel: false, width: 2, height: 2) {
state "battery", label: '${currentValue}% battery', unit: ""
}
standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "default", action: "refresh.refresh", icon: "st.secondary.refresh"
}
main(["motion"])
details(["motion","battery", "refresh"])
}
}
def stopMotion() {
log.debug "motion inactive"
sendEvent(getMotionResult(false))
}
def installed(){
log.debug "installed"
return zigbee.readAttribute(zigbee.POWER_CONFIGURATION_CLUSTER, 0x0021) +
zigbee.readAttribute(zigbee.IAS_ZONE_CLUSTER,zigbee.ATTRIBUTE_IAS_ZONE_STATUS)

}
def parse(String description) {
log.debug "description(): $description"
def map = zigbee.getEvent(description)
if(!map){
if (description?.startsWith('zone status')) {
map = parseIasMessage(description)
motionHandler(description);
} else {
map = batteyHandler(description);
}
}
log.debug "Parse returned $map"
def result = map ? createEvent(map) : [:]
if (description?.startsWith('enroll request')) {
List cmds = zigbee.enrollResponse()
log.debug "enroll response: ${cmds}"
result = cmds?.collect { new physicalgraph.device.HubAction(it) }
}
return result
}
def batteyHandler(String description){
def descMap = zigbee.parseDescriptionAsMap(description)
def map = [:]
if (descMap?.clusterInt == zigbee.POWER_CONFIGURATION_CLUSTER && descMap.commandInt != 0x07 && descMap.value) {
map = getBatteryPercentageResult(Integer.parseInt(descMap.value, 16))
}
return map;
}
def motionHandler(String description){
//inactive
def isActive = zigbee.translateStatusZoneType19(description)
if (isActive) {
def timeout = 3
log.debug "Stopping motion in ${timeout} seconds"
runIn(timeout, stopMotion)
}
}
def parseIasMessage(String description) {
ZoneStatus zs = zigbee.parseZoneStatus(description)
return getMotionResult(zs.isAlarm1Set() || zs.isAlarm2Set())
}
def getBatteryPercentageResult(rawValue) {
log.debug "Battery Percentage rawValue = ${rawValue} -> ${rawValue / 2}%"
def result = [:]
if (0 <= rawValue && rawValue <= 200) {
result.name = 'battery'
result.translatable = true
result.value = Math.round(rawValue / 2)
result.descriptionText = "${device.displayName} battery was ${result.value}%"
}
return result
}
def getMotionResult(value) {
def descriptionText = value ? "${device.displayName} detected motion" : "${device.displayName} motion has stopped"
return [
name : 'motion',
value : value ? 'active' : 'inactive',
descriptionText : descriptionText,
translatable : true
]
}
/**
* PING is used by Device-Watch in attempt to reach the Device
* */
def ping() {
log.debug "ping "
return zigbee.readAttribute(zigbee.IAS_ZONE_CLUSTER, zigbee.ATTRIBUTE_IAS_ZONE_STATUS) + zigbee.readAttribute(zigbee.POWER_CONFIGURATION_CLUSTER, 0x0021)
}
def refresh() {
log.debug "Refreshing Values"
return zigbee.readAttribute(zigbee.POWER_CONFIGURATION_CLUSTER, 0x0021) +
zigbee.readAttribute(zigbee.IAS_ZONE_CLUSTER,zigbee.ATTRIBUTE_IAS_ZONE_STATUS) +
zigbee.enrollResponse()
}
def configure() {
log.debug "configure"
sendEvent(name: "checkInterval", value:20 * 60 + 2*60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID, offlinePingable: "1"])
}

0 comments on commit fead801

Please sign in to comment.