mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-21 21:03:47 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d0385f6fe |
@@ -0,0 +1,171 @@
|
|||||||
|
/**
|
||||||
|
* Fibaro Wall Plug ZW3
|
||||||
|
*
|
||||||
|
* Copyright 2016 Fibar Group S.A.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
metadata {
|
||||||
|
definition (name: "Fibaro Wall Plug ZW3", namespace: "fibargroup", author: "Fibar Group S.A.") {
|
||||||
|
capability "Actuator"
|
||||||
|
capability "Configuration"
|
||||||
|
capability "Energy Meter"
|
||||||
|
capability "Power Meter"
|
||||||
|
capability "Refresh"
|
||||||
|
capability "Sensor"
|
||||||
|
capability "Switch"
|
||||||
|
|
||||||
|
command "reset"
|
||||||
|
|
||||||
|
fingerprint deviceId: "0x1001", inClusters: "0x72, 0x86, 0x70, 0x85, 0x25, 0x9C, 0x71, 0x73, 0x32, 0x31, 0x7A", outClusters: "0x25" //v 2.2
|
||||||
|
fingerprint deviceId: "0x1000", inClusters: "0x72, 0x86, 0x70, 0x85, 0x8E, 0x25, 0x73, 0x32, 0x31, 0x7A", outClusters: "0x25, 0x31, 0x32" //v2.4+
|
||||||
|
}
|
||||||
|
|
||||||
|
simulator {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
tiles(scale: 2) {
|
||||||
|
multiAttributeTile(name:"FGWP", type:"lighting", width:6, height:4) {//with generic type secondary control text is not displayed in Android app
|
||||||
|
tileAttribute("device.switch", key:"PRIMARY_CONTROL") {
|
||||||
|
attributeState("on", label: '${name}', action: "switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821")
|
||||||
|
attributeState("off", label: '${name}', action: "switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff")
|
||||||
|
}
|
||||||
|
|
||||||
|
tileAttribute("device.power", key:"SECONDARY_CONTROL") {
|
||||||
|
attributeState("default", label:'${currentValue} W', backgroundColor:"#ffffff")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
valueTile("energy", "device.energy", width: 2, height: 2) {
|
||||||
|
state "default", label:'${currentValue} kWh'
|
||||||
|
}
|
||||||
|
standardTile("reset", "device.energy", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||||
|
state "default", label:'reset kWh', action:"reset"
|
||||||
|
}
|
||||||
|
standardTile("refresh", "device.power", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||||
|
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
|
||||||
|
}
|
||||||
|
|
||||||
|
main "FGWP"
|
||||||
|
details(["FGWP", "energy", "reset", "refresh"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse events into attributes
|
||||||
|
def parse(String description) {
|
||||||
|
log.debug "Parsing '${description}'"
|
||||||
|
|
||||||
|
def cmd = zwave.parse(description, [0x25: 1, 0x31: 2, 0x32: 1, 0x72: 1, 0x86: 1])
|
||||||
|
|
||||||
|
if (cmd) {
|
||||||
|
log.debug "Parsed '${cmd}'"
|
||||||
|
zwaveEvent(cmd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv1.ManufacturerSpecificReport cmd) {
|
||||||
|
log.debug "manufacturerId: ${cmd.manufacturerId}"
|
||||||
|
log.debug "manufacturerName: ${cmd.manufacturerName}"
|
||||||
|
log.debug "productId: ${cmd.productId}"
|
||||||
|
log.debug "productTypeId: ${cmd.productTypeId}"
|
||||||
|
}
|
||||||
|
|
||||||
|
def zwaveEvent(physicalgraph.zwave.commands.versionv1.VersionReport cmd) {
|
||||||
|
updateDataValue("version", "${cmd.applicationVersion}.${cmd.applicationSubVersion}")
|
||||||
|
log.debug "applicationVersion: ${cmd.applicationVersion}"
|
||||||
|
log.debug "applicationSubVersion: ${cmd.applicationSubVersion}"
|
||||||
|
log.debug "zWaveLibraryType: ${cmd.zWaveLibraryType}"
|
||||||
|
log.debug "zWaveProtocolVersion: ${cmd.zWaveProtocolVersion}"
|
||||||
|
log.debug "zWaveProtocolSubVersion: ${cmd.zWaveProtocolSubVersion}"
|
||||||
|
}
|
||||||
|
|
||||||
|
def zwaveEvent(physicalgraph.zwave.commands.meterv1.MeterReport cmd) {
|
||||||
|
if (cmd.scale == 0) {
|
||||||
|
createEvent(name: "energy", value: cmd.scaledMeterValue, unit: "kWh")
|
||||||
|
} else if (cmd.scale == 2) {
|
||||||
|
createEvent(name: "power", value: Math.round(cmd.scaledMeterValue), unit: "W")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def zwaveEvent(physicalgraph.zwave.commands.sensormultilevelv2.SensorMultilevelReport cmd) {
|
||||||
|
def map = [ displayed: true ]
|
||||||
|
if (cmd.sensorType == 4) {
|
||||||
|
createEvent(name: "power", value: Math.round(cmd.scaledSensorValue), unit: "W")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
|
||||||
|
createEvent(name: "switch", value: cmd.value ? "on" : "off", type: "digital")
|
||||||
|
}
|
||||||
|
|
||||||
|
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
||||||
|
log.debug "$device.displayName: Unhandled: $cmd"
|
||||||
|
[:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle commands
|
||||||
|
def configure() {
|
||||||
|
log.debug "Executing 'configure'"
|
||||||
|
|
||||||
|
def cmds = []
|
||||||
|
cmds += zwave.manufacturerSpecificV1.manufacturerSpecificGet()
|
||||||
|
cmds += zwave.versionV1.versionGet()
|
||||||
|
//this group is associated automatically upon inclusion, but it is not needed
|
||||||
|
//group 3 should be set instead
|
||||||
|
cmds += zwave.associationV2.associationRemove(groupingIdentifier:1, nodeId:[zwaveHubNodeId])
|
||||||
|
cmds += zwave.associationV2.associationSet(groupingIdentifier:3, nodeId:[zwaveHubNodeId])
|
||||||
|
cmds += zwave.meterV2.meterGet(scale:0)
|
||||||
|
cmds += zwave.meterV2.meterGet(scale:2)
|
||||||
|
cmds += zwave.switchBinaryV1.switchBinaryGet()
|
||||||
|
|
||||||
|
sequence(cmds, 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
def refresh() {
|
||||||
|
log.debug "Executing 'refresh'"
|
||||||
|
|
||||||
|
def cmds = []
|
||||||
|
cmds += zwave.meterV2.meterGet(scale:0)
|
||||||
|
cmds += zwave.meterV2.meterGet(scale:2)
|
||||||
|
cmds += zwave.switchBinaryV1.switchBinaryGet()
|
||||||
|
|
||||||
|
sequence(cmds, 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
def reset() {
|
||||||
|
log.debug "Executing 'reset'"
|
||||||
|
zwave.meterV2.meterReset().format()
|
||||||
|
}
|
||||||
|
|
||||||
|
def on() {
|
||||||
|
log.debug "Executing 'on'"
|
||||||
|
|
||||||
|
def cmds = []
|
||||||
|
cmds += zwave.switchBinaryV1.switchBinarySet(switchValue: 0xFF)
|
||||||
|
cmds += zwave.switchBinaryV1.switchBinaryGet()//for ZW3 version Report is not automatically sent after receiving Set frame
|
||||||
|
|
||||||
|
sequence(cmds)
|
||||||
|
}
|
||||||
|
|
||||||
|
def off() {
|
||||||
|
log.debug "Executing 'off'"
|
||||||
|
|
||||||
|
def cmds = []
|
||||||
|
cmds += zwave.switchBinaryV1.switchBinarySet(switchValue: 0x00)
|
||||||
|
cmds += zwave.switchBinaryV1.switchBinaryGet()//for ZW3 version Report is not automatically sent after receiving Set frame
|
||||||
|
|
||||||
|
sequence(cmds)
|
||||||
|
}
|
||||||
|
|
||||||
|
private sequence(commands, delay=200) {
|
||||||
|
delayBetween(commands.collect{ it.format() }, delay)
|
||||||
|
}
|
||||||
@@ -1,159 +0,0 @@
|
|||||||
/**
|
|
||||||
* InfluxdbShipper
|
|
||||||
*
|
|
||||||
* Copyright 2016 Prune - prune@lecentre.net
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* Description :
|
|
||||||
* This application listen to sensors and send the result metric to an Influxdb 0.9.x or newer server.
|
|
||||||
* It is NOT compatible with Influxdb 0.8.x
|
|
||||||
*
|
|
||||||
* Check Influxdb docs at
|
|
||||||
* https://docs.influxdata.com/influxdb/v0.10/introduction/
|
|
||||||
*
|
|
||||||
* Usage :
|
|
||||||
* select sensors you want to monitor
|
|
||||||
* enter your InfluxDB URL with full informations :
|
|
||||||
*
|
|
||||||
* <host>:<port>
|
|
||||||
*
|
|
||||||
* Ex : www.myserver.ca:8086/write
|
|
||||||
*
|
|
||||||
* It is strongly encouraged to use HTTPS and a login/password as your Influxdb server need to be open to the world
|
|
||||||
*/
|
|
||||||
definition(
|
|
||||||
name: "InfluxdbShipper",
|
|
||||||
namespace: "Prune",
|
|
||||||
author: "Prune",
|
|
||||||
description: "stream metrics to Influxdb",
|
|
||||||
category: "My Apps",
|
|
||||||
iconUrl: "http://lkhill.com/wp/wp-content/uploads/2015/10/influxdb-logo.png",
|
|
||||||
iconX2Url: "http://lkhill.com/wp/wp-content/uploads/2015/10/influxdb-logo.png",
|
|
||||||
iconX3Url: "http://lkhill.com/wp/wp-content/uploads/2015/10/influxdb-logo.png")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
preferences {
|
|
||||||
section("Log devices...") {
|
|
||||||
input "temperatures", "capability.temperatureMeasurement", title: "Temperatures", required:false, multiple: true
|
|
||||||
input "humidity", "capability.relativeHumidityMeasurement", title: "Humidity", required:false, multiple: true
|
|
||||||
input "contacts", "capability.contactSensor", title: "Doors open/close", required: false, multiple: true
|
|
||||||
input "motions", "capability.motionSensor", title: "Motions", required: false, multiple: true
|
|
||||||
input "presence", "capability.presenceSensor", title: "Presence", required: false, multiple: true
|
|
||||||
input "switches", "capability.switch", title: "Switches", required: false, multiple: true
|
|
||||||
input "energy", "capability.energyMeter", title: "Energy", required: false, multiple: true
|
|
||||||
input "smoke", "capability.smokeDetector", title: "Smoke", required: false, multiple: true
|
|
||||||
}
|
|
||||||
|
|
||||||
section ("Influxdb URL...") {
|
|
||||||
input "influxdb_url", "text", title: "Influxdb URL"
|
|
||||||
input "influxdb_proto", "enum", title: "Protocol (http or https)", options: ["HTTP", "HTTPS"]
|
|
||||||
input "influxdb_db", "text", title: "Influxdb DB"
|
|
||||||
input "influxdb_login", "text", title: "Influxdb Login"
|
|
||||||
input "influxdb_password", "password", title: "Influxdb Password"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def installed() {
|
|
||||||
initialize()
|
|
||||||
}
|
|
||||||
|
|
||||||
def updated() {
|
|
||||||
unsubscribe()
|
|
||||||
initialize()
|
|
||||||
}
|
|
||||||
|
|
||||||
def initialize() {
|
|
||||||
/*subscribe(temperatures, "temperature", handleTemperatureEvent)
|
|
||||||
subscribe(contacts, "contact", handleContactEvent)
|
|
||||||
subscribe(accelerations, "acceleration", handleAccelerationEvent)
|
|
||||||
subscribe(motions, "motion", handleMotionEvent)
|
|
||||||
subscribe(presence, "presence", handlePresenceEvent)
|
|
||||||
subscribe(switches, "switch", handleSwitchEvent)
|
|
||||||
log.debug "Done subscribing to events"
|
|
||||||
*/
|
|
||||||
//log.debug "temperatures: ${temperatures[0].name} = ${temperatures[0].currentState("temperature").value}"
|
|
||||||
// Send data every 5 mins
|
|
||||||
runEvery5Minutes(updateCurrentStats)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Push data to Influx
|
|
||||||
*/
|
|
||||||
def updateCurrentStats() {
|
|
||||||
|
|
||||||
//log.debug "Logging to Influxdb ${influxdb_url}"
|
|
||||||
// Builds the URL that will be sent to Influxdb
|
|
||||||
def full_url = "${influxdb_proto}://${influxdb_url}/write?db=${influxdb_db}"
|
|
||||||
if (influxdb_login != "") {
|
|
||||||
full_url += "&u=${influxdb_login}&p=${influxdb_password}"
|
|
||||||
}
|
|
||||||
|
|
||||||
def full_body=""
|
|
||||||
temperatures.eachWithIndex{ val, idx ->
|
|
||||||
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
|
|
||||||
full_body += "temp,sensor=${sensorName} value=${val.currentState("temperature").value} \n"
|
|
||||||
}
|
|
||||||
contacts.eachWithIndex{ val, idx ->
|
|
||||||
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
|
|
||||||
// 0=closed, 1=open
|
|
||||||
def contactState = val.currentState("contact").value == "open" ? 1 : 0
|
|
||||||
full_body += "contact,sensor=${sensorName} value=${contactState} \n"
|
|
||||||
}
|
|
||||||
humidity.eachWithIndex{ val, idx ->
|
|
||||||
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
|
|
||||||
full_body += "humidity,sensor=${sensorName} value=${val.currentState("humidity").value} \n"
|
|
||||||
}
|
|
||||||
motions.eachWithIndex{ val, idx ->
|
|
||||||
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
|
|
||||||
// 0=no motion, 1=motion detected
|
|
||||||
def motionState = val.currentState("motion").value == "active" ? 1 : 0
|
|
||||||
full_body += "motion,sensor=${sensorName} value=${motionState} \n"
|
|
||||||
}
|
|
||||||
presence.eachWithIndex{ val, idx ->
|
|
||||||
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
|
|
||||||
// 0=no presence, 1=present
|
|
||||||
def presenceState = val.currentState("presence").value == "present" ? 1 : 0
|
|
||||||
full_body += "presence,sensor=${sensorName} value=${presenceState} \n"
|
|
||||||
}
|
|
||||||
switches.eachWithIndex{ val, idx ->
|
|
||||||
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
|
|
||||||
// 0=off, 1=on
|
|
||||||
def switchState = val.currentState("switch").value == "on" ? 1 : 0
|
|
||||||
full_body += "switch,sensor=${sensorName} value=${switchState} \n"
|
|
||||||
}
|
|
||||||
energy.eachWithIndex{ val, idx ->
|
|
||||||
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
|
|
||||||
full_body += "energy,sensor=${sensorName} value=${val.currentState("energy").value} \n"
|
|
||||||
}
|
|
||||||
smoke.eachWithIndex{ val, idx ->
|
|
||||||
def sensorName = val.displayName.replaceAll(" ",'\\\\ ')
|
|
||||||
// 0="clear" 1="detected" 2="tested"
|
|
||||||
def smokeState = val.currentState("smoke").value == "detected" ? 1 : 0
|
|
||||||
full_body += "smoke,sensor=${sensorName} value=${smokeState} \n"
|
|
||||||
}
|
|
||||||
def params = [
|
|
||||||
uri: full_url,
|
|
||||||
body: full_body
|
|
||||||
]
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Make the HTTP request using httpGet()
|
|
||||||
log.debug "Calling $params"
|
|
||||||
httpPost(params) { resp -> // This is how we define the "return data". Can also use $it.
|
|
||||||
log.debug "response data: ${resp.data}"
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
log.error "something went wrong: $e"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user