From 3b9183447106b4dc5301d099648328d37fca13ad Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Wed, 29 Sep 2021 00:00:22 -0400 Subject: [PATCH 01/15] Add files via upload --- .../VirtualOmniBatterySensor_Driver.groovy | 212 ++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 examples/drivers/VirtualOmniBatterySensor_Driver.groovy diff --git a/examples/drivers/VirtualOmniBatterySensor_Driver.groovy b/examples/drivers/VirtualOmniBatterySensor_Driver.groovy new file mode 100644 index 0000000..928ded1 --- /dev/null +++ b/examples/drivers/VirtualOmniBatterySensor_Driver.groovy @@ -0,0 +1,212 @@ +// Copyright 2016-2019 Hubitat Inc. All Rights Reserved + +metadata { + definition (name: "Virtual OmniBattery Sensor", namespace: "hubitat", author: "Terrel") { + capability "Presence Sensor" + capability "Acceleration Sensor" + capability "Carbon Dioxide Measurement" + capability "Carbon Monoxide Detector" + capability "Contact Sensor" + capability "Illuminance Measurement" + capability "Motion Sensor" + capability "Relative Humidity Measurement" + capability "Smoke Detector" + capability "Temperature Measurement" + capability "Water Sensor" + capability "Energy Meter" + capability "Power Meter" + capability "Battery" + command "arrived" + command "departed" + command "accelerationActive" + command "accelerationInactive" + command "motionActive" + command "motionInactive" + command "open" + command "close" + command "CODetected" + command "COClear" + command "smokeDetected" + command "smokeClear" + command "setCarbonDioxide", ["Number"] + command "setIlluminance", ["Number"] + command "setRelativeHumidity", ["Number"] + command "setTemperature", ["Number"] + command "wet" + command "dry" + command "setVariable", ["String"] + command "setEnergy", ["Number"] + command "setPower", ["Number"] + command "setBattery", ["Number"] + attribute "variable", "String" + } + preferences { + input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true + input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true + } +} + +def logsOff(){ + log.warn "debug logging disabled..." + device.updateSetting("logEnable",[value:"false",type:"bool"]) +} + +def installed() { + log.warn "installed..." + arrived() + accelerationInactive() + COClear() + close() + setIlluminance(50) + setCarbonDioxide(350) + setRelativeHumidity(35) + motionInactive() + smokeClear() + setTemperature(70) + dry() + runIn(1800,logsOff) +} + +def updated() { + log.info "updated..." + log.warn "debug logging is: ${logEnable == true}" + log.warn "description logging is: ${txtEnable == true}" + if (logEnable) runIn(1800,logsOff) +} + +def parse(String description) { +} + +def arrived() { + def descriptionText = "${device.displayName} has arrived" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "presence", value: "present",descriptionText: descriptionText) +} + +def departed() { + def descriptionText = "${device.displayName} has departed" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "presence", value: "not present",descriptionText: descriptionText) +} + +def accelerationActive() { + def descriptionText = "${device.displayName} is active" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "acceleration", value: "active", descriptionText: descriptionText) +} + +def accelerationInactive() { + def descriptionText = "${device.displayName} is inactive" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "acceleration", value: "inactive", descriptionText: descriptionText) +} + +def CODetected() { + def descriptionText = "${device.displayName} CO detected" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "carbonMonoxide", value: "detected", descriptionText: descriptionText) +} + +def COClear() { + def descriptionText = "${device.displayName} CO clear" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "carbonMonoxide", value: "clear", descriptionText: descriptionText) +} + +def open() { + def descriptionText = "${device.displayName} is open" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "contact", value: "open", descriptionText: descriptionText) +} + +def close() { + def descriptionText = "${device.displayName} is closed" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "contact", value: "closed", descriptionText: descriptionText) +} + +def setIlluminance(lux) { + def descriptionText = "${device.displayName} is ${lux} lux" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "illuminance", value: lux, descriptionText: descriptionText, unit: "Lux") +} + +def setCarbonDioxide(CO2) { + def descriptionText = "${device.displayName} Carbon Dioxide is ${CO2} ppm" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "carbonDioxide", value: CO2, descriptionText: descriptionText, unit: "ppm") +} + +def setRelativeHumidity(humid) { + def descriptionText = "${device.displayName} is ${humid}% humidity" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "humidity", value: humid, descriptionText: descriptionText, unit: "RH%") +} + +def smokeDetected() { + def descriptionText = "${device.displayName} smoke detected" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "smoke", value: "detected", descriptionText: descriptionText) +} + +def motionActive() { + def descriptionText = "${device.displayName} is active" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "active", descriptionText: descriptionText) +} + +def motionInactive() { + def descriptionText = "${device.displayName} is inactive" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "inactive", descriptionText: descriptionText) +} + +def smokeClear() { + def descriptionText = "${device.displayName} smoke clear" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "smoke", value: "clear", descriptionText: descriptionText) +} + +def setTemperature(temp) { + def unit = "°${location.temperatureScale}" + def descriptionText = "${device.displayName} is ${temp}${unit}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "temperature", value: temp, descriptionText: descriptionText, unit: unit) +} + +def wet() { + def descriptionText = "${device.displayName} water wet" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "water", value: "wet", descriptionText: descriptionText) +} + +def dry() { + def descriptionText = "${device.displayName} water dry" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "water", value: "dry", descriptionText: descriptionText) +} + +def setVariable(str) { + def descriptionText = "${device.displayName} variable is ${str}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "variable", value: str, descriptionText: descriptionText) +} + +def setEnergy(energy) { + def descriptionText = "${device.displayName} is ${energy} energy" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "energy", value: energy, descriptionText: descriptionText) +} + +def setPower(power) { + def descriptionText = "${device.displayName} is ${power} power" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "power", value: power, descriptionText: descriptionText) +} + +def setBattery(level) { + def unit = "%" + def descriptionText = "${device.displayName} battery level is ${level}%" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "battery", value: level, descriptionText: descriptionText, unit: unit) +} \ No newline at end of file From 87bd9cccaa2db4e22ee1d53a54873b0af1cc6e16 Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Wed, 29 Sep 2021 23:09:17 -0400 Subject: [PATCH 02/15] Add battery capability Add battery capability and setBattery(level) to omni device driver --- examples/drivers/virtualOmniSensor.groovy | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/drivers/virtualOmniSensor.groovy b/examples/drivers/virtualOmniSensor.groovy index 2bc2f65..b5efc2c 100644 --- a/examples/drivers/virtualOmniSensor.groovy +++ b/examples/drivers/virtualOmniSensor.groovy @@ -2,7 +2,7 @@ metadata { definition (name: "Virtual Omni Sensor", namespace: "hubitat", author: "Bruce Ravenel") { - capability "Presence Sensor" + capability "Presence Sensor" capability "Acceleration Sensor" capability "Carbon Dioxide Measurement" capability "Carbon Monoxide Detector" @@ -15,6 +15,7 @@ metadata { capability "Water Sensor" capability "Energy Meter" capability "Power Meter" + capability "Battery" command "arrived" command "departed" command "accelerationActive" @@ -36,6 +37,7 @@ metadata { command "setVariable", ["String"] command "setEnergy", ["Number"] command "setPower", ["Number"] + command "setBattery", ["Number"] attribute "variable", "String" } preferences { @@ -201,3 +203,10 @@ def setPower(power) { if (txtEnable) log.info "${descriptionText}" sendEvent(name: "power", value: power, descriptionText: descriptionText) } + +def setBattery(level) { + def unit = "%" + def descriptionText = "${device.displayName} battery level is ${level}%" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "battery", value: level, descriptionText: descriptionText, unit: unit) +} From 7b0916f85057445b70a53dfa91ed0d4821563680 Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Wed, 29 Sep 2021 23:10:22 -0400 Subject: [PATCH 03/15] Delete VirtualOmniBatterySensor_Driver.groovy --- .../VirtualOmniBatterySensor_Driver.groovy | 212 ------------------ 1 file changed, 212 deletions(-) delete mode 100644 examples/drivers/VirtualOmniBatterySensor_Driver.groovy diff --git a/examples/drivers/VirtualOmniBatterySensor_Driver.groovy b/examples/drivers/VirtualOmniBatterySensor_Driver.groovy deleted file mode 100644 index 928ded1..0000000 --- a/examples/drivers/VirtualOmniBatterySensor_Driver.groovy +++ /dev/null @@ -1,212 +0,0 @@ -// Copyright 2016-2019 Hubitat Inc. All Rights Reserved - -metadata { - definition (name: "Virtual OmniBattery Sensor", namespace: "hubitat", author: "Terrel") { - capability "Presence Sensor" - capability "Acceleration Sensor" - capability "Carbon Dioxide Measurement" - capability "Carbon Monoxide Detector" - capability "Contact Sensor" - capability "Illuminance Measurement" - capability "Motion Sensor" - capability "Relative Humidity Measurement" - capability "Smoke Detector" - capability "Temperature Measurement" - capability "Water Sensor" - capability "Energy Meter" - capability "Power Meter" - capability "Battery" - command "arrived" - command "departed" - command "accelerationActive" - command "accelerationInactive" - command "motionActive" - command "motionInactive" - command "open" - command "close" - command "CODetected" - command "COClear" - command "smokeDetected" - command "smokeClear" - command "setCarbonDioxide", ["Number"] - command "setIlluminance", ["Number"] - command "setRelativeHumidity", ["Number"] - command "setTemperature", ["Number"] - command "wet" - command "dry" - command "setVariable", ["String"] - command "setEnergy", ["Number"] - command "setPower", ["Number"] - command "setBattery", ["Number"] - attribute "variable", "String" - } - preferences { - input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true - input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true - } -} - -def logsOff(){ - log.warn "debug logging disabled..." - device.updateSetting("logEnable",[value:"false",type:"bool"]) -} - -def installed() { - log.warn "installed..." - arrived() - accelerationInactive() - COClear() - close() - setIlluminance(50) - setCarbonDioxide(350) - setRelativeHumidity(35) - motionInactive() - smokeClear() - setTemperature(70) - dry() - runIn(1800,logsOff) -} - -def updated() { - log.info "updated..." - log.warn "debug logging is: ${logEnable == true}" - log.warn "description logging is: ${txtEnable == true}" - if (logEnable) runIn(1800,logsOff) -} - -def parse(String description) { -} - -def arrived() { - def descriptionText = "${device.displayName} has arrived" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "presence", value: "present",descriptionText: descriptionText) -} - -def departed() { - def descriptionText = "${device.displayName} has departed" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "presence", value: "not present",descriptionText: descriptionText) -} - -def accelerationActive() { - def descriptionText = "${device.displayName} is active" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "acceleration", value: "active", descriptionText: descriptionText) -} - -def accelerationInactive() { - def descriptionText = "${device.displayName} is inactive" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "acceleration", value: "inactive", descriptionText: descriptionText) -} - -def CODetected() { - def descriptionText = "${device.displayName} CO detected" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "carbonMonoxide", value: "detected", descriptionText: descriptionText) -} - -def COClear() { - def descriptionText = "${device.displayName} CO clear" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "carbonMonoxide", value: "clear", descriptionText: descriptionText) -} - -def open() { - def descriptionText = "${device.displayName} is open" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "contact", value: "open", descriptionText: descriptionText) -} - -def close() { - def descriptionText = "${device.displayName} is closed" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "contact", value: "closed", descriptionText: descriptionText) -} - -def setIlluminance(lux) { - def descriptionText = "${device.displayName} is ${lux} lux" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "illuminance", value: lux, descriptionText: descriptionText, unit: "Lux") -} - -def setCarbonDioxide(CO2) { - def descriptionText = "${device.displayName} Carbon Dioxide is ${CO2} ppm" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "carbonDioxide", value: CO2, descriptionText: descriptionText, unit: "ppm") -} - -def setRelativeHumidity(humid) { - def descriptionText = "${device.displayName} is ${humid}% humidity" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "humidity", value: humid, descriptionText: descriptionText, unit: "RH%") -} - -def smokeDetected() { - def descriptionText = "${device.displayName} smoke detected" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "smoke", value: "detected", descriptionText: descriptionText) -} - -def motionActive() { - def descriptionText = "${device.displayName} is active" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "motion", value: "active", descriptionText: descriptionText) -} - -def motionInactive() { - def descriptionText = "${device.displayName} is inactive" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "motion", value: "inactive", descriptionText: descriptionText) -} - -def smokeClear() { - def descriptionText = "${device.displayName} smoke clear" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "smoke", value: "clear", descriptionText: descriptionText) -} - -def setTemperature(temp) { - def unit = "°${location.temperatureScale}" - def descriptionText = "${device.displayName} is ${temp}${unit}" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "temperature", value: temp, descriptionText: descriptionText, unit: unit) -} - -def wet() { - def descriptionText = "${device.displayName} water wet" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "water", value: "wet", descriptionText: descriptionText) -} - -def dry() { - def descriptionText = "${device.displayName} water dry" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "water", value: "dry", descriptionText: descriptionText) -} - -def setVariable(str) { - def descriptionText = "${device.displayName} variable is ${str}" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "variable", value: str, descriptionText: descriptionText) -} - -def setEnergy(energy) { - def descriptionText = "${device.displayName} is ${energy} energy" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "energy", value: energy, descriptionText: descriptionText) -} - -def setPower(power) { - def descriptionText = "${device.displayName} is ${power} power" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "power", value: power, descriptionText: descriptionText) -} - -def setBattery(level) { - def unit = "%" - def descriptionText = "${device.displayName} battery level is ${level}%" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "battery", value: level, descriptionText: descriptionText, unit: unit) -} \ No newline at end of file From 963eaffe094514470d9e14d3beda71a907a46977 Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Wed, 29 Sep 2021 23:11:40 -0400 Subject: [PATCH 04/15] Fix indent --- examples/drivers/virtualOmniSensor.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/drivers/virtualOmniSensor.groovy b/examples/drivers/virtualOmniSensor.groovy index b5efc2c..e721c6b 100644 --- a/examples/drivers/virtualOmniSensor.groovy +++ b/examples/drivers/virtualOmniSensor.groovy @@ -2,7 +2,7 @@ metadata { definition (name: "Virtual Omni Sensor", namespace: "hubitat", author: "Bruce Ravenel") { - capability "Presence Sensor" + capability "Presence Sensor" capability "Acceleration Sensor" capability "Carbon Dioxide Measurement" capability "Carbon Monoxide Detector" From 2d7ff0b2bf3532c1260805bf9d2c9af3f47de695 Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Thu, 30 Sep 2021 21:47:10 -0400 Subject: [PATCH 05/15] Added Tamper Alerts Added tamper alerts --- examples/drivers/virtualOmniSensor.groovy | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/drivers/virtualOmniSensor.groovy b/examples/drivers/virtualOmniSensor.groovy index e721c6b..b039560 100644 --- a/examples/drivers/virtualOmniSensor.groovy +++ b/examples/drivers/virtualOmniSensor.groovy @@ -1,7 +1,7 @@ // Copyright 2016-2019 Hubitat Inc. All Rights Reserved metadata { - definition (name: "Virtual Omni Sensor", namespace: "hubitat", author: "Bruce Ravenel") { + definition (name: "Virtual Omni Sensor With Battery", namespace: "hubitat", author: "Terrel") { capability "Presence Sensor" capability "Acceleration Sensor" capability "Carbon Dioxide Measurement" @@ -16,6 +16,7 @@ metadata { capability "Energy Meter" capability "Power Meter" capability "Battery" + capability "Tamper Alert" command "arrived" command "departed" command "accelerationActive" @@ -38,6 +39,8 @@ metadata { command "setEnergy", ["Number"] command "setPower", ["Number"] command "setBattery", ["Number"] + command "tamperClear" + command "tamperDetected" attribute "variable", "String" } preferences { @@ -64,6 +67,7 @@ def installed() { smokeClear() setTemperature(70) dry() + tamperClear() runIn(1800,logsOff) } @@ -205,8 +209,18 @@ def setPower(power) { } def setBattery(level) { - def unit = "%" def descriptionText = "${device.displayName} battery level is ${level}%" if (txtEnable) log.info "${descriptionText}" sendEvent(name: "battery", value: level, descriptionText: descriptionText, unit: unit) } +def tamperClear() { + def descriptionText = "${device.displayName} is clear" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "clear", descriptionText: descriptionText) +} + +def tamperDetected() { + def descriptionText = "${device.displayName} is detected" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "detected", descriptionText: descriptionText) +} From c2947d3f723b53d89bdc1e7eafda59ba805aebeb Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Fri, 1 Oct 2021 22:35:53 -0400 Subject: [PATCH 06/15] Add files via upload --- examples/drivers/virtualOmniSensorPlus.groovy | 353 ++++++++++++++++++ 1 file changed, 353 insertions(+) create mode 100644 examples/drivers/virtualOmniSensorPlus.groovy diff --git a/examples/drivers/virtualOmniSensorPlus.groovy b/examples/drivers/virtualOmniSensorPlus.groovy new file mode 100644 index 0000000..476e2b4 --- /dev/null +++ b/examples/drivers/virtualOmniSensorPlus.groovy @@ -0,0 +1,353 @@ +/************* +* Virtual Omni Sensor Plus +* Copyright 2021 Terrel Allen All Rights Reserved +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as published +* by the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +* WARNING!!! +* Use at your own risk. +* Modify at your own risk. +* +* USAGE +* Repalces existing Virtual Omni Sensor driver +* Adds additonal capabilities, commands, and attributes not available +* in the default Virtual Omni Sensor driver +* +* CHANGE LOG +* v20211001 +* -add header +* -add battery status +* -add battery last updated +* v20210930 +* -initial release w/ battery level and tamper +* +*************/ + +metadata { + definition (name: "Virtual Omni Sensor Plus", + namespace: "whodunitGorilla", + author: "Terrel Allen", + importUrl: "https://raw.githubusercontent.com/terrelsa13/HubitatPublic/master/examples/drivers/virtualOmniSensorPlus.groovy") + { + capability "Presence Sensor" + capability "Acceleration Sensor" + capability "Carbon Dioxide Measurement" + capability "Carbon Monoxide Detector" + capability "Contact Sensor" + capability "Illuminance Measurement" + capability "Motion Sensor" + capability "Relative Humidity Measurement" + capability "Smoke Detector" + capability "Temperature Measurement" + capability "Water Sensor" + capability "Energy Meter" + capability "Power Meter" + capability "Battery" + capability "Tamper Alert" + command "arrived" + command "departed" + command "accelerationActive" + command "accelerationInactive" + command "motionActive" + command "motionInactive" + command "open" + command "close" + command "CODetected" + command "COClear" + command "smokeDetected" + command "smokeClear" + command "setCarbonDioxide", ["Number"] + command "setIlluminance", ["Number"] + command "setRelativeHumidity", ["Number"] + command "setTemperature", ["Number"] + command "wet" + command "dry" + command "setVariable", ["String"] + command "setEnergy", ["Number"] + command "setPower", ["Number"] + command "setBattery", ["Number"] + command "batteryStatusIdle" + command "batteryStatusDischarging" + command "batteryStatusCharging" + command "tamperClear" + command "tamperDetected" + attribute "variable", "String" + attribute "batteryLevel", "Number" + attribute "batteryStatus", "String" + attribute "batteryLastUpdated", "Date" + } + preferences { + input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true + input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true + } +} + +def logsOff(){ + log.warn "debug logging disabled..." + device.updateSetting("logEnable",[value:"false",type:"bool"]) +} + +def installed() { + log.warn "installed..." + initialized() + arrived() + accelerationInactive() + COClear() + close() + setIlluminance(50) + setCarbonDioxide(350) + setRelativeHumidity(35) + motionInactive() + smokeClear() + setTemperature(70) + dry() + setBatteryStatus("unknown") + tamperClear() + runIn(1800,logsOff) +} + +void initialized() { + //Clear warning count for out of range battery level + state.warningCount = 0 +} + +def updated() { + log.info "updated..." + log.warn "debug logging is: ${logEnable == true}" + log.warn "description logging is: ${txtEnable == true}" + if (logEnable) runIn(1800,logsOff) +} + +def parse(String description) { +} + +def arrived() { + def descriptionText = "${device.displayName} has arrived" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "presence", value: "present",descriptionText: descriptionText) +} + +def departed() { + def descriptionText = "${device.displayName} has departed" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "presence", value: "not present",descriptionText: descriptionText) +} + +def accelerationActive() { + def descriptionText = "${device.displayName} acceleration is active" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "acceleration", value: "active", descriptionText: descriptionText) +} + +def accelerationInactive() { + def descriptionText = "${device.displayName} acceleration is inactive" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "acceleration", value: "inactive", descriptionText: descriptionText) +} + +def CODetected() { + def descriptionText = "${device.displayName} CO detected" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "carbonMonoxide", value: "detected", descriptionText: descriptionText) +} + +def COClear() { + def descriptionText = "${device.displayName} CO clear" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "carbonMonoxide", value: "clear", descriptionText: descriptionText) +} + +def open() { + def descriptionText = "${device.displayName} is open" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "contact", value: "open", descriptionText: descriptionText) +} + +def close() { + def descriptionText = "${device.displayName} is closed" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "contact", value: "closed", descriptionText: descriptionText) +} + +def setIlluminance(lux) { + def descriptionText = "${device.displayName} is ${lux} lux" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "illuminance", value: lux, descriptionText: descriptionText, unit: "Lux") +} + +def setCarbonDioxide(CO2) { + def descriptionText = "${device.displayName} Carbon Dioxide is ${CO2} ppm" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "carbonDioxide", value: CO2, descriptionText: descriptionText, unit: "ppm") +} + +def setRelativeHumidity(humid) { + def descriptionText = "${device.displayName} is ${humid}% humidity" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "humidity", value: humid, descriptionText: descriptionText, unit: "RH%") +} + +def smokeDetected() { + def descriptionText = "${device.displayName} smoke detected" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "smoke", value: "detected", descriptionText: descriptionText) +} + +def motionActive() { + def descriptionText = "${device.displayName} is active" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "active", descriptionText: descriptionText) +} + +def motionInactive() { + def descriptionText = "${device.displayName} is inactive" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "inactive", descriptionText: descriptionText) +} + +def smokeClear() { + def descriptionText = "${device.displayName} smoke clear" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "smoke", value: "clear", descriptionText: descriptionText) +} + +def setTemperature(temp) { + def unit = "°${location.temperatureScale}" + def descriptionText = "${device.displayName} is ${temp}${unit}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "temperature", value: temp, descriptionText: descriptionText, unit: unit) +} + +def wet() { + def descriptionText = "${device.displayName} water wet" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "water", value: "wet", descriptionText: descriptionText) +} + +def dry() { + def descriptionText = "${device.displayName} water dry" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "water", value: "dry", descriptionText: descriptionText) +} + +def setVariable(str) { + def descriptionText = "${device.displayName} variable is ${str}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "variable", value: str, descriptionText: descriptionText) +} + +def setEnergy(energy) { + def descriptionText = "${device.displayName} is ${energy} energy" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "energy", value: energy, descriptionText: descriptionText) +} + +def setPower(power) { + def descriptionText = "${device.displayName} is ${power} power" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "power", value: power, descriptionText: descriptionText) +} + +String getBatteryStatus() { + //return battery status + return device.currentValue("batteryStatus") +} + +def setBatteryStatus(status) { + def descriptionText = "${device.displayName} battery status is: ${status}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "batteryStatus", value: status, descriptionText: descriptionText) +} + +def batteryStatusIdle() { + setBatteryStatus("idle") +} + +def batteryStatusDischarging() { + setBatteryStatus("discharging") +} + +def batteryStatusCharging() { + setBatteryStatus("charging") +} + +Number getBattery() { + //return battery level + return device.currentValue('batteryLevel') +} + +def setBattery(level) { + //Check battery level is 0 - 100 + if(level >= 0 && level <= 100) { + //Get current date and time + Date lastUpdate = new Date() + //Get previous battery level + Number prevBatteryLevel = getBattery() + //No battery level set + if (prevBatteryLevel == null) { + setBatteryStatus("unknown") + } + //No change in battery level + else if (prevBatteryLevel == level) { + setBatteryStatus("idle") + } + //Battery level decreasing + else if (prevBatteryLevel > level) { + setBatteryStatus("discharging") + } + //Battery level increasing + else /*(prevBatteryLevel < level)*/ { + setBatteryStatus("charging") + } + //Set unit + unit = "%" + def descriptionTextLevel = "${device.displayName} battery level is ${level}${unit}" + def descriptionTextLastUpdate = "${device.displayName} battery information last updated ${lastUpdate}" + if (txtEnable) log.info "${descriptionTextLevel}" + if (txtEnable) log.info "${descriptionTextLastUpdate}" + //Update attributes + sendEvent(name: "batteryLevel", value: level, descriptionText: descriptionTextLevel, unit: unit) + sendEvent(name: "batteryLastUpdated", value : lastUpdate.format("yyyy/MM/dd HH:mm:ss"), descriptionText: descriptionTextLastUpdate) + //Reset warning count if there have been previous warnings + if (state.warningCount > 0) { + state.warningCount = 0 + log.info("setBattery(): Warning count reset") + } + } + // If the battery reading is outside the 0 - 100 range, log a warning and leave the current reading in place + // use the warning count state variable to make sure we don't spam the logs with repeated warnings + else { + if (state.warningCount < 10) { + state.warningCount++ + if (getBattery() == null) { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining ${prevBatteryLevel} battery level") + } + else { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining prevoius battery level ${prevBatteryLevel}%") + } + } + } +} + +def tamperClear() { + def descriptionText = "${device.displayName} tamper is clear" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "clear", descriptionText: descriptionText) +} + +def tamperDetected() { + def descriptionText = "${device.displayName} tamper is detected" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "detected", descriptionText: descriptionText) +} \ No newline at end of file From b7882601e1821fbb6332bf98349e0f974ac4c9ea Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Fri, 1 Oct 2021 22:38:29 -0400 Subject: [PATCH 07/15] Back to original. New driver based off of this one named Virtual Omni Sensor Plus --- examples/drivers/virtualOmniSensor.groovy | 25 +---------------------- 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/examples/drivers/virtualOmniSensor.groovy b/examples/drivers/virtualOmniSensor.groovy index b039560..2bc2f65 100644 --- a/examples/drivers/virtualOmniSensor.groovy +++ b/examples/drivers/virtualOmniSensor.groovy @@ -1,7 +1,7 @@ // Copyright 2016-2019 Hubitat Inc. All Rights Reserved metadata { - definition (name: "Virtual Omni Sensor With Battery", namespace: "hubitat", author: "Terrel") { + definition (name: "Virtual Omni Sensor", namespace: "hubitat", author: "Bruce Ravenel") { capability "Presence Sensor" capability "Acceleration Sensor" capability "Carbon Dioxide Measurement" @@ -15,8 +15,6 @@ metadata { capability "Water Sensor" capability "Energy Meter" capability "Power Meter" - capability "Battery" - capability "Tamper Alert" command "arrived" command "departed" command "accelerationActive" @@ -38,9 +36,6 @@ metadata { command "setVariable", ["String"] command "setEnergy", ["Number"] command "setPower", ["Number"] - command "setBattery", ["Number"] - command "tamperClear" - command "tamperDetected" attribute "variable", "String" } preferences { @@ -67,7 +62,6 @@ def installed() { smokeClear() setTemperature(70) dry() - tamperClear() runIn(1800,logsOff) } @@ -207,20 +201,3 @@ def setPower(power) { if (txtEnable) log.info "${descriptionText}" sendEvent(name: "power", value: power, descriptionText: descriptionText) } - -def setBattery(level) { - def descriptionText = "${device.displayName} battery level is ${level}%" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "battery", value: level, descriptionText: descriptionText, unit: unit) -} -def tamperClear() { - def descriptionText = "${device.displayName} is clear" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "tamper", value: "clear", descriptionText: descriptionText) -} - -def tamperDetected() { - def descriptionText = "${device.displayName} is detected" - if (txtEnable) log.info "${descriptionText}" - sendEvent(name: "tamper", value: "detected", descriptionText: descriptionText) -} From e55bc15048ee2f2ed72dfe54b1b537cf5ae73e22 Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Sat, 2 Oct 2021 17:27:26 -0400 Subject: [PATCH 08/15] Update virtualOmniSensorPlus.groovy --- examples/drivers/virtualOmniSensorPlus.groovy | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/drivers/virtualOmniSensorPlus.groovy b/examples/drivers/virtualOmniSensorPlus.groovy index 476e2b4..782b93a 100644 --- a/examples/drivers/virtualOmniSensorPlus.groovy +++ b/examples/drivers/virtualOmniSensorPlus.groovy @@ -25,6 +25,8 @@ * in the default Virtual Omni Sensor driver * * CHANGE LOG +* v20211002 +* -change batteryLevel attribute back to battery * v20211001 * -add header * -add battery status @@ -83,7 +85,6 @@ metadata { command "tamperClear" command "tamperDetected" attribute "variable", "String" - attribute "batteryLevel", "Number" attribute "batteryStatus", "String" attribute "batteryLastUpdated", "Date" } @@ -284,10 +285,12 @@ def batteryStatusCharging() { Number getBattery() { //return battery level - return device.currentValue('batteryLevel') + return device.currentValue('battery') } +//Command to set the battery level def setBattery(level) { +//def battery(level) { //Check battery level is 0 - 100 if(level >= 0 && level <= 100) { //Get current date and time @@ -317,7 +320,7 @@ def setBattery(level) { if (txtEnable) log.info "${descriptionTextLevel}" if (txtEnable) log.info "${descriptionTextLastUpdate}" //Update attributes - sendEvent(name: "batteryLevel", value: level, descriptionText: descriptionTextLevel, unit: unit) + sendEvent(name: "battery", value: level, descriptionText: descriptionTextLevel, unit: unit) sendEvent(name: "batteryLastUpdated", value : lastUpdate.format("yyyy/MM/dd HH:mm:ss"), descriptionText: descriptionTextLastUpdate) //Reset warning count if there have been previous warnings if (state.warningCount > 0) { @@ -340,6 +343,11 @@ def setBattery(level) { } } +//The other command to set battery level +def battery(level) { + setBattery(level) +} + def tamperClear() { def descriptionText = "${device.displayName} tamper is clear" if (txtEnable) log.info "${descriptionText}" @@ -350,4 +358,4 @@ def tamperDetected() { def descriptionText = "${device.displayName} tamper is detected" if (txtEnable) log.info "${descriptionText}" sendEvent(name: "tamper", value: "detected", descriptionText: descriptionText) -} \ No newline at end of file +} From aee8cdca9ed207230885e64344eaaba3ae014039 Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Sat, 2 Oct 2021 23:19:06 -0400 Subject: [PATCH 09/15] Update virtualOmniSensorPlus.groovy --- examples/drivers/virtualOmniSensorPlus.groovy | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/drivers/virtualOmniSensorPlus.groovy b/examples/drivers/virtualOmniSensorPlus.groovy index 782b93a..719b62b 100644 --- a/examples/drivers/virtualOmniSensorPlus.groovy +++ b/examples/drivers/virtualOmniSensorPlus.groovy @@ -25,9 +25,12 @@ * in the default Virtual Omni Sensor driver * * CHANGE LOG -* v20211002 +* v202110022249 +* -updates to event descriptive text for humidity +* -add hours and minutes to change log dates +* v202110020000 * -change batteryLevel attribute back to battery -* v20211001 +* v202110010000 * -add header * -add battery status * -add battery last updated @@ -194,7 +197,7 @@ def setCarbonDioxide(CO2) { } def setRelativeHumidity(humid) { - def descriptionText = "${device.displayName} is ${humid}% humidity" + def descriptionText = "${device.displayName} humidity is ${humid}%" if (txtEnable) log.info "${descriptionText}" sendEvent(name: "humidity", value: humid, descriptionText: descriptionText, unit: "RH%") } @@ -225,7 +228,7 @@ def smokeClear() { def setTemperature(temp) { def unit = "°${location.temperatureScale}" - def descriptionText = "${device.displayName} is ${temp}${unit}" + def descriptionText = "${device.displayName} temperature is ${temp}${unit}" if (txtEnable) log.info "${descriptionText}" sendEvent(name: "temperature", value: temp, descriptionText: descriptionText, unit: unit) } @@ -266,7 +269,7 @@ String getBatteryStatus() { } def setBatteryStatus(status) { - def descriptionText = "${device.displayName} battery status is: ${status}" + def descriptionText = "${device.displayName} battery status is ${status}" if (txtEnable) log.info "${descriptionText}" sendEvent(name: "batteryStatus", value: status, descriptionText: descriptionText) } From 4c5c64a093633c93778be9fee43609aec0f66b35 Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Sun, 3 Oct 2021 15:09:50 -0400 Subject: [PATCH 10/15] Update virtualOmniSensorPlus.groovy --- examples/drivers/virtualOmniSensorPlus.groovy | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/drivers/virtualOmniSensorPlus.groovy b/examples/drivers/virtualOmniSensorPlus.groovy index 719b62b..098dcac 100644 --- a/examples/drivers/virtualOmniSensorPlus.groovy +++ b/examples/drivers/virtualOmniSensorPlus.groovy @@ -25,6 +25,8 @@ * in the default Virtual Omni Sensor driver * * CHANGE LOG +* v202110031411 +* -add threeAxis * v202110022249 * -updates to event descriptive text for humidity * -add hours and minutes to change log dates @@ -60,6 +62,7 @@ metadata { capability "Power Meter" capability "Battery" capability "Tamper Alert" + capability "Three Axis" command "arrived" command "departed" command "accelerationActive" @@ -87,6 +90,7 @@ metadata { command "batteryStatusCharging" command "tamperClear" command "tamperDetected" + command "threeAxis", [[name:"x",type:"NUMBER", description:"X-Axis", constraints:["NUMBER"]],[name:"y",type:"NUMBER", description:"Y-Axis", constraints:["NUMBER"]],[name:"z",type:"NUMBER", description:"Z-Axis", constraints:["NUMBER"]]] attribute "variable", "String" attribute "batteryStatus", "String" attribute "batteryLastUpdated", "Date" @@ -362,3 +366,13 @@ def tamperDetected() { if (txtEnable) log.info "${descriptionText}" sendEvent(name: "tamper", value: "detected", descriptionText: descriptionText) } + +def threeAxis(x,y,z) { + def xyz = "x:${x},y:${y},z:${z}" + def descriptionText = "${device.displayName} threeAxis is ${xyz}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "threeAxis", value: xyz, descriptionText: descriptionText) + sendEvent(name: "xAxis", value: x) + sendEvent(name: "yAxis", value: y) + sendEvent(name: "zAxis", value: z) +} From 3869e55a658bde319f0b4f15b71e0fff790a2bcc Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Tue, 5 Oct 2021 21:20:21 -0400 Subject: [PATCH 11/15] Add files via upload --- examples/drivers/virtualAeotecAerQ.groovy | 192 ++++++++++++ examples/drivers/virtualDomeDMDP1DMDP2.groovy | 217 ++++++++++++++ examples/drivers/virtualEcoLinkDW.groovy | 206 +++++++++++++ examples/drivers/virtualFibaroZW5.groovy | 279 ++++++++++++++++++ examples/drivers/virtualOmniSensorPlus.groovy | 24 ++ examples/drivers/virtualZoozZSE11ZSE40.groovy | 233 +++++++++++++++ examples/drivers/virtualZoozZSE29.groovy | 213 +++++++++++++ 7 files changed, 1364 insertions(+) create mode 100644 examples/drivers/virtualAeotecAerQ.groovy create mode 100644 examples/drivers/virtualDomeDMDP1DMDP2.groovy create mode 100644 examples/drivers/virtualEcoLinkDW.groovy create mode 100644 examples/drivers/virtualFibaroZW5.groovy create mode 100644 examples/drivers/virtualZoozZSE11ZSE40.groovy create mode 100644 examples/drivers/virtualZoozZSE29.groovy diff --git a/examples/drivers/virtualAeotecAerQ.groovy b/examples/drivers/virtualAeotecAerQ.groovy new file mode 100644 index 0000000..e3a2ff0 --- /dev/null +++ b/examples/drivers/virtualAeotecAerQ.groovy @@ -0,0 +1,192 @@ +/************* +* Virtual Aeotec AerQ +* Copyright 2021 Terrel Allen All Rights Reserved +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as published +* by the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +* WARNING!!! +* Use at your own risk. +* Modify at your own risk. +* +* USAGE +* Repalces existing Virtual Omni Sensor driver +* Adds additonal capabilities, commands, and attributes not available +* in the default Virtual Omni Sensor driver +* +* CHANGE LOG +* v202110031918 +* -initial release +* +*************/ + +metadata { + definition (name: "Virtual Aeotec AerQ", + namespace: "whodunitGorilla", + author: "Terrel Allen", + importUrl: "https://raw.githubusercontent.com/terrelsa13/HubitatPublic/master/examples/drivers/virtualOmniSensorPlus.groovy") + { + capability "Relative Humidity Measurement" + capability "Temperature Measurement" + capability "Battery" + command "setRelativeHumidity", ["Number"] + command "setTemperature", ["Number"] + command "setBattery", ["Number"] + command "batteryStatusIdle" + command "batteryStatusDischarging" + command "batteryStatusCharging" + attribute "variable", "String" + attribute "batteryStatus", "String" + attribute "batteryLastUpdated", "Date" + } + preferences { + input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true + input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true + } +} + +def logsOff(){ + log.warn "debug logging disabled..." + device.updateSetting("logEnable",[value:"false",type:"bool"]) +} + +def installed() { + log.warn "installed..." + initialized() + setRelativeHumidity(35) + setTemperature(70) + setBatteryStatus("unknown") + runIn(1800,logsOff) +} + +void initialized() { + //Clear warning count for out of range battery level + state.warningCount = 0 +} + +def updated() { + log.info "updated..." + log.warn "debug logging is: ${logEnable == true}" + log.warn "description logging is: ${txtEnable == true}" + if (logEnable) runIn(1800,logsOff) +} + +def parse(String description) { +} + +def setRelativeHumidity(humid) { + def descriptionText = "${device.displayName} humidity is ${humid}%" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "humidity", value: humid, descriptionText: descriptionText, unit: "RH%") +} + +def setTemperature(temp) { + def unit = "°${location.temperatureScale}" + def descriptionText = "${device.displayName} temperature is ${temp}${unit}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "temperature", value: temp, descriptionText: descriptionText, unit: unit) +} + +def setVariable(str) { + def descriptionText = "${device.displayName} variable is ${str}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "variable", value: str, descriptionText: descriptionText) +} + +String getBatteryStatus() { + //return battery status + return device.currentValue("batteryStatus") +} + +def setBatteryStatus(status) { + def descriptionText = "${device.displayName} battery status is ${status}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "batteryStatus", value: status, descriptionText: descriptionText) +} + +def batteryStatusIdle() { + setBatteryStatus("idle") +} + +def batteryStatusDischarging() { + setBatteryStatus("discharging") +} + +def batteryStatusCharging() { + setBatteryStatus("charging") +} + +Number getBattery() { + //return battery level + return device.currentValue('battery') +} + +//Command to set the battery level +def setBattery(level) { +//def battery(level) { + //Check battery level is 0 - 100 + if(level >= 0 && level <= 100) { + //Get current date and time + Date lastUpdate = new Date() + //Get previous battery level + Number prevBatteryLevel = getBattery() + //No battery level set + if (prevBatteryLevel == null) { + setBatteryStatus("unknown") + } + //No change in battery level + else if (prevBatteryLevel == level) { + setBatteryStatus("idle") + } + //Battery level decreasing + else if (prevBatteryLevel > level) { + setBatteryStatus("discharging") + } + //Battery level increasing + else /*(prevBatteryLevel < level)*/ { + setBatteryStatus("charging") + } + //Set unit + unit = "%" + def descriptionTextLevel = "${device.displayName} battery level is ${level}${unit}" + def descriptionTextLastUpdate = "${device.displayName} battery information last updated ${lastUpdate}" + if (txtEnable) log.info "${descriptionTextLevel}" + if (txtEnable) log.info "${descriptionTextLastUpdate}" + //Update attributes + sendEvent(name: "battery", value: level, descriptionText: descriptionTextLevel, unit: unit) + sendEvent(name: "batteryLastUpdated", value : lastUpdate.format("yyyy/MM/dd HH:mm:ss"), descriptionText: descriptionTextLastUpdate) + //Reset warning count if there have been previous warnings + if (state.warningCount > 0) { + state.warningCount = 0 + log.info("setBattery(): Warning count reset") + } + } + // If the battery reading is outside the 0 - 100 range, log a warning and leave the current reading in place + // use the warning count state variable to make sure we don't spam the logs with repeated warnings + else { + if (state.warningCount < 10) { + state.warningCount++ + if (getBattery() == null) { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining ${prevBatteryLevel} battery level") + } + else { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining prevoius battery level ${prevBatteryLevel}%") + } + } + } +} + +//The other command to set battery level +def battery(level) { + setBattery(level) +} \ No newline at end of file diff --git a/examples/drivers/virtualDomeDMDP1DMDP2.groovy b/examples/drivers/virtualDomeDMDP1DMDP2.groovy new file mode 100644 index 0000000..507a5ac --- /dev/null +++ b/examples/drivers/virtualDomeDMDP1DMDP2.groovy @@ -0,0 +1,217 @@ +/************* +* Virtual Dome DMDP1 +* Virtual Dome DMDP2 +* Copyright 2021 Terrel Allen All Rights Reserved +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as published +* by the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +* WARNING!!! +* Use at your own risk. +* Modify at your own risk. +* +* USAGE +* Repalces existing Virtual Omni Sensor driver +* Adds additonal capabilities, commands, and attributes not available +* in the default Virtual Omni Sensor driver +* +* CHANGE LOG +* v202110031906 +* -initial release +* +*************/ + +metadata { + definition (name: "Virtual Dome DMDP1 DMDP2", + namespace: "whodunitGorilla", + author: "Terrel Allen", + importUrl: "https://raw.githubusercontent.com/terrelsa13/HubitatPublic/master/examples/drivers/virtualOmniSensorPlus.groovy") + { + capability "Contact Sensor" + capability "Temperature Measurement" + capability "Battery" + capability "Tamper Alert" + command "open" + command "close" + command "setTemperature", ["Number"] + command "setVariable", ["String"] + command "setBattery", ["Number"] + command "batteryStatusIdle" + command "batteryStatusDischarging" + command "batteryStatusCharging" + command "tamperClear" + command "tamperDetected" + attribute "variable", "String" + attribute "batteryStatus", "String" + attribute "batteryLastUpdated", "Date" + } + preferences { + input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true + input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true + } +} + +def logsOff(){ + log.warn "debug logging disabled..." + device.updateSetting("logEnable",[value:"false",type:"bool"]) +} + +def installed() { + log.warn "installed..." + initialized() + close() + setTemperature(70) + setBatteryStatus("unknown") + tamperClear() + runIn(1800,logsOff) +} + +void initialized() { + //Clear warning count for out of range battery level + state.warningCount = 0 +} + +def updated() { + log.info "updated..." + log.warn "debug logging is: ${logEnable == true}" + log.warn "description logging is: ${txtEnable == true}" + if (logEnable) runIn(1800,logsOff) +} + +def parse(String description) { +} + +def open() { + def descriptionText = "${device.displayName} is open" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "contact", value: "open", descriptionText: descriptionText) +} + +def close() { + def descriptionText = "${device.displayName} is closed" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "contact", value: "closed", descriptionText: descriptionText) +} + +def setTemperature(temp) { + def unit = "°${location.temperatureScale}" + def descriptionText = "${device.displayName} temperature is ${temp}${unit}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "temperature", value: temp, descriptionText: descriptionText, unit: unit) +} + +def setVariable(str) { + def descriptionText = "${device.displayName} variable is ${str}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "variable", value: str, descriptionText: descriptionText) +} + +String getBatteryStatus() { + //return battery status + return device.currentValue("batteryStatus") +} + +def setBatteryStatus(status) { + def descriptionText = "${device.displayName} battery status is ${status}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "batteryStatus", value: status, descriptionText: descriptionText) +} + +def batteryStatusIdle() { + setBatteryStatus("idle") +} + +def batteryStatusDischarging() { + setBatteryStatus("discharging") +} + +def batteryStatusCharging() { + setBatteryStatus("charging") +} + +Number getBattery() { + //return battery level + return device.currentValue('battery') +} + +//Command to set the battery level +def setBattery(level) { +//def battery(level) { + //Check battery level is 0 - 100 + if(level >= 0 && level <= 100) { + //Get current date and time + Date lastUpdate = new Date() + //Get previous battery level + Number prevBatteryLevel = getBattery() + //No battery level set + if (prevBatteryLevel == null) { + setBatteryStatus("unknown") + } + //No change in battery level + else if (prevBatteryLevel == level) { + setBatteryStatus("idle") + } + //Battery level decreasing + else if (prevBatteryLevel > level) { + setBatteryStatus("discharging") + } + //Battery level increasing + else /*(prevBatteryLevel < level)*/ { + setBatteryStatus("charging") + } + //Set unit + unit = "%" + def descriptionTextLevel = "${device.displayName} battery level is ${level}${unit}" + def descriptionTextLastUpdate = "${device.displayName} battery information last updated ${lastUpdate}" + if (txtEnable) log.info "${descriptionTextLevel}" + if (txtEnable) log.info "${descriptionTextLastUpdate}" + //Update attributes + sendEvent(name: "battery", value: level, descriptionText: descriptionTextLevel, unit: unit) + sendEvent(name: "batteryLastUpdated", value : lastUpdate.format("yyyy/MM/dd HH:mm:ss"), descriptionText: descriptionTextLastUpdate) + //Reset warning count if there have been previous warnings + if (state.warningCount > 0) { + state.warningCount = 0 + log.info("setBattery(): Warning count reset") + } + } + // If the battery reading is outside the 0 - 100 range, log a warning and leave the current reading in place + // use the warning count state variable to make sure we don't spam the logs with repeated warnings + else { + if (state.warningCount < 10) { + state.warningCount++ + if (getBattery() == null) { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining ${prevBatteryLevel} battery level") + } + else { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining prevoius battery level ${prevBatteryLevel}%") + } + } + } +} + +//The other command to set battery level +def battery(level) { + setBattery(level) +} + +def tamperClear() { + def descriptionText = "${device.displayName} tamper is clear" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "clear", descriptionText: descriptionText) +} + +def tamperDetected() { + def descriptionText = "${device.displayName} tamper is detected" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "detected", descriptionText: descriptionText) +} \ No newline at end of file diff --git a/examples/drivers/virtualEcoLinkDW.groovy b/examples/drivers/virtualEcoLinkDW.groovy new file mode 100644 index 0000000..554720b --- /dev/null +++ b/examples/drivers/virtualEcoLinkDW.groovy @@ -0,0 +1,206 @@ +/************* +* Virtual EcoLink DW Z-Wave 2.5 +* Copyright 2021 Terrel Allen All Rights Reserved +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as published +* by the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +* WARNING!!! +* Use at your own risk. +* Modify at your own risk. +* +* USAGE +* Repalces existing Virtual Omni Sensor driver +* Adds additonal capabilities, commands, and attributes not available +* in the default Virtual Omni Sensor driver +* +* CHANGE LOG +* v202110031906 +* -initial release +* +*************/ + +metadata { + definition (name: "Virtual EcoLink DW", + namespace: "whodunitGorilla", + author: "Terrel Allen", + importUrl: "https://raw.githubusercontent.com/terrelsa13/HubitatPublic/master/examples/drivers/virtualOmniSensorPlus.groovy") + { + capability "Contact Sensor" + capability "Battery" + capability "Tamper Alert" + command "open" + command "close" + command "setVariable", ["String"] + command "setBattery", ["Number"] + command "batteryStatusIdle" + command "batteryStatusDischarging" + command "batteryStatusCharging" + command "tamperClear" + command "tamperDetected" + attribute "variable", "String" + attribute "batteryStatus", "String" + attribute "batteryLastUpdated", "Date" + } + preferences { + input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true + input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true + } +} + +def logsOff(){ + log.warn "debug logging disabled..." + device.updateSetting("logEnable",[value:"false",type:"bool"]) +} + +def installed() { + log.warn "installed..." + initialized() + close() + setBatteryStatus("unknown") + tamperClear() + runIn(1800,logsOff) +} + +void initialized() { + //Clear warning count for out of range battery level + state.warningCount = 0 +} + +def updated() { + log.info "updated..." + log.warn "debug logging is: ${logEnable == true}" + log.warn "description logging is: ${txtEnable == true}" + if (logEnable) runIn(1800,logsOff) +} + +def parse(String description) { +} + +def open() { + def descriptionText = "${device.displayName} is open" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "contact", value: "open", descriptionText: descriptionText) +} + +def close() { + def descriptionText = "${device.displayName} is closed" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "contact", value: "closed", descriptionText: descriptionText) +} + +def setVariable(str) { + def descriptionText = "${device.displayName} variable is ${str}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "variable", value: str, descriptionText: descriptionText) +} + +String getBatteryStatus() { + //return battery status + return device.currentValue("batteryStatus") +} + +def setBatteryStatus(status) { + def descriptionText = "${device.displayName} battery status is ${status}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "batteryStatus", value: status, descriptionText: descriptionText) +} + +def batteryStatusIdle() { + setBatteryStatus("idle") +} + +def batteryStatusDischarging() { + setBatteryStatus("discharging") +} + +def batteryStatusCharging() { + setBatteryStatus("charging") +} + +Number getBattery() { + //return battery level + return device.currentValue('battery') +} + +//Command to set the battery level +def setBattery(level) { +//def battery(level) { + //Check battery level is 0 - 100 + if(level >= 0 && level <= 100) { + //Get current date and time + Date lastUpdate = new Date() + //Get previous battery level + Number prevBatteryLevel = getBattery() + //No battery level set + if (prevBatteryLevel == null) { + setBatteryStatus("unknown") + } + //No change in battery level + else if (prevBatteryLevel == level) { + setBatteryStatus("idle") + } + //Battery level decreasing + else if (prevBatteryLevel > level) { + setBatteryStatus("discharging") + } + //Battery level increasing + else /*(prevBatteryLevel < level)*/ { + setBatteryStatus("charging") + } + //Set unit + unit = "%" + def descriptionTextLevel = "${device.displayName} battery level is ${level}${unit}" + def descriptionTextLastUpdate = "${device.displayName} battery information last updated ${lastUpdate}" + if (txtEnable) log.info "${descriptionTextLevel}" + if (txtEnable) log.info "${descriptionTextLastUpdate}" + //Update attributes + sendEvent(name: "battery", value: level, descriptionText: descriptionTextLevel, unit: unit) + sendEvent(name: "batteryLastUpdated", value : lastUpdate.format("yyyy/MM/dd HH:mm:ss"), descriptionText: descriptionTextLastUpdate) + //Reset warning count if there have been previous warnings + if (state.warningCount > 0) { + state.warningCount = 0 + log.info("setBattery(): Warning count reset") + } + } + // If the battery reading is outside the 0 - 100 range, log a warning and leave the current reading in place + // use the warning count state variable to make sure we don't spam the logs with repeated warnings + else { + if (state.warningCount < 10) { + state.warningCount++ + if (getBattery() == null) { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining ${prevBatteryLevel} battery level") + } + else { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining prevoius battery level ${prevBatteryLevel}%") + } + } + } +} + +//The other command to set battery level +def battery(level) { + setBattery(level) +} + +def tamperClear() { + def descriptionText = "${device.displayName} tamper is clear" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "clear", descriptionText: descriptionText) +} + +def tamperDetected() { + def descriptionText = "${device.displayName} tamper is detected" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "detected", descriptionText: descriptionText) +} \ No newline at end of file diff --git a/examples/drivers/virtualFibaroZW5.groovy b/examples/drivers/virtualFibaroZW5.groovy new file mode 100644 index 0000000..e191117 --- /dev/null +++ b/examples/drivers/virtualFibaroZW5.groovy @@ -0,0 +1,279 @@ +/************* +* Virtual Fibaro ZW5 +* Copyright 2021 Terrel Allen All Rights Reserved +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as published +* by the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +* WARNING!!! +* Use at your own risk. +* Modify at your own risk. +* +* USAGE +* Virtual Fibaro ZW5 Driver +* +* CHANGE LOG +* v202110031511 +* -initial release +* +*************/ + +metadata { + definition (name: "Virtual Fibaro ZW5", + namespace: "whodunitGorilla", + author: "Terrel Allen", + importUrl: "https://raw.githubusercontent.com/terrelsa13/HubitatPublic/master/examples/drivers/virtualFibaroZW5.groovy") + { + capability "Acceleration Sensor" + capability "Illuminance Measurement" + capability "Motion Sensor" + capability "Temperature Measurement" + capability "Battery" + capability "Tamper Alert" + capability "Three Axis" + command "accelerationActive" + command "accelerationInactive" + command "motionActive" + command "motionInactive" + command "setIlluminance", ["Number"] + command "setTemperature", ["Number"] + command "setVariable", ["String"] + command "setBattery", ["Number"] + command "batteryStatusIdle" + command "batteryStatusDischarging" + command "batteryStatusCharging" + command "tamperClear" + command "tamperDetected" + command "threeAxis", [[name:"x",type:"NUMBER", description:"X-Axis", constraints:["NUMBER"]],[name:"y",type:"NUMBER", description:"Y-Axis", constraints:["NUMBER"]],[name:"z",type:"NUMBER", description:"Z-Axis", constraints:["NUMBER"]]] + command "setThreeAxis" + attribute "variable", "String" + attribute "batteryStatus", "String" + attribute "batteryLastUpdated", "Date" + } + preferences { + input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true + input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true + } +} + +def logsOff(){ + log.warn "debug logging disabled..." + device.updateSetting("logEnable",[value:"false",type:"bool"]) +} + +def installed() { + log.warn "installed..." + initialized() + accelerationInactive() + setIlluminance(50) + motionInactive() + setTemperature(70) + setBatteryStatus("unknown") + tamperClear() + runIn(1800,logsOff) +} + +void initialized() { + //Clear warning count for out of range battery level + state.warningCount = 0 +} + +def updated() { + log.info "updated..." + log.warn "debug logging is: ${logEnable == true}" + log.warn "description logging is: ${txtEnable == true}" + if (logEnable) runIn(1800,logsOff) +} + +def parse(String description) { +} + +def accelerationActive() { + def descriptionText = "${device.displayName} acceleration is active" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "acceleration", value: "active", descriptionText: descriptionText) +} + +def accelerationInactive() { + def descriptionText = "${device.displayName} acceleration is inactive" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "acceleration", value: "inactive", descriptionText: descriptionText) +} + +def CODetected() { + def descriptionText = "${device.displayName} CO detected" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "carbonMonoxide", value: "detected", descriptionText: descriptionText) +} + +def setIlluminance(lux) { + def descriptionText = "${device.displayName} is ${lux} lux" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "illuminance", value: lux, descriptionText: descriptionText, unit: "Lux") +} + +def motionActive() { + def descriptionText = "${device.displayName} is active" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "active", descriptionText: descriptionText) +} + +def motionInactive() { + def descriptionText = "${device.displayName} is inactive" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "inactive", descriptionText: descriptionText) +} + +def setTemperature(temp) { + def unit = "°${location.temperatureScale}" + def descriptionText = "${device.displayName} temperature is ${temp}${unit}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "temperature", value: temp, descriptionText: descriptionText, unit: unit) +} + +def setVariable(str) { + def descriptionText = "${device.displayName} variable is ${str}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "variable", value: str, descriptionText: descriptionText) +} + +String getBatteryStatus() { + //return battery status + return device.currentValue("batteryStatus") +} + +def setBatteryStatus(status) { + def descriptionText = "${device.displayName} battery status is ${status}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "batteryStatus", value: status, descriptionText: descriptionText) +} + +def batteryStatusIdle() { + setBatteryStatus("idle") +} + +def batteryStatusDischarging() { + setBatteryStatus("discharging") +} + +def batteryStatusCharging() { + setBatteryStatus("charging") +} + +Number getBattery() { + //return battery level + return device.currentValue('battery') +} + +//Command to set the battery level +def setBattery(level) { +//def battery(level) { + //Check battery level is 0 - 100 + if(level >= 0 && level <= 100) { + //Get current date and time + Date lastUpdate = new Date() + //Get previous battery level + Number prevBatteryLevel = getBattery() + //No battery level set + if (prevBatteryLevel == null) { + setBatteryStatus("unknown") + } + //No change in battery level + else if (prevBatteryLevel == level) { + setBatteryStatus("idle") + } + //Battery level decreasing + else if (prevBatteryLevel > level) { + setBatteryStatus("discharging") + } + //Battery level increasing + else /*(prevBatteryLevel < level)*/ { + setBatteryStatus("charging") + } + //Set unit + unit = "%" + def descriptionTextLevel = "${device.displayName} battery level is ${level}${unit}" + def descriptionTextLastUpdate = "${device.displayName} battery information last updated ${lastUpdate}" + if (txtEnable) log.info "${descriptionTextLevel}" + if (txtEnable) log.info "${descriptionTextLastUpdate}" + //Update attributes + sendEvent(name: "battery", value: level, descriptionText: descriptionTextLevel, unit: unit) + sendEvent(name: "batteryLastUpdated", value : lastUpdate.format("yyyy/MM/dd HH:mm:ss"), descriptionText: descriptionTextLastUpdate) + //Reset warning count if there have been previous warnings + if (state.warningCount > 0) { + state.warningCount = 0 + log.info("setBattery(): Warning count reset") + } + } + // If the battery reading is outside the 0 - 100 range, log a warning and leave the current reading in place + // use the warning count state variable to make sure we don't spam the logs with repeated warnings + else { + if (state.warningCount < 10) { + state.warningCount++ + if (getBattery() == null) { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining ${prevBatteryLevel} battery level") + } + else { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining prevoius battery level ${prevBatteryLevel}%") + } + } + } +} + +//The other command to set battery level +def battery(level) { + setBattery(level) +} + +def tamperClear() { + def descriptionText = "${device.displayName} tamper is clear" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "clear", descriptionText: descriptionText) +} + +def tamperDetected() { + def descriptionText = "${device.displayName} tamper is detected" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "detected", descriptionText: descriptionText) +} + +//threeAxis(integer,integer,integer) input format: 0,0,0 +def threeAxis(x,y,z) { + def xyz = "x:${x},y:${y},z:${z}" + def descriptionText = "${device.displayName} threeAxis is ${xyz}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "threeAxis", value: xyz, descriptionText: descriptionText) + sendEvent(name: "xAxis", value: x) + sendEvent(name: "yAxis", value: y) + sendEvent(name: "zAxis", value: z) +} + +//setThreeAxis(string) input format: [x:0,y:0,z:0] +def setThreeAxis(xyz) { + //remove open bracket + removeBrackets = xyz.minus("[") + //remove close bracket + removeBrackets = removeBrackets.minus("]") + //split string into an array at "," + threeAxisArray = removeBrackets.split(",") + //split strings into arrys at ":" + xPair = threeAxisArray[0].split(":") + yPair = threeAxisArray[1].split(":") + zPair = threeAxisArray[2].split(":") + //to integers + int x = xPair[1] as Integer + int y = yPair[1] as Integer + int z = zPair[1] as Integer + //command + threeAxis(x,y,z) +} \ No newline at end of file diff --git a/examples/drivers/virtualOmniSensorPlus.groovy b/examples/drivers/virtualOmniSensorPlus.groovy index 098dcac..ecaf6ca 100644 --- a/examples/drivers/virtualOmniSensorPlus.groovy +++ b/examples/drivers/virtualOmniSensorPlus.groovy @@ -91,6 +91,7 @@ metadata { command "tamperClear" command "tamperDetected" command "threeAxis", [[name:"x",type:"NUMBER", description:"X-Axis", constraints:["NUMBER"]],[name:"y",type:"NUMBER", description:"Y-Axis", constraints:["NUMBER"]],[name:"z",type:"NUMBER", description:"Z-Axis", constraints:["NUMBER"]]] + command "setThreeAxis" attribute "variable", "String" attribute "batteryStatus", "String" attribute "batteryLastUpdated", "Date" @@ -367,6 +368,7 @@ def tamperDetected() { sendEvent(name: "tamper", value: "detected", descriptionText: descriptionText) } +//threeAxis(integer,integer,integer) input format: 0,0,0 def threeAxis(x,y,z) { def xyz = "x:${x},y:${y},z:${z}" def descriptionText = "${device.displayName} threeAxis is ${xyz}" @@ -376,3 +378,25 @@ def threeAxis(x,y,z) { sendEvent(name: "yAxis", value: y) sendEvent(name: "zAxis", value: z) } + +//setThreeAxis(string) input format: [x:0,y:0,z:0] +def setThreeAxis(xyz) { + if (xyz != null) { + //remove open bracket + removeBrackets = xyz.minus("[") + //remove close bracket + removeBrackets = removeBrackets.minus("]") + //split string into an array at "," + threeAxisArray = removeBrackets.split(",") + //split strings into arrys at ":" + xPair = threeAxisArray[0].split(":") + yPair = threeAxisArray[1].split(":") + zPair = threeAxisArray[2].split(":") + //to integers + int x = xPair[1] as Integer + int y = yPair[1] as Integer + int z = zPair[1] as Integer + //command + threeAxis(x,y,z) + } +} \ No newline at end of file diff --git a/examples/drivers/virtualZoozZSE11ZSE40.groovy b/examples/drivers/virtualZoozZSE11ZSE40.groovy new file mode 100644 index 0000000..0b06e87 --- /dev/null +++ b/examples/drivers/virtualZoozZSE11ZSE40.groovy @@ -0,0 +1,233 @@ +/************* +* Virtual Zooz ZSE11 +* Virtual Zooz ZSE40 +* Copyright 2021 Terrel Allen All Rights Reserved +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as published +* by the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +* WARNING!!! +* Use at your own risk. +* Modify at your own risk. +* +* USAGE +* n/a +* +* CHANGE LOG +* v202110031855 +* -initial release +* +*************/ + +metadata { + definition (name: "Virtual Fibaro ZW5", + namespace: "whodunitGorilla", + author: "Terrel Allen", + importUrl: "https://raw.githubusercontent.com/terrelsa13/HubitatPublic/master/examples/drivers/virtualFibaroZW5.groovy") + { + capability "Illuminance Measurement" + capability "Motion Sensor" + capability "Relative Humidity Measurement" + capability "Temperature Measurement" + capability "Battery" + capability "Tamper Alert" + command "motionActive" + command "motionInactive" + command "setIlluminance", ["Number"] + command "setRelativeHumidity", ["Number"] + command "setTemperature", ["Number"] + command "setVariable", ["String"] + command "setBattery", ["Number"] + command "batteryStatusIdle" + command "batteryStatusDischarging" + command "batteryStatusCharging" + command "tamperClear" + command "tamperDetected" + attribute "variable", "String" + attribute "batteryStatus", "String" + attribute "batteryLastUpdated", "Date" + } + preferences { + input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true + input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true + } +} + +def logsOff(){ + log.warn "debug logging disabled..." + device.updateSetting("logEnable",[value:"false",type:"bool"]) +} + +def installed() { + log.warn "installed..." + initialized() + setIlluminance(50) + setRelativeHumidity(35) + motionInactive() + setTemperature(70) + setBatteryStatus("unknown") + tamperClear() + runIn(1800,logsOff) +} + +void initialized() { + //Clear warning count for out of range battery level + state.warningCount = 0 +} + +def updated() { + log.info "updated..." + log.warn "debug logging is: ${logEnable == true}" + log.warn "description logging is: ${txtEnable == true}" + if (logEnable) runIn(1800,logsOff) +} + +def parse(String description) { +} + +def setIlluminance(lux) { + def descriptionText = "${device.displayName} is ${lux} lux" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "illuminance", value: lux, descriptionText: descriptionText, unit: "Lux") +} + +def setRelativeHumidity(humid) { + def descriptionText = "${device.displayName} humidity is ${humid}%" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "humidity", value: humid, descriptionText: descriptionText, unit: "RH%") +} + +def motionActive() { + def descriptionText = "${device.displayName} is active" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "active", descriptionText: descriptionText) +} + +def motionInactive() { + def descriptionText = "${device.displayName} is inactive" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "inactive", descriptionText: descriptionText) +} + +def setTemperature(temp) { + def unit = "°${location.temperatureScale}" + def descriptionText = "${device.displayName} temperature is ${temp}${unit}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "temperature", value: temp, descriptionText: descriptionText, unit: unit) +} + +def setVariable(str) { + def descriptionText = "${device.displayName} variable is ${str}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "variable", value: str, descriptionText: descriptionText) +} + +String getBatteryStatus() { + //return battery status + return device.currentValue("batteryStatus") +} + +def setBatteryStatus(status) { + def descriptionText = "${device.displayName} battery status is ${status}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "batteryStatus", value: status, descriptionText: descriptionText) +} + +def batteryStatusIdle() { + setBatteryStatus("idle") +} + +def batteryStatusDischarging() { + setBatteryStatus("discharging") +} + +def batteryStatusCharging() { + setBatteryStatus("charging") +} + +Number getBattery() { + //return battery level + return device.currentValue('battery') +} + +//Command to set the battery level +def setBattery(level) { +//def battery(level) { + //Check battery level is 0 - 100 + if(level >= 0 && level <= 100) { + //Get current date and time + Date lastUpdate = new Date() + //Get previous battery level + Number prevBatteryLevel = getBattery() + //No battery level set + if (prevBatteryLevel == null) { + setBatteryStatus("unknown") + } + //No change in battery level + else if (prevBatteryLevel == level) { + setBatteryStatus("idle") + } + //Battery level decreasing + else if (prevBatteryLevel > level) { + setBatteryStatus("discharging") + } + //Battery level increasing + else /*(prevBatteryLevel < level)*/ { + setBatteryStatus("charging") + } + //Set unit + unit = "%" + def descriptionTextLevel = "${device.displayName} battery level is ${level}${unit}" + def descriptionTextLastUpdate = "${device.displayName} battery information last updated ${lastUpdate}" + if (txtEnable) log.info "${descriptionTextLevel}" + if (txtEnable) log.info "${descriptionTextLastUpdate}" + //Update attributes + sendEvent(name: "battery", value: level, descriptionText: descriptionTextLevel, unit: unit) + sendEvent(name: "batteryLastUpdated", value : lastUpdate.format("yyyy/MM/dd HH:mm:ss"), descriptionText: descriptionTextLastUpdate) + //Reset warning count if there have been previous warnings + if (state.warningCount > 0) { + state.warningCount = 0 + log.info("setBattery(): Warning count reset") + } + } + // If the battery reading is outside the 0 - 100 range, log a warning and leave the current reading in place + // use the warning count state variable to make sure we don't spam the logs with repeated warnings + else { + if (state.warningCount < 10) { + state.warningCount++ + if (getBattery() == null) { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining ${prevBatteryLevel} battery level") + } + else { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining prevoius battery level ${prevBatteryLevel}%") + } + } + } +} + +//The other command to set battery level +def battery(level) { + setBattery(level) +} + +def tamperClear() { + def descriptionText = "${device.displayName} tamper is clear" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "clear", descriptionText: descriptionText) +} + +def tamperDetected() { + def descriptionText = "${device.displayName} tamper is detected" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "detected", descriptionText: descriptionText) +} \ No newline at end of file diff --git a/examples/drivers/virtualZoozZSE29.groovy b/examples/drivers/virtualZoozZSE29.groovy new file mode 100644 index 0000000..e125e75 --- /dev/null +++ b/examples/drivers/virtualZoozZSE29.groovy @@ -0,0 +1,213 @@ +/************* +* Virtual Zooz ZSE29 +* Copyright 2021 Terrel Allen All Rights Reserved +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as published +* by the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +* WARNING!!! +* Use at your own risk. +* Modify at your own risk. +* +* USAGE +* n/a +* +* CHANGE LOG +* v202110031855 +* -initial release +* +*************/ + +metadata { + definition (name: "Virtual Fibaro ZW5", + namespace: "whodunitGorilla", + author: "Terrel Allen", + importUrl: "https://raw.githubusercontent.com/terrelsa13/HubitatPublic/master/examples/drivers/virtualFibaroZW5.groovy") + { + capability "Illuminance Measurement" + capability "Motion Sensor" + capability "Battery" + capability "Tamper Alert" + command "motionActive" + command "motionInactive" + command "setIlluminance", ["Number"] + command "setVariable", ["String"] + command "setBattery", ["Number"] + command "batteryStatusIdle" + command "batteryStatusDischarging" + command "batteryStatusCharging" + command "tamperClear" + command "tamperDetected" + attribute "variable", "String" + attribute "batteryStatus", "String" + attribute "batteryLastUpdated", "Date" + } + preferences { + input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true + input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true + } +} + +def logsOff(){ + log.warn "debug logging disabled..." + device.updateSetting("logEnable",[value:"false",type:"bool"]) +} + +def installed() { + log.warn "installed..." + initialized() + setIlluminance(50) + motionInactive() + setBatteryStatus("unknown") + tamperClear() + runIn(1800,logsOff) +} + +void initialized() { + //Clear warning count for out of range battery level + state.warningCount = 0 +} + +def updated() { + log.info "updated..." + log.warn "debug logging is: ${logEnable == true}" + log.warn "description logging is: ${txtEnable == true}" + if (logEnable) runIn(1800,logsOff) +} + +def parse(String description) { +} + +def setIlluminance(lux) { + def descriptionText = "${device.displayName} is ${lux} lux" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "illuminance", value: lux, descriptionText: descriptionText, unit: "Lux") +} + +def motionActive() { + def descriptionText = "${device.displayName} is active" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "active", descriptionText: descriptionText) +} + +def motionInactive() { + def descriptionText = "${device.displayName} is inactive" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "inactive", descriptionText: descriptionText) +} + +def setVariable(str) { + def descriptionText = "${device.displayName} variable is ${str}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "variable", value: str, descriptionText: descriptionText) +} + +String getBatteryStatus() { + //return battery status + return device.currentValue("batteryStatus") +} + +def setBatteryStatus(status) { + def descriptionText = "${device.displayName} battery status is ${status}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "batteryStatus", value: status, descriptionText: descriptionText) +} + +def batteryStatusIdle() { + setBatteryStatus("idle") +} + +def batteryStatusDischarging() { + setBatteryStatus("discharging") +} + +def batteryStatusCharging() { + setBatteryStatus("charging") +} + +Number getBattery() { + //return battery level + return device.currentValue('battery') +} + +//Command to set the battery level +def setBattery(level) { +//def battery(level) { + //Check battery level is 0 - 100 + if(level >= 0 && level <= 100) { + //Get current date and time + Date lastUpdate = new Date() + //Get previous battery level + Number prevBatteryLevel = getBattery() + //No battery level set + if (prevBatteryLevel == null) { + setBatteryStatus("unknown") + } + //No change in battery level + else if (prevBatteryLevel == level) { + setBatteryStatus("idle") + } + //Battery level decreasing + else if (prevBatteryLevel > level) { + setBatteryStatus("discharging") + } + //Battery level increasing + else /*(prevBatteryLevel < level)*/ { + setBatteryStatus("charging") + } + //Set unit + unit = "%" + def descriptionTextLevel = "${device.displayName} battery level is ${level}${unit}" + def descriptionTextLastUpdate = "${device.displayName} battery information last updated ${lastUpdate}" + if (txtEnable) log.info "${descriptionTextLevel}" + if (txtEnable) log.info "${descriptionTextLastUpdate}" + //Update attributes + sendEvent(name: "battery", value: level, descriptionText: descriptionTextLevel, unit: unit) + sendEvent(name: "batteryLastUpdated", value : lastUpdate.format("yyyy/MM/dd HH:mm:ss"), descriptionText: descriptionTextLastUpdate) + //Reset warning count if there have been previous warnings + if (state.warningCount > 0) { + state.warningCount = 0 + log.info("setBattery(): Warning count reset") + } + } + // If the battery reading is outside the 0 - 100 range, log a warning and leave the current reading in place + // use the warning count state variable to make sure we don't spam the logs with repeated warnings + else { + if (state.warningCount < 10) { + state.warningCount++ + if (getBattery() == null) { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining ${prevBatteryLevel} battery level") + } + else { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining prevoius battery level ${prevBatteryLevel}%") + } + } + } +} + +//The other command to set battery level +def battery(level) { + setBattery(level) +} + +def tamperClear() { + def descriptionText = "${device.displayName} tamper is clear" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "clear", descriptionText: descriptionText) +} + +def tamperDetected() { + def descriptionText = "${device.displayName} tamper is detected" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "tamper", value: "detected", descriptionText: descriptionText) +} \ No newline at end of file From 71c26ae29283a923627abe0abbd6aeb57a084134 Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Tue, 5 Oct 2021 21:27:05 -0400 Subject: [PATCH 12/15] Add files via upload --- examples/drivers/virtualZoozZSE11ZSE40.groovy | 2 +- examples/drivers/virtualZoozZSE29.groovy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/drivers/virtualZoozZSE11ZSE40.groovy b/examples/drivers/virtualZoozZSE11ZSE40.groovy index 0b06e87..badf262 100644 --- a/examples/drivers/virtualZoozZSE11ZSE40.groovy +++ b/examples/drivers/virtualZoozZSE11ZSE40.groovy @@ -30,7 +30,7 @@ *************/ metadata { - definition (name: "Virtual Fibaro ZW5", + definition (name: "Virtual Zooz ZSE11 ZSE40", namespace: "whodunitGorilla", author: "Terrel Allen", importUrl: "https://raw.githubusercontent.com/terrelsa13/HubitatPublic/master/examples/drivers/virtualFibaroZW5.groovy") diff --git a/examples/drivers/virtualZoozZSE29.groovy b/examples/drivers/virtualZoozZSE29.groovy index e125e75..d214297 100644 --- a/examples/drivers/virtualZoozZSE29.groovy +++ b/examples/drivers/virtualZoozZSE29.groovy @@ -29,7 +29,7 @@ *************/ metadata { - definition (name: "Virtual Fibaro ZW5", + definition (name: "Virtual Zooz ZSE29", namespace: "whodunitGorilla", author: "Terrel Allen", importUrl: "https://raw.githubusercontent.com/terrelsa13/HubitatPublic/master/examples/drivers/virtualFibaroZW5.groovy") From 3a51b3ad9168f82bd61cce4f1d4433674e0aa242 Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Tue, 28 Dec 2021 21:41:26 -0500 Subject: [PATCH 13/15] Add files via upload --- .../drivers/virtualPhilipsHueMotion.groovy | 207 ++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 examples/drivers/virtualPhilipsHueMotion.groovy diff --git a/examples/drivers/virtualPhilipsHueMotion.groovy b/examples/drivers/virtualPhilipsHueMotion.groovy new file mode 100644 index 0000000..76c5649 --- /dev/null +++ b/examples/drivers/virtualPhilipsHueMotion.groovy @@ -0,0 +1,207 @@ +/************* +* Virtual Philips Hue Motion Sensor +* Copyright 2021 Terrel Allen All Rights Reserved +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as published +* by the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +* WARNING!!! +* Use at your own risk. +* Modify at your own risk. +* +* USAGE +* n/a +* +* CHANGE LOG +* v202112282131 +* -initial release +* +*************/ + +metadata { + definition (name: "Virtual Philips Hue Motion Sensor", + namespace: "whodunitGorilla", + author: "Terrel Allen", + importUrl: "https://raw.githubusercontent.com/terrelsa13/HubitatPublic/master/examples/drivers/virtualPhilipsHueMotion.groovy") + { + capability "Illuminance Measurement" + capability "Motion Sensor" + capability "Temperature Measurement" + capability "Battery" + command "motionActive" + command "motionInactive" + command "setIlluminance", ["Number"] + command "setTemperature", ["Number"] + command "setVariable", ["String"] + command "setBattery", ["Number"] + command "batteryStatusIdle" + command "batteryStatusDischarging" + command "batteryStatusCharging" + attribute "variable", "String" + attribute "batteryStatus", "String" + attribute "batteryLastUpdated", "Date" + } + preferences { + input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true + input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true + } +} + +def logsOff(){ + log.warn "debug logging disabled..." + device.updateSetting("logEnable",[value:"false",type:"bool"]) +} + +def installed() { + log.warn "installed..." + initialized() + setIlluminance(50) + motionInactive() + setTemperature(70) + setBatteryStatus("unknown") + runIn(1800,logsOff) +} + +void initialized() { + //Clear warning count for out of range battery level + state.warningCount = 0 +} + +def updated() { + log.info "updated..." + log.warn "debug logging is: ${logEnable == true}" + log.warn "description logging is: ${txtEnable == true}" + if (logEnable) runIn(1800,logsOff) +} + +def parse(String description) { +} + +def setIlluminance(lux) { + def descriptionText = "${device.displayName} is ${lux} lux" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "illuminance", value: lux, descriptionText: descriptionText, unit: "Lux") +} + +def motionActive() { + def descriptionText = "${device.displayName} is active" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "active", descriptionText: descriptionText) +} + +def motionInactive() { + def descriptionText = "${device.displayName} is inactive" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "inactive", descriptionText: descriptionText) +} + +def setTemperature(temp) { + def unit = "°${location.temperatureScale}" + def descriptionText = "${device.displayName} temperature is ${temp}${unit}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "temperature", value: temp, descriptionText: descriptionText, unit: unit) +} + +def setVariable(str) { + def descriptionText = "${device.displayName} variable is ${str}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "variable", value: str, descriptionText: descriptionText) +} + +String getBatteryStatus() { + //return battery status + return device.currentValue("batteryStatus") +} + +def setBatteryStatus(status) { + def descriptionText = "${device.displayName} battery status is ${status}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "batteryStatus", value: status, descriptionText: descriptionText) +} + +def batteryStatusIdle() { + setBatteryStatus("idle") +} + +def batteryStatusDischarging() { + setBatteryStatus("discharging") +} + +def batteryStatusCharging() { + setBatteryStatus("charging") +} + +Number getBattery() { + //return battery level + return device.currentValue('battery') +} + +//Command to set the battery level +def setBattery(level) { +//def battery(level) { + //Check battery level is 0 - 100 + if(level >= 0 && level <= 100) { + //Get current date and time + Date lastUpdate = new Date() + //Get previous battery level + Number prevBatteryLevel = getBattery() + //No battery level set + if (prevBatteryLevel == null) { + setBatteryStatus("unknown") + } + //No change in battery level + else if (prevBatteryLevel == level) { + setBatteryStatus("idle") + } + //Battery level decreasing + else if (prevBatteryLevel > level) { + setBatteryStatus("discharging") + } + //Battery level increasing + else /*(prevBatteryLevel < level)*/ { + setBatteryStatus("charging") + } + //Set unit + unit = "%" + def descriptionTextLevel = "${device.displayName} battery level is ${level}${unit}" + def descriptionTextLastUpdate = "${device.displayName} battery information last updated ${lastUpdate}" + if (txtEnable) log.info "${descriptionTextLevel}" + if (txtEnable) log.info "${descriptionTextLastUpdate}" + //Update attributes + sendEvent(name: "battery", value: level, descriptionText: descriptionTextLevel, unit: unit) + sendEvent(name: "batteryLastUpdated", value : lastUpdate.format("yyyy/MM/dd HH:mm:ss"), descriptionText: descriptionTextLastUpdate) + //Reset warning count if there have been previous warnings + if (state.warningCount > 0) { + state.warningCount = 0 + log.info("setBattery(): Warning count reset") + } + } + // If the battery reading is outside the 0 - 100 range, log a warning and leave the current reading in place + // use the warning count state variable to make sure we don't spam the logs with repeated warnings + else { + if (state.warningCount < 10) { + state.warningCount++ + if (getBattery() == null) { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining ${prevBatteryLevel} battery level") + } + else { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining prevoius battery level ${prevBatteryLevel}%") + } + } + } +} + +//The other command to set battery level +def battery(level) { + setBattery(level) +} \ No newline at end of file From d897762211e992ea84a70d2c3e74d76be707ff2a Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Sat, 27 Aug 2022 18:58:18 -0400 Subject: [PATCH 14/15] Add files via upload --- .../drivers/virtualPhilipsHueSML001.groovy | 207 ++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 examples/drivers/virtualPhilipsHueSML001.groovy diff --git a/examples/drivers/virtualPhilipsHueSML001.groovy b/examples/drivers/virtualPhilipsHueSML001.groovy new file mode 100644 index 0000000..fc3ec95 --- /dev/null +++ b/examples/drivers/virtualPhilipsHueSML001.groovy @@ -0,0 +1,207 @@ +/************* +* Virtual Philips Hue SML001 +* Copyright 2021 Terrel Allen All Rights Reserved +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as published +* by the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +* WARNING!!! +* Use at your own risk. +* Modify at your own risk. +* +* USAGE +* Virtual Philips Hue SML001 Driver +* +* CHANGE LOG +* v202208271853 +* -initial release +* +*************/ + +metadata { + definition (name: "Virtual Philips Hue SML001", + namespace: "whodunitGorilla", + author: "Terrel Allen", + importUrl: "https://raw.githubusercontent.com/terrelsa13/HubitatPublic/master/examples/drivers/virtualPhilipsHueSML001.groovy") + { + capability "Illuminance Measurement" + capability "Motion Sensor" + capability "Temperature Measurement" + capability "Battery" + command "motionActive" + command "motionInactive" + command "setIlluminance", ["Number"] + command "setTemperature", ["Number"] + command "setVariable", ["String"] + command "setBattery", ["Number"] + command "batteryStatusIdle" + command "batteryStatusDischarging" + command "batteryStatusCharging" + attribute "variable", "String" + attribute "batteryStatus", "String" + attribute "batteryLastUpdated", "Date" + } + preferences { + input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true + input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true + } +} + +def logsOff(){ + log.warn "debug logging disabled..." + device.updateSetting("logEnable",[value:"false",type:"bool"]) +} + +def installed() { + log.warn "installed..." + initialized() + setIlluminance(50) + motionInactive() + setTemperature(70) + setBatteryStatus("unknown") + runIn(1800,logsOff) +} + +void initialized() { + //Clear warning count for out of range battery level + state.warningCount = 0 +} + +def updated() { + log.info "updated..." + log.warn "debug logging is: ${logEnable == true}" + log.warn "description logging is: ${txtEnable == true}" + if (logEnable) runIn(1800,logsOff) +} + +def parse(String description) { +} + +def setIlluminance(lux) { + def descriptionText = "${device.displayName} is ${lux} lux" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "illuminance", value: lux, descriptionText: descriptionText, unit: "Lux") +} + +def motionActive() { + def descriptionText = "${device.displayName} is active" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "active", descriptionText: descriptionText) +} + +def motionInactive() { + def descriptionText = "${device.displayName} is inactive" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "motion", value: "inactive", descriptionText: descriptionText) +} + +def setTemperature(temp) { + def unit = "°${location.temperatureScale}" + def descriptionText = "${device.displayName} temperature is ${temp}${unit}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "temperature", value: temp, descriptionText: descriptionText, unit: unit) +} + +def setVariable(str) { + def descriptionText = "${device.displayName} variable is ${str}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "variable", value: str, descriptionText: descriptionText) +} + +String getBatteryStatus() { + //return battery status + return device.currentValue("batteryStatus") +} + +def setBatteryStatus(status) { + def descriptionText = "${device.displayName} battery status is ${status}" + if (txtEnable) log.info "${descriptionText}" + sendEvent(name: "batteryStatus", value: status, descriptionText: descriptionText) +} + +def batteryStatusIdle() { + setBatteryStatus("idle") +} + +def batteryStatusDischarging() { + setBatteryStatus("discharging") +} + +def batteryStatusCharging() { + setBatteryStatus("charging") +} + +Number getBattery() { + //return battery level + return device.currentValue('battery') +} + +//Command to set the battery level +def setBattery(level) { +//def battery(level) { + //Check battery level is 0 - 100 + if(level >= 0 && level <= 100) { + //Get current date and time + Date lastUpdate = new Date() + //Get previous battery level + Number prevBatteryLevel = getBattery() + //No battery level set + if (prevBatteryLevel == null) { + setBatteryStatus("unknown") + } + //No change in battery level + else if (prevBatteryLevel == level) { + setBatteryStatus("idle") + } + //Battery level decreasing + else if (prevBatteryLevel > level) { + setBatteryStatus("discharging") + } + //Battery level increasing + else /*(prevBatteryLevel < level)*/ { + setBatteryStatus("charging") + } + //Set unit + unit = "%" + def descriptionTextLevel = "${device.displayName} battery level is ${level}${unit}" + def descriptionTextLastUpdate = "${device.displayName} battery information last updated ${lastUpdate}" + if (txtEnable) log.info "${descriptionTextLevel}" + if (txtEnable) log.info "${descriptionTextLastUpdate}" + //Update attributes + sendEvent(name: "battery", value: level, descriptionText: descriptionTextLevel, unit: unit) + sendEvent(name: "batteryLastUpdated", value : lastUpdate.format("yyyy/MM/dd HH:mm:ss"), descriptionText: descriptionTextLastUpdate) + //Reset warning count if there have been previous warnings + if (state.warningCount > 0) { + state.warningCount = 0 + log.info("setBattery(): Warning count reset") + } + } + // If the battery reading is outside the 0 - 100 range, log a warning and leave the current reading in place + // use the warning count state variable to make sure we don't spam the logs with repeated warnings + else { + if (state.warningCount < 10) { + state.warningCount++ + if (getBattery() == null) { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining ${prevBatteryLevel} battery level") + } + else { + log.warn("setBattery(): Warning (#${state.warningCount}) - Battery level outside of 0%-100% range, ${device.displayName} not updated. Retaining prevoius battery level ${prevBatteryLevel}%") + } + } + } +} + +//The other command to set battery level +def battery(level) { + setBattery(level) +} \ No newline at end of file From bae75b8dc53035c65b2abb6233ad42142c110189 Mon Sep 17 00:00:00 2001 From: terrelsa13 Date: Tue, 17 Jan 2023 11:09:17 -0500 Subject: [PATCH 15/15] Add SML002 Outdoor Sensor --- ....groovy => virtualPhilipsHueSML001_SML002.groovy} | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) rename examples/drivers/{virtualPhilipsHueSML001.groovy => virtualPhilipsHueSML001_SML002.groovy} (96%) diff --git a/examples/drivers/virtualPhilipsHueSML001.groovy b/examples/drivers/virtualPhilipsHueSML001_SML002.groovy similarity index 96% rename from examples/drivers/virtualPhilipsHueSML001.groovy rename to examples/drivers/virtualPhilipsHueSML001_SML002.groovy index fc3ec95..add1c9e 100644 --- a/examples/drivers/virtualPhilipsHueSML001.groovy +++ b/examples/drivers/virtualPhilipsHueSML001_SML002.groovy @@ -1,5 +1,5 @@ /************* -* Virtual Philips Hue SML001 +* Virtual Philips Hue SML001 SML002 * Copyright 2021 Terrel Allen All Rights Reserved * * This program is free software: you can redistribute it and/or modify @@ -20,19 +20,21 @@ * Modify at your own risk. * * USAGE -* Virtual Philips Hue SML001 Driver +* Virtual Philips Hue SML001 And SML002 Driver * * CHANGE LOG +* v202301171107 +* -add SML002 outdoor motion sensor * v202208271853 * -initial release * *************/ metadata { - definition (name: "Virtual Philips Hue SML001", + definition (name: "Virtual Philips Hue SML001 SML002", namespace: "whodunitGorilla", author: "Terrel Allen", - importUrl: "https://raw.githubusercontent.com/terrelsa13/HubitatPublic/master/examples/drivers/virtualPhilipsHueSML001.groovy") + importUrl: "https://raw.githubusercontent.com/terrelsa13/HubitatPublic/master/examples/drivers/virtualPhilipsHueSML001_SML002.groovy") { capability "Illuminance Measurement" capability "Motion Sensor" @@ -204,4 +206,4 @@ def setBattery(level) { //The other command to set battery level def battery(level) { setBattery(level) -} \ No newline at end of file +}