mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-09 05:11:52 +00:00
Compare commits
32 Commits
MSA-2080-1
...
MSA-2119-9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbd82d0564 | ||
|
|
de5f0683d3 | ||
|
|
36e63133fc | ||
|
|
838c466312 | ||
|
|
97bfe61baa | ||
|
|
34df40d5b4 | ||
|
|
545be046f0 | ||
|
|
a5041e0fcb | ||
|
|
5beae1d9fc | ||
|
|
e5738978b0 | ||
|
|
07064eb8cc | ||
|
|
f519a2d828 | ||
|
|
4da49283bf | ||
|
|
7389edf795 | ||
|
|
23154372d2 | ||
|
|
1b0437c633 | ||
|
|
b3d9578140 | ||
|
|
7549979be5 | ||
|
|
771926c337 | ||
|
|
f647be3a62 | ||
|
|
d2f981fd34 | ||
|
|
2536c69083 | ||
|
|
a58dd2094d | ||
|
|
c549a5bed0 | ||
|
|
ef5fffc4bc | ||
|
|
c370e88a6b | ||
|
|
ce8c50c630 | ||
|
|
b069669c11 | ||
|
|
4d61d28b42 | ||
|
|
6b1e41198c | ||
|
|
f752a01906 | ||
|
|
45663ffb86 |
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Spruce Sensor -Pre-release V2 10/8/2015
|
||||
* Spruce Sensor -updated with SLP model number 5/2017
|
||||
*
|
||||
* Copyright 2014 Plaid Systems
|
||||
*
|
||||
@@ -14,25 +14,33 @@
|
||||
*
|
||||
-------10/20/2015 Updates--------
|
||||
-Fix/add battery reporting interval to update
|
||||
-remove polling and/or refresh(?)
|
||||
-remove polling and/or refresh
|
||||
|
||||
-------5/2017 Updates--------
|
||||
-Add fingerprints for SLP
|
||||
-add device health, check every 60mins + 2mins
|
||||
*/
|
||||
|
||||
metadata {
|
||||
definition (name: "Spruce Sensor", namespace: "plaidsystems", author: "NCauffman") {
|
||||
definition (name: "Spruce Sensor", namespace: "plaidsystems", author: "Plaid Systems") {
|
||||
|
||||
capability "Configuration"
|
||||
capability "Battery"
|
||||
capability "Relative Humidity Measurement"
|
||||
capability "Temperature Measurement"
|
||||
capability "Sensor"
|
||||
capability "Health Check"
|
||||
//capability "Polling"
|
||||
|
||||
attribute "maxHum", "string"
|
||||
attribute "minHum", "string"
|
||||
|
||||
|
||||
command "resetHumidity"
|
||||
command "refresh"
|
||||
|
||||
fingerprint profileId: "0104", inClusters: "0000,0001,0003,0402,0405", outClusters: "0003, 0019", manufacturer: "PLAID SYSTEMS", model: "PS-SPRZMS-01"
|
||||
fingerprint profileId: "0104", inClusters: "0000,0001,0003,0402,0405", outClusters: "0003, 0019", manufacturer: "PLAID SYSTEMS", model: "PS-SPRZMS-01", deviceJoinName: "Spruce Sensor"
|
||||
fingerprint profileId: "0104", inClusters: "0000,0001,0003,0402,0405", outClusters: "0003, 0019", manufacturer: "PLAID SYSTEMS", model: "PS-SPRZMS-SLP1", deviceJoinName: "Spruce Sensor"
|
||||
}
|
||||
|
||||
preferences {
|
||||
@@ -293,6 +301,11 @@ def setConfig(){
|
||||
sendEvent(name: 'configuration',value: configInterval, descriptionText: "Configuration initialized")
|
||||
}
|
||||
|
||||
def installed(){
|
||||
//check every 1 hour + 2mins
|
||||
sendEvent(name: "checkInterval", value: 1 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
||||
}
|
||||
|
||||
//when device preferences are changed
|
||||
def updated(){
|
||||
log.debug "device updated"
|
||||
@@ -303,6 +316,8 @@ def updated(){
|
||||
sendEvent(name: 'configuration',value: 0, descriptionText: "Settings changed and will update at next report. Measure interval set to ${interval} mins")
|
||||
}
|
||||
}
|
||||
//check every 1 hour + 2mins
|
||||
sendEvent(name: "checkInterval", value: 1 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
||||
}
|
||||
|
||||
//poll
|
||||
@@ -395,4 +410,4 @@ private byte[] reverseArray(byte[] array) {
|
||||
i++;
|
||||
}
|
||||
return array
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,13 +27,9 @@ Works with:
|
||||
## Device Health
|
||||
|
||||
Aeon Labs MultiSensor 6 is polled by the hub.
|
||||
As of hubCore version 0.14.38 the hub sends up reports every 15 minutes regardless of whether the state changed.
|
||||
Device-Watch allows 2 check-in misses from device plus some lag time. So Check-in interval = (2*15 + 2)mins = 32 mins.
|
||||
Not to mention after going OFFLINE when the device is plugged back in, it might take a considerable amount of time for
|
||||
the device to appear as ONLINE again. This is because if this listening device does not respond to two poll requests in a row,
|
||||
it is not polled for 5 minutes by the hub. This can delay up the process of being marked ONLINE by quite some time.
|
||||
Aeon MultiSensor reports in once every hour.
|
||||
|
||||
* __32min__ checkInterval
|
||||
* __122min__ checkInterval
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
|
||||
@@ -130,13 +130,13 @@ metadata {
|
||||
}
|
||||
|
||||
def installed(){
|
||||
// Device-Watch simply pings if no device events received for 32min(checkInterval)
|
||||
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
||||
// Device-Watch simply pings if no device events received for 122min(checkInterval)
|
||||
sendEvent(name: "checkInterval", value: 2 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
||||
}
|
||||
|
||||
def updated() {
|
||||
// Device-Watch simply pings if no device events received for 32min(checkInterval)
|
||||
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
||||
// Device-Watch simply pings if no device events received for 122min(checkInterval)
|
||||
sendEvent(name: "checkInterval", value: 2 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
||||
log.debug "Updated with settings: ${settings}"
|
||||
log.debug "${device.displayName} is now ${device.latestValue("powerSupply")}"
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ def generateEvent(Map results) {
|
||||
if(results) {
|
||||
|
||||
def linkText = getLinkText(device)
|
||||
def supportedThermostatModes = []
|
||||
def supportedThermostatModes = ["off"]
|
||||
def thermostatMode = null
|
||||
|
||||
results.each { name, value ->
|
||||
|
||||
@@ -105,6 +105,8 @@ def parse(String description) {
|
||||
} else {
|
||||
log.warn "TEMP REPORTING CONFIG FAILED- error code: ${descMap.data[0]}"
|
||||
}
|
||||
} else if (descMap?.clusterInt == zigbee.IAS_ZONE_CLUSTER && descMap.attrInt == zigbee.ATTRIBUTE_IAS_ZONE_STATUS && descMap?.value) {
|
||||
map = translateZoneStatus(new ZoneStatus(zigbee.convertToInt(descMap?.value)))
|
||||
}
|
||||
}
|
||||
} else if (map.name == "temperature") {
|
||||
@@ -129,6 +131,10 @@ def parse(String description) {
|
||||
private Map parseIasMessage(String description) {
|
||||
ZoneStatus zs = zigbee.parseZoneStatus(description)
|
||||
|
||||
translateZoneStatus(zs)
|
||||
}
|
||||
|
||||
private Map translateZoneStatus(ZoneStatus zs) {
|
||||
return zs.isAlarm1Set() ? getMoistureResult('wet') : getMoistureResult('dry')
|
||||
}
|
||||
|
||||
@@ -197,7 +203,8 @@ def ping() {
|
||||
def refresh() {
|
||||
log.debug "Refreshing Temperature and Battery"
|
||||
def refreshCmds = zigbee.readAttribute(zigbee.TEMPERATURE_MEASUREMENT_CLUSTER, 0x0000) +
|
||||
zigbee.readAttribute(zigbee.POWER_CONFIGURATION_CLUSTER, 0x0020)
|
||||
zigbee.readAttribute(zigbee.POWER_CONFIGURATION_CLUSTER, 0x0020) +
|
||||
zigbee.readAttribute(zigbee.IAS_ZONE_CLUSTER, zigbee.ATTRIBUTE_IAS_ZONE_STATUS)
|
||||
|
||||
return refreshCmds + zigbee.enrollResponse()
|
||||
}
|
||||
|
||||
@@ -111,6 +111,8 @@ def parse(String description) {
|
||||
def value = descMap.value.endsWith("01") ? "active" : "inactive"
|
||||
log.debug "Doing a read attr motion event"
|
||||
map = getMotionResult(value)
|
||||
} else if (descMap?.clusterInt == zigbee.IAS_ZONE_CLUSTER && descMap.attrInt == zigbee.ATTRIBUTE_IAS_ZONE_STATUS && descMap?.value) {
|
||||
map = translateZoneStatus(new ZoneStatus(zigbee.convertToInt(descMap?.value)))
|
||||
}
|
||||
}
|
||||
} else if (map.name == "temperature") {
|
||||
@@ -135,6 +137,10 @@ def parse(String description) {
|
||||
private Map parseIasMessage(String description) {
|
||||
ZoneStatus zs = zigbee.parseZoneStatus(description)
|
||||
|
||||
translateZoneStatus(zs)
|
||||
}
|
||||
|
||||
private Map translateZoneStatus(ZoneStatus zs) {
|
||||
// Some sensor models that use this DTH use alarm1 and some use alarm2 to signify motion
|
||||
return (zs.isAlarm1Set() || zs.isAlarm2Set()) ? getMotionResult('active') : getMotionResult('inactive')
|
||||
}
|
||||
@@ -165,8 +171,8 @@ private Map getBatteryResult(rawValue) {
|
||||
def pct = batteryMap[volts]
|
||||
result.value = pct
|
||||
} else {
|
||||
def minVolts = 2.1
|
||||
def maxVolts = 3.0
|
||||
def minVolts = 2.4
|
||||
def maxVolts = 2.7
|
||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
||||
def roundedPct = Math.round(pct * 100)
|
||||
if (roundedPct <= 0)
|
||||
@@ -200,7 +206,8 @@ def refresh() {
|
||||
log.debug "refresh called"
|
||||
|
||||
def refreshCmds = zigbee.readAttribute(zigbee.POWER_CONFIGURATION_CLUSTER, 0x0020) +
|
||||
zigbee.readAttribute(zigbee.TEMPERATURE_MEASUREMENT_CLUSTER, 0x0000)
|
||||
zigbee.readAttribute(zigbee.TEMPERATURE_MEASUREMENT_CLUSTER, 0x0000) +
|
||||
zigbee.readAttribute(zigbee.IAS_ZONE_CLUSTER, zigbee.ATTRIBUTE_IAS_ZONE_STATUS)
|
||||
|
||||
return refreshCmds + zigbee.enrollResponse()
|
||||
}
|
||||
|
||||
@@ -134,8 +134,9 @@ def parse(String description) {
|
||||
} else {
|
||||
log.warn "TEMP REPORTING CONFIG FAILED- error code: ${descMap.data[0]}"
|
||||
}
|
||||
} else if (descMap?.clusterInt == zigbee.IAS_ZONE_CLUSTER && descMap.attrInt == zigbee.ATTRIBUTE_IAS_ZONE_STATUS && descMap?.value) {
|
||||
maps += translateZoneStatus(new ZoneStatus(zigbee.convertToInt(descMap?.value)))
|
||||
} else {
|
||||
|
||||
maps += handleAcceleration(descMap)
|
||||
}
|
||||
}
|
||||
@@ -229,6 +230,11 @@ private List<Map> parseAxis(List<Map> attrData) {
|
||||
|
||||
private List<Map> parseIasMessage(String description) {
|
||||
ZoneStatus zs = zigbee.parseZoneStatus(description)
|
||||
|
||||
translateZoneStatus(zs)
|
||||
}
|
||||
|
||||
private List<Map> translateZoneStatus(ZoneStatus zs) {
|
||||
List<Map> results = []
|
||||
|
||||
if (garageSensor != "Yes") {
|
||||
@@ -268,7 +274,7 @@ private Map getBatteryResult(rawValue) {
|
||||
result.value = pct
|
||||
} else {
|
||||
def minVolts = 2.1
|
||||
def maxVolts = 3.0
|
||||
def maxVolts = 2.7
|
||||
def pct = (volts - minVolts) / (maxVolts - minVolts)
|
||||
def roundedPct = Math.round(pct * 100)
|
||||
if (roundedPct <= 0)
|
||||
@@ -313,7 +319,7 @@ def refresh() {
|
||||
def refreshCmds = zigbee.readAttribute(zigbee.TEMPERATURE_MEASUREMENT_CLUSTER, 0x0000) +
|
||||
zigbee.readAttribute(zigbee.POWER_CONFIGURATION_CLUSTER, 0x0020) +
|
||||
zigbee.readAttribute(0xFC02, 0x0010, [mfgCode: manufacturerCode]) +
|
||||
zigbee.enrollResponse()
|
||||
zigbee.readAttribute(zigbee.IAS_ZONE_CLUSTER, zigbee.ATTRIBUTE_IAS_ZONE_STATUS) + zigbee.enrollResponse()
|
||||
|
||||
return refreshCmds
|
||||
}
|
||||
|
||||
@@ -28,9 +28,8 @@ Works with:
|
||||
|
||||
## Device Health
|
||||
|
||||
SmartThings platform will ping the device after `checkInterval` seconds of inactivity in last attempt to reach the device before marking it `OFFLINE`
|
||||
ZigBee Button is marked offline only in the case when Hub is offline.
|
||||
|
||||
* __722min__ checkInterval
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
* for the specific language governing permissions and limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import physicalgraph.zigbee.zcl.DataType
|
||||
|
||||
metadata {
|
||||
@@ -183,13 +185,6 @@ private Map parseNonIasButtonMessage(Map descMap){
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PING is used by Device-Watch in attempt to reach the Device
|
||||
* */
|
||||
def ping() {
|
||||
refresh()
|
||||
}
|
||||
|
||||
def refresh() {
|
||||
log.debug "Refreshing Battery"
|
||||
|
||||
@@ -198,8 +193,6 @@ def refresh() {
|
||||
}
|
||||
|
||||
def configure() {
|
||||
// Device-Watch allows 2 check-in misses from device (plus 2 mins lag time)
|
||||
sendEvent(name: "checkInterval", value: 2 * 6 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
||||
log.debug "Configuring Reporting, IAS CIE, and Bindings."
|
||||
def cmds = []
|
||||
if (device.getDataValue("model") == "3450-L") {
|
||||
@@ -259,6 +252,8 @@ def updated() {
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
// Arrival sensors only goes OFFLINE when Hub is off
|
||||
sendEvent(name: "DeviceWatch-Enroll", value: JsonOutput.toJson([protocol: "zigbee", scheme:"untracked"]), displayed: false)
|
||||
if ((device.getDataValue("manufacturer") == "OSRAM") && (device.getDataValue("model") == "LIGHTIFY Dimming Switch")) {
|
||||
sendEvent(name: "numberOfButtons", value: 2)
|
||||
}
|
||||
|
||||
@@ -15,10 +15,9 @@ metadata {
|
||||
definition (name: "Z-Wave Thermostat", namespace: "smartthings", author: "SmartThings") {
|
||||
capability "Actuator"
|
||||
capability "Temperature Measurement"
|
||||
capability "Relative Humidity Measurement"
|
||||
capability "Thermostat"
|
||||
capability "Configuration"
|
||||
capability "Polling"
|
||||
capability "Refresh"
|
||||
capability "Sensor"
|
||||
capability "Health Check"
|
||||
|
||||
@@ -117,7 +116,7 @@ metadata {
|
||||
state "cool", label:'${currentValue}° cool', backgroundColor:"#ffffff"
|
||||
}
|
||||
standardTile("refresh", "device.thermostatMode", inactiveLabel: false, decoration: "flat") {
|
||||
state "default", action:"polling.poll", icon:"st.secondary.refresh"
|
||||
state "default", action:"refresh.refresh", icon:"st.secondary.refresh"
|
||||
}
|
||||
main "temperature"
|
||||
details(["temperature", "mode", "fanMode", "heatSliderControl", "heatingSetpoint", "coolSliderControl", "coolingSetpoint", "refresh"])
|
||||
@@ -125,13 +124,20 @@ metadata {
|
||||
}
|
||||
|
||||
def installed(){
|
||||
// Device-Watch simply pings if no device events received for 32min(checkInterval)
|
||||
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
||||
sendHubCommand(new physicalgraph.device.HubAction(zwave.thermostatModeV2.thermostatModeSupportedGet().format()))
|
||||
initialize()
|
||||
}
|
||||
|
||||
def updated(){
|
||||
initialize()
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
// Device-Watch simply pings if no device events received for 32min(checkInterval)
|
||||
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
||||
unschedule()
|
||||
runEvery5Minutes("refresh")
|
||||
refresh()
|
||||
}
|
||||
|
||||
def parse(String description)
|
||||
@@ -149,6 +155,7 @@ def parse(String description)
|
||||
]
|
||||
if (map.name == "thermostatMode") {
|
||||
state.lastTriedMode = map.value
|
||||
map.data = [supportedThermostatModes:state.supportedThermostatModes]
|
||||
if (map.value == "cool") {
|
||||
map2.value = device.latestValue("coolingSetpoint")
|
||||
log.info "THERMOSTAT, latest cooling setpoint = ${map2.value}"
|
||||
@@ -172,6 +179,7 @@ def parse(String description)
|
||||
}
|
||||
} else if (map.name == "thermostatFanMode" && map.isStateChange) {
|
||||
state.lastTriedFanMode = map.value
|
||||
map.data = [supportedThermostatFanModes: state.supportedThermostatFanModes]
|
||||
}
|
||||
log.debug "Parse returned $result"
|
||||
result
|
||||
@@ -305,26 +313,26 @@ def zwaveEvent(physicalgraph.zwave.commands.thermostatfanmodev3.ThermostatFanMod
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.thermostatmodev2.ThermostatModeSupportedReport cmd) {
|
||||
def supportedModes = ""
|
||||
if(cmd.off) { supportedModes += "off " }
|
||||
if(cmd.heat) { supportedModes += "heat " }
|
||||
if(cmd.auxiliaryemergencyHeat) { supportedModes += "emergency heat " }
|
||||
if(cmd.cool) { supportedModes += "cool " }
|
||||
if(cmd.auto) { supportedModes += "auto " }
|
||||
def supportedModes = []
|
||||
if(cmd.off) { supportedModes << "off" }
|
||||
if(cmd.heat) { supportedModes << "heat" }
|
||||
if(cmd.cool) { supportedModes << "cool" }
|
||||
if(cmd.auto) { supportedModes << "auto" }
|
||||
if(cmd.auxiliaryemergencyHeat) { supportedModes << "emergency heat" }
|
||||
|
||||
state.supportedModes = supportedModes
|
||||
// No events to be generated, return empty map
|
||||
state.supportedThermostatModes = supportedModes
|
||||
sendEvent(name: "supportedThermostatModes", value: supportedModes, displayed: false)
|
||||
return [:]
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.thermostatfanmodev3.ThermostatFanModeSupportedReport cmd) {
|
||||
def supportedFanModes = ""
|
||||
if(cmd.auto) { supportedFanModes += "auto " } // "fanAuto "
|
||||
if(cmd.low) { supportedFanModes += "on " } // "fanOn"
|
||||
if(cmd.circulation) { supportedFanModes += "circulate " } // "fanCirculate"
|
||||
def supportedFanModes = []
|
||||
if(cmd.auto) { supportedFanModes << "auto" } // "fanAuto "
|
||||
if(cmd.circulation) { supportedFanModes << "circulate" } // "fanCirculate"
|
||||
if(cmd.low) { supportedFanModes << "on" } // "fanOn"
|
||||
|
||||
state.supportedFanModes = supportedFanModes
|
||||
// No events to be generated, return empty map
|
||||
state.supportedThermostatFanModes = supportedFanModes
|
||||
sendEvent(name: "supportedThermostatFanModes", value: supportedFanModes, displayed: false)
|
||||
return [:]
|
||||
}
|
||||
|
||||
@@ -337,15 +345,17 @@ def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
||||
}
|
||||
|
||||
// Command Implementations
|
||||
def poll() {
|
||||
delayBetween([
|
||||
zwave.sensorMultilevelV3.sensorMultilevelGet().format(), // current temperature
|
||||
zwave.thermostatSetpointV1.thermostatSetpointGet(setpointType: 1).format(),
|
||||
zwave.thermostatSetpointV1.thermostatSetpointGet(setpointType: 2).format(),
|
||||
zwave.thermostatModeV2.thermostatModeGet().format(),
|
||||
zwave.thermostatFanModeV3.thermostatFanModeGet().format(),
|
||||
zwave.thermostatOperatingStateV1.thermostatOperatingStateGet().format()
|
||||
], 2300)
|
||||
def refresh() {
|
||||
def cmds = []
|
||||
cmds << new physicalgraph.device.HubAction(zwave.thermostatModeV2.thermostatModeSupportedGet().format())
|
||||
cmds << new physicalgraph.device.HubAction(zwave.thermostatFanModeV3.thermostatFanModeSupportedGet().format())
|
||||
cmds << new physicalgraph.device.HubAction(zwave.thermostatModeV2.thermostatModeGet().format())
|
||||
cmds << new physicalgraph.device.HubAction(zwave.thermostatFanModeV3.thermostatFanModeGet().format())
|
||||
cmds << new physicalgraph.device.HubAction(zwave.sensorMultilevelV2.sensorMultilevelGet().format()) // current temperature
|
||||
cmds << new physicalgraph.device.HubAction(zwave.thermostatOperatingStateV1.thermostatOperatingStateGet().format())
|
||||
cmds << new physicalgraph.device.HubAction(zwave.thermostatSetpointV1.thermostatSetpointGet(setpointType: 1).format())
|
||||
cmds << new physicalgraph.device.HubAction(zwave.thermostatSetpointV1.thermostatSetpointGet(setpointType: 2).format())
|
||||
sendHubCommand(cmds)
|
||||
}
|
||||
|
||||
def quickSetHeat(degrees) {
|
||||
@@ -416,28 +426,14 @@ def ping() {
|
||||
poll()
|
||||
}
|
||||
|
||||
def configure() {
|
||||
delayBetween([
|
||||
zwave.thermostatModeV2.thermostatModeSupportedGet().format(),
|
||||
zwave.thermostatFanModeV3.thermostatFanModeSupportedGet().format(),
|
||||
zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:[zwaveHubNodeId]).format(),
|
||||
zwave.sensorMultilevelV3.sensorMultilevelGet().format(), // current temperature
|
||||
zwave.thermostatSetpointV1.thermostatSetpointGet(setpointType: 1).format(),
|
||||
zwave.thermostatSetpointV1.thermostatSetpointGet(setpointType: 2).format(),
|
||||
zwave.thermostatModeV2.thermostatModeGet().format(),
|
||||
zwave.thermostatFanModeV3.thermostatFanModeGet().format(),
|
||||
zwave.thermostatOperatingStateV1.thermostatOperatingStateGet().format()
|
||||
], 2300)
|
||||
}
|
||||
|
||||
def modes() {
|
||||
["off", "heat", "cool", "auto", "emergency heat"]
|
||||
return state.supportedThermostatModes
|
||||
}
|
||||
|
||||
def switchMode() {
|
||||
def currentMode = device.currentState("thermostatMode")?.value
|
||||
def lastTriedMode = state.lastTriedMode ?: currentMode ?: "off"
|
||||
def supportedModes = getDataByName("supportedModes")
|
||||
def lastTriedMode = state.lastTriedMode ?: currentMode ?: ["off"]
|
||||
def supportedModes = getDataByName("supportedThermostatModes")
|
||||
def modeOrder = modes()
|
||||
def next = { modeOrder[modeOrder.indexOf(it) + 1] ?: modeOrder[0] }
|
||||
def nextMode = next(lastTriedMode)
|
||||
@@ -454,7 +450,7 @@ def switchMode() {
|
||||
}
|
||||
|
||||
def switchToMode(nextMode) {
|
||||
def supportedModes = getDataByName("supportedModes")
|
||||
def supportedModes = getDataByName("supportedThermostatModes")
|
||||
if(supportedModes && !supportedModes.contains(nextMode)) log.warn "thermostat mode '$nextMode' is not supported"
|
||||
if (nextMode in modes()) {
|
||||
state.lastTriedMode = nextMode
|
||||
@@ -466,9 +462,9 @@ def switchToMode(nextMode) {
|
||||
|
||||
def switchFanMode() {
|
||||
def currentMode = device.currentState("thermostatFanMode")?.value
|
||||
def lastTriedMode = state.lastTriedFanMode ?: currentMode ?: "off"
|
||||
def supportedModes = getDataByName("supportedFanModes") ?: "auto on" // "fanAuto fanOn"
|
||||
def modeOrder = ["auto", "circulate", "on"] // "fanAuto", "fanCirculate", "fanOn"
|
||||
def lastTriedMode = state.lastTriedFanMode ?: currentMode ?: ["off"]
|
||||
def supportedModes = getDataByName("supportedThermostatFanModes") ?: ["auto", "on"]
|
||||
def modeOrder = state.supportedThermostatFanModes
|
||||
def next = { modeOrder[modeOrder.indexOf(it) + 1] ?: modeOrder[0] }
|
||||
def nextMode = next(lastTriedMode)
|
||||
while (!supportedModes?.contains(nextMode) && nextMode != "auto") { // "fanAuto"
|
||||
@@ -478,7 +474,7 @@ def switchFanMode() {
|
||||
}
|
||||
|
||||
def switchToFanMode(nextMode) {
|
||||
def supportedFanModes = getDataByName("supportedFanModes")
|
||||
def supportedFanModes = getDataByName("supportedThermostatFanModes")
|
||||
if(supportedFanModes && !supportedFanModes.contains(nextMode)) log.warn "thermostat mode '$nextMode' is not supported"
|
||||
|
||||
def returnCommand
|
||||
|
||||
@@ -58,6 +58,7 @@ metadata {
|
||||
def installed() {
|
||||
// Device-Watch simply pings if no device events received for 32min(checkInterval)
|
||||
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
||||
response(refresh())
|
||||
}
|
||||
|
||||
def updated() {
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
/**
|
||||
* Consumption Metering
|
||||
*
|
||||
* Copyright 2016 FortrezZ, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing permissions and limitations under the License.
|
||||
*
|
||||
*/
|
||||
definition(
|
||||
name: "Consumption Metering",
|
||||
namespace: "FortrezZ",
|
||||
author: "FortrezZ, LLC",
|
||||
description: "Child SmartApp for Consumption Metering rules",
|
||||
category: "Green Living",
|
||||
parent: "FortrezZ:FortrezZ Water Consumption Metering",
|
||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
|
||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
||||
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
|
||||
|
||||
preferences {
|
||||
page(name: "prefsPage", title: "Choose the detector behavior", install: true, uninstall: true)
|
||||
|
||||
// Do something here like update a message on the screen,
|
||||
// or introduce more inputs. submitOnChange will refresh
|
||||
// the page and allow the user to see the changes immediately.
|
||||
// For example, you could prompt for the level of the dimmers
|
||||
// if dimmers have been selected:
|
||||
//log.debug "Child Settings: ${settings}"
|
||||
}
|
||||
|
||||
def prefsPage() {
|
||||
def dailySchedule = 0
|
||||
def daysOfTheWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
|
||||
dynamicPage(name: "prefsPage") {
|
||||
section("Set Water Usage Goals") {
|
||||
input(name: "type", type: "enum", title: "Set a new goal?", submitOnChange: true, options: ruleTypes())
|
||||
}
|
||||
def measurementType = "water"
|
||||
if(type)
|
||||
{
|
||||
switch (type) {
|
||||
case "Daily Goal":
|
||||
section("Water Measurement Preference"){
|
||||
input(name: "measurementType", type: "enum", title: "Press to change water measurement options", submitOnChange: true, options: waterTypes())}
|
||||
|
||||
section("Threshold settings") {
|
||||
input(name: "waterGoal", type: "decimal", title: "Daily ${measurementType} Goal", required: true, defaultValue: 0.5)
|
||||
}
|
||||
|
||||
|
||||
break
|
||||
|
||||
case "Weekly Goal":
|
||||
section("Water Measurement Preference"){
|
||||
input(name: "measurementType", type: "enum", title: "Press to change water measurement options", submitOnChange: true, options: waterTypes())}
|
||||
section("Threshold settings") {
|
||||
input(name: "waterGoal", type: "decimal", title: "Weekly ${measurementType} Goal", required: true, defaultValue: 0.1)
|
||||
}
|
||||
|
||||
|
||||
break
|
||||
|
||||
case "Monthly Goal":
|
||||
section("Water Measurement Preference"){
|
||||
input(name: "measurementType", type: "enum", title: "Press to change water measurement options", submitOnChange: true, options: waterTypes())}
|
||||
section("Threshold settings") {
|
||||
input(name: "waterGoal", type: "decimal", title: "Monthly ${measurementType} Goal", required: true, defaultValue: 0.1)
|
||||
}
|
||||
|
||||
|
||||
break
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def ruleTypes() {
|
||||
def types = []
|
||||
types << "Daily Goal"
|
||||
types << "Weekly Goal"
|
||||
types << "Monthly Goal"
|
||||
|
||||
return types
|
||||
}
|
||||
|
||||
def waterTypes()
|
||||
{
|
||||
def watertype = []
|
||||
|
||||
watertype << "Gallons"
|
||||
watertype << "Cubic Feet"
|
||||
watertype << "Liters"
|
||||
watertype << "Cubic Meters"
|
||||
return watertype
|
||||
}
|
||||
/*
|
||||
def setDailyGoal(measurementType3)
|
||||
{
|
||||
return parent.setDailyGoal(measurementType3)
|
||||
}
|
||||
def setWeeklyGoal()
|
||||
{
|
||||
return parent.setWeeklyGoal(measurementType)
|
||||
}
|
||||
def setMonthlyGoal()
|
||||
{
|
||||
return parent.setMonthlyGoal(measurementType)
|
||||
}
|
||||
*/
|
||||
|
||||
def actionTypes() {
|
||||
def types = []
|
||||
types << [name: "Switch", capability: "capabilty.switch"]
|
||||
types << [name: "Water Valve", capability: "capability.valve"]
|
||||
|
||||
return types
|
||||
}
|
||||
|
||||
def deviceCommands(dev)
|
||||
{
|
||||
def cmds = []
|
||||
dev.supportedCommands.each { command ->
|
||||
cmds << command.name
|
||||
}
|
||||
|
||||
return cmds
|
||||
}
|
||||
|
||||
def installed() {
|
||||
state.Daily = 0
|
||||
log.debug "Installed with settings: ${settings}"
|
||||
app.updateLabel("${type} - ${waterGoal} ${measurementType}")
|
||||
//schedule(" 0 0/1 * 1/1 * ? *", setDailyGoal())
|
||||
initialize()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def updated() {
|
||||
log.debug "Updated with settings: ${settings}"
|
||||
app.updateLabel("${type} - ${waterGoal} ${measurementType}")
|
||||
|
||||
|
||||
unsubscribe()
|
||||
initialize()
|
||||
//unschedule()
|
||||
}
|
||||
|
||||
def settings() {
|
||||
def set = settings
|
||||
if (set["dev"] != null)
|
||||
{
|
||||
log.debug("dev set: ${set.dev}")
|
||||
set.dev = set.dev.id
|
||||
}
|
||||
if (set["valve"] != null)
|
||||
{
|
||||
log.debug("valve set: ${set.valve}")
|
||||
set.valve = set.valve.id
|
||||
}
|
||||
|
||||
log.debug(set)
|
||||
|
||||
return set
|
||||
}
|
||||
|
||||
def devAction(action)
|
||||
{
|
||||
if(dev)
|
||||
{
|
||||
log.debug("device: ${dev}, action: ${action}")
|
||||
dev."${action}"()
|
||||
}
|
||||
}
|
||||
|
||||
def isValveStatus(status)
|
||||
{
|
||||
def result = false
|
||||
log.debug("Water Valve ${valve} has status ${valve.currentState("contact").value}, compared to ${status.toLowerCase()}")
|
||||
if(valve)
|
||||
{
|
||||
if(valve.currentState("contact").value == status.toLowerCase())
|
||||
{
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
|
||||
|
||||
// TODO: subscribe to attributes, devices, locations, etc.
|
||||
}
|
||||
def uninstalled() {
|
||||
// external cleanup. No need to unsubscribe or remove scheduled jobs
|
||||
}
|
||||
// TODO: implement event handlers
|
||||
@@ -0,0 +1,388 @@
|
||||
/**
|
||||
* FortrezZ Water Consumption Metering
|
||||
*
|
||||
* Copyright 2016 FortrezZ, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing permissions and limitations under the License.
|
||||
*
|
||||
*/
|
||||
definition(
|
||||
name: "FortrezZ Water Consumption Metering",
|
||||
namespace: "FortrezZ",
|
||||
author: "FortrezZ, LLC",
|
||||
description: "Use the FortrezZ Water Meter to efficiently use your homes water system.",
|
||||
category: "Green Living",
|
||||
iconUrl: "http://swiftlet.technology/wp-content/uploads/2016/05/logo-square-200-1.png",
|
||||
iconX2Url: "http://swiftlet.technology/wp-content/uploads/2016/05/logo-square-500.png",
|
||||
iconX3Url: "http://swiftlet.technology/wp-content/uploads/2016/05/logo-square.png")
|
||||
|
||||
|
||||
preferences {
|
||||
page(name: "page2", title: "Select device and actions", install: true, uninstall: true)
|
||||
}
|
||||
|
||||
def page2() {
|
||||
dynamicPage(name: "page2") {
|
||||
section("Choose a water meter to monitor:") {
|
||||
input(name: "meter", type: "capability.energyMeter", title: "Water Meter", description: null, required: true, submitOnChange: true)
|
||||
}
|
||||
|
||||
if (meter) {
|
||||
section {
|
||||
app(name: "childRules", appName: "Consumption Metering", namespace: "FortrezZ", title: "Create New Water Consumption Goal", multiple: true)
|
||||
}
|
||||
}
|
||||
|
||||
section("Start/End time of all water usage goal periods") {
|
||||
input(name: "alertTime", type: "time", required: true)
|
||||
}
|
||||
|
||||
section("Billing info") {
|
||||
input(name: "unitType", type: "enum", title: "Water unit used in billing", description: null, defaultValue: "Gallons", required: true, submitOnChange: true, options: waterTypes())
|
||||
input(name: "costPerUnit", type: "decimal", title: "Cost of water unit in billing", description: null, defaultValue: 0, required: true, submitOnChange: true)
|
||||
input(name: "fixedFee", type: "decimal", title: "Add a Fixed Fee?", description: null, defaultValue: 0, submitOnChange: true)}
|
||||
|
||||
section("Send notifications through...") {
|
||||
input(name: "pushNotification", type: "bool", title: "SmartThings App", required: false)
|
||||
input(name: "smsNotification", type: "bool", title: "Text Message (SMS)", submitOnChange: true, required: false)
|
||||
if (smsNotification)
|
||||
{
|
||||
input(name: "phone", type: "phone", title: "Phone number?", required: true)
|
||||
}
|
||||
//input(name: "hoursBetweenNotifications", type: "number", title: "Hours between notifications", required: false)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
log.debug "there are ${childApps.size()} child smartapps"
|
||||
|
||||
|
||||
def childRules = []
|
||||
childApps.each {child ->
|
||||
log.debug "child ${child.id}: ${child.settings()}"
|
||||
childRules << [id: child.id, rules: child.settings()] //this section of code stores the long ID and settings (which contains several variables of the individual goal such as measurement type, water consumption goal, start cumulation, current cumulation.) into an array
|
||||
}
|
||||
|
||||
def match = false
|
||||
def changeOfSettings = false
|
||||
for (myItem in childRules) {
|
||||
def q = myItem.rules
|
||||
for (item2 in state.rules) {
|
||||
def r = item2.rules
|
||||
log.debug(r.alertType)
|
||||
if (myItem.id == item2.id) { //I am comparing the previous array to current array and checking to see if any new goals have been made.
|
||||
match = true
|
||||
if (q.type == r.type){
|
||||
changeOfSettings = true}
|
||||
}
|
||||
}
|
||||
if (match == false) { // if a new goal has been made, i need to do some first time things like set up a recurring schedule depending on goal duration
|
||||
state["NewApp${myItem.id}"] = true
|
||||
log.debug "Created a new ${q.type} with an ID of ${myItem.id}"}
|
||||
|
||||
match = false
|
||||
}
|
||||
|
||||
for (myItem in childRules) {
|
||||
if (state["NewApp${myItem.id}"] == true){
|
||||
state["NewApp${myItem.id}"] = false
|
||||
state["currentCumulation${myItem.id}"] = 0 // we create another object attached to our new goal called 'currentCumulation' which should hold the value for how much water has been used since the goal period has started
|
||||
state["oneHundred${myItem.id}"] = false
|
||||
state["ninety${myItem.id}"] = false
|
||||
state["seventyFive${myItem.id}"] = false
|
||||
state["fifty${myItem.id}"] = false
|
||||
state["endOfGoalPeriod${myItem.id}"] = false
|
||||
}
|
||||
}
|
||||
|
||||
state.rules = childRules // storing the array we just made to state makes it persistent across the instances this smart app is used and global across the app ( this value cannot be implicitely shared to any child app unfortunately without making it a local variable FYI
|
||||
log.debug "Parent Settings: ${settings}"
|
||||
|
||||
if (costPerUnit != 0 && costPerUnit != null){//we ask the user in the main page for billing info which includes the price of the water and what water measurement unit is used. we combine convert the unit to gallons (since that is what the FMI uses to tick water usage) and then create a ratio that can be converted to any water measurement type
|
||||
state.costRatio = costPerUnit/(convertToGallons(unitType))
|
||||
state.fixedFee = fixedFee
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def parseAlerTimeAndStartNewSchedule(myAlert)
|
||||
{
|
||||
def endTime = myAlert.split("T")
|
||||
def endHour = endTime[1].split(":")[0] // parsing the time stamp which is of this format: 2016-12-13T16:25:00.000-0500
|
||||
def endMinute = endTime[1].split(":")[1]
|
||||
schedule("0 ${endMinute} ${endHour} 1/1 * ? *", goalSearch) // creating a schedule to launch goalSearch every day at a user defined time - default is at midnight
|
||||
log.debug("new schedule created at ${endHour} : ${endMinute}")
|
||||
}
|
||||
|
||||
def convertToGallons(myUnit) // does what title says - takes whatever unit in string form and converts it to gallons to create a ratio. the result is returned
|
||||
{
|
||||
switch (myUnit){
|
||||
case "Gallons":
|
||||
return 1
|
||||
break
|
||||
case "Cubic Feet":
|
||||
return 7.48052
|
||||
break
|
||||
case "Liters":
|
||||
return 0.264172
|
||||
break
|
||||
case "Cubic Meters":
|
||||
return 264.172
|
||||
break
|
||||
default:
|
||||
log.debug "value for water measurement doesn't fit into the 4 water measurement categories"
|
||||
return 1
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def goalSearch(){
|
||||
|
||||
def dateTime = new Date() // this section is where we get date in time within our timezone and split it into 2 arrays which carry the date and time
|
||||
def fullDateTime = dateTime.format("yyyy-MM-dd HH:mm:ss", location.timeZone)
|
||||
def mySplit = fullDateTime.split()
|
||||
|
||||
log.debug("goalSearch: ${fullDateTime}") // 2016-12-09 14:59:56
|
||||
|
||||
// ok, so I ran into a problem here. I wanted to simply do | state.dateSplit = mySplit[0].split("-") | but I kept getting this error in the log "java.lang.UnsupportedOperationException" So I split it to variables and then individually placed them into the state array
|
||||
def dateSplit = mySplit[0].split("-")
|
||||
def timeSplit = mySplit[1].split(":")
|
||||
state.dateSplit = []
|
||||
state.timeSplit = []
|
||||
for (i in dateSplit){
|
||||
state.dateSplit << i} // unnecessary?
|
||||
for (g in timeSplit){
|
||||
state.timeSplit << g}
|
||||
def dayOfWeek = Date.parse("yyyy-MM-dd", mySplit[0]).format("EEEE")
|
||||
state.debug = false
|
||||
dailyGoalSearch(dateSplit, timeSplit)
|
||||
weeklyGoalSearch(dateSplit, timeSplit, dayOfWeek)
|
||||
monthlyGoalSearch(dateSplit, timeSplit)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
def dailyGoalSearch(dateSplit, timeSplit){ // because of our limitations of schedule() we had to create 3 separate methods for the existing goal period of day, month, and year. they are identical other than their time periods.
|
||||
def myRules = state.rules // also, these methods are called when our goal period ends. we filter out the goals that we want and then invoke a separate method called schedulGoal to inform the user that the goal ended and produce some results based on their water usage.
|
||||
for (it in myRules){
|
||||
def r = it.rules
|
||||
if (r.type == "Daily Goal") {
|
||||
scheduleGoal(r.measurementType, it.id, r.waterGoal, r.type, 0.03333)
|
||||
}
|
||||
}
|
||||
}
|
||||
def weeklyGoalSearch(dateSplit, timeSplit, dayOfWeek){
|
||||
def myRules = state.rules // also, these methods are called when our goal period ends. we filter out the goals that we want and then invoke a separate method called schedulGoal to inform the user that the goal ended and produce some results based on their water usage.
|
||||
for (it in myRules){
|
||||
def r = it.rules
|
||||
if (r.type == "Weekly Goal") {
|
||||
if (dayOfWeek == "Sunday" || state.debug == true){
|
||||
scheduleGoal(r.measurementType, it.id, r.waterGoal, r.type, 0.23333)}
|
||||
}
|
||||
}
|
||||
}
|
||||
def monthlyGoalSearch(dateSplit, timeSplit){
|
||||
def myRules = state.rules // also, these methods are called when our goal period ends. we filter out the goals that we want and then invoke a separate method called schedulGoal to inform the user that the goal ended and produce some results based on their water usage.
|
||||
for (it in myRules){
|
||||
def r = it.rules
|
||||
if (r.type == "Monthly Goal") {
|
||||
if (dateSplit[2] == "01" || state.debug == true){
|
||||
scheduleGoal(r.measurementType, it.id, r.waterGoal, r.type, 0.23333)}
|
||||
}
|
||||
}
|
||||
}
|
||||
def scheduleGoal(measureType, goalID, wGoal, goalType, fixedFeeRatio){ // this is where the magic happens. after a goal period has finished this method is invoked and the user gets a notification of the results of the water usage over their period.
|
||||
def cost = 0
|
||||
def f = 1.0f
|
||||
def topCumulative = meter.latestValue("cumulative") // pulling the current cumulative value from the FMI for calculating how much water we have used since starting the goal.
|
||||
if (state["Start${goalID}"] == null){state["Start${goalID}"] = topCumulative} // we create another object attached to our goal called 'start' and store the existing cumulation on the FMI device so we know at what mileage we are starting at for this goal. this is useful for determining how much water is used during the goal period.
|
||||
def curCumulation = waterConversionPreference(topCumulative, measureType) - waterConversionPreference(state["Start${goalID}"], measureType)
|
||||
|
||||
|
||||
if (state.costRatio){
|
||||
cost = costConversionPreference(state.costRatio,measureType) * curCumulation * f + (state.fixedFee * fixedFeeRatio)// determining the cost of the water that they have used over the period ( i had to create a variable 'f' and make it a float and multiply it to make the result a float. this is because the method .round() requires it to be a float for some reasons and it was easier than typecasting the result to a float.
|
||||
}
|
||||
def percentage = (curCumulation / wGoal) * 100 * f
|
||||
if (costPerUnit != 0) {
|
||||
notify("Your ${goalType} period has ended. You have used ${(curCumulation * f).round(2)} ${measureType} of your goal of ${wGoal} ${measureType} (${(percentage * f).round(1)}%). Costing \$${cost.round(2)}")// notifies user of the type of goal that finished, the amount of water they used versus the goal of water they used, and the cost of the water used
|
||||
log.debug "Your ${goalType} period has ended. You have used ${(curCumulation * f).round(2)} ${measureType} of your goal of ${wGoal} ${measureType} (${(percentage * f).round(1)}%). Costing \$${cost.round(2)}"
|
||||
|
||||
}
|
||||
if (costPerUnit == 0) // just in case the user didn't add any billing info, i created a second set of notification code to not include any billing info.
|
||||
{
|
||||
notify("Your ${goalType} period has ended. You have you have used ${(curCumulation * f).round(2)} ${measureType} of your goal of ${wGoal} ${measureType} (${percentage.round(1)}%).")
|
||||
log.debug "Your ${goalType} period has ended. You have you have used ${(curCumulation * f).round(2)} ${measureType} of your goal of ${wGoal} ${measureType} (${percentage.round(1)}%)."
|
||||
}
|
||||
state["Start${goalID}"] = topCumulative;
|
||||
state["oneHundred${goalID}"] = false
|
||||
state["ninety${goalID}"] = false
|
||||
state["seventyFive${goalID}"] = false
|
||||
state["fifty${goalID}"] = false
|
||||
state["endOfGoalPeriod${goalID}"] = true // telling the app that the goal period is over.
|
||||
}
|
||||
|
||||
|
||||
|
||||
def waterTypes() // holds the types of water measurement used in the main smartapp page for billing info and for setting goals
|
||||
{
|
||||
def watertype = []
|
||||
|
||||
watertype << "Gallons"
|
||||
watertype << "Cubic Feet"
|
||||
watertype << "Liters"
|
||||
watertype << "Cubic Meters"
|
||||
return watertype
|
||||
}
|
||||
|
||||
def installed() { // when the app is first installed - do something
|
||||
log.debug "Installed with settings: ${settings}"
|
||||
|
||||
initialize()
|
||||
}
|
||||
|
||||
def updated() { // whevenever the app is updated in any way by the user and you press the 'done' button on the top right of the app - do something
|
||||
log.debug "Updated with settings: ${settings}"
|
||||
|
||||
if (alertTime != state.alertTime) // we created this 'if' statement to prevent another schedule being made whenever the user opens the smartapp
|
||||
{
|
||||
unschedule() //unscheduling is a good idea here because we don't want multiple schedules happening and this function cancles all schedules
|
||||
parseAlerTimeAndStartNewSchedule(alertTime) // we use cron scheduling to use the function 'goalSearch' every minute
|
||||
state.alarmTime = alarmTime // setting state.alarmTime prevents a new schedule being made whenever the user opens the smartapp
|
||||
}
|
||||
|
||||
unsubscribe()
|
||||
initialize()
|
||||
//unschedule()
|
||||
}
|
||||
|
||||
def initialize() { // whenever you open the smart app - do something
|
||||
subscribe(meter, "cumulative", cumulativeHandler)
|
||||
//subscribe(meter, "gpm", gpmHandler)
|
||||
log.debug("Subscribing to events")
|
||||
}
|
||||
|
||||
def cumulativeHandler(evt) { // every time a tick on the FMI happens this method is called. 'evt' contains the cumulative value of every tick that has happened on the FMI since it was last reset. each tick represents 1/10 of a gallon
|
||||
def f = 1.0f
|
||||
def gpm = meter.latestValue("gpm") // storing the current gallons per minute value
|
||||
def cumulative = new BigDecimal(evt.value) // storing the current cumulation value
|
||||
log.debug "Cumulative Handler: [gpm: ${gpm}, cumulative: ${cumulative}]"
|
||||
def rules = state.rules //storing the array of child apps to 'rules'
|
||||
rules.each { it -> // looping through each app in the array but storing each app into the variable 'it'
|
||||
def r = it.rules // each child app has a 2 immediate properties, one called 'id' and one called 'rules' - so 'r' contains the values of 'rules' in the child app
|
||||
def childAppID = it.id // storing the child app ID to a variable
|
||||
if (state["Start${childAppID}"] == null) {state["Start${childAppID}"] = cumulative}// just for the first run of the app... start should be null. so we have to change that for the logic to work.
|
||||
|
||||
|
||||
def newCumulative = waterConversionPreference(cumulative, r.measurementType) //each goal allows the user to choose a water measurement type. here we convert the value of 'cumulative' to whatever the user prefers for display and logic purposes
|
||||
def goalStartCumulative = waterConversionPreference(state["Start${childAppID}"], r.measurementType)
|
||||
|
||||
|
||||
def DailyGallonGoal = r.waterGoal // 'r.waterGoal' contains the number of units of water the user set as a goal. we then save that to 'DailyGallonGoal'
|
||||
state.DailyGallonGoal = DailyGallonGoal // and then we make that value global and persistent for logic reasons
|
||||
def currentCumulation = newCumulative - goalStartCumulative // earlier we created the value 'currentCumulation' and set it to 0, now we are converting both the 'cumulative' value and what 'cumulative' was when the goal perio was made and subtracting them to discover how much water has been used since the creation of the goal in the users prefered water measurement unit.
|
||||
state["currentCumulation${childAppID}"] = currentCumulation
|
||||
log.debug("Threshold:${DailyGallonGoal}, Value:${(currentCumulation * f).round(2)}")
|
||||
|
||||
if ( currentCumulation >= (0.5 * DailyGallonGoal) && currentCumulation < (0.75 * DailyGallonGoal) && state["fifty${childAppID}"] == false) // tell the user if they break certain use thresholds
|
||||
{
|
||||
notify("You have reached 50% of your ${r.type} use limit. (${(currentCumulation * f).round(2)} of ${DailyGallonGoal} ${r.measurementType})")
|
||||
log.debug "You have reached 50% of your ${r.type} use limit. (${(currentCumulation * f).round(2)} of ${DailyGallonGoal} ${r.measurementType})"
|
||||
state["fifty${childAppID}"] = true
|
||||
}
|
||||
if ( currentCumulation >= (0.75 * DailyGallonGoal) && currentCumulation < (0.9 * DailyGallonGoal) && state["seventyFive${childAppID}"] == false)
|
||||
{
|
||||
notify("You have reached 75% of your ${r.type} use limit. (${(currentCumulation * f).round(2)} of ${DailyGallonGoal} ${r.measurementType})")
|
||||
log.debug "You have reached 75% of your ${r.type} use limit. (${(currentCumulation * f).round(2)} of ${DailyGallonGoal} ${r.measurementType})"
|
||||
state["seventyFive${childAppID}"] = true
|
||||
}
|
||||
if ( currentCumulation >= (0.9 * DailyGallonGoal) && currentCumulation < (DailyGallonGoal) && state["ninety${childAppID}"] == false)
|
||||
{
|
||||
notify("You have reached 90% of your ${r.type} use limit. (${(currentCumulation * f).round(2)} of ${DailyGallonGoal} ${r.measurementType})")
|
||||
log.debug "You have reached 90% of your ${r.type} use limit. (${(currentCumulation * f).round(2)} of ${DailyGallonGoal} ${r.measurementType})"
|
||||
state["ninety${childAppID}"] = true
|
||||
}
|
||||
if (currentCumulation >= DailyGallonGoal && state["oneHundred${childAppID}"] == false)
|
||||
{
|
||||
notify("You have reached 100% of your ${r.type} use limit. (${(currentCumulation * f).round(2)} of ${DailyGallonGoal} ${r.measurementType})")
|
||||
log.debug "You have reached 100% of your ${r.type} use limit. (${(currentCumulation * f).round(2)} of ${DailyGallonGoal} ${r.measurementType})"
|
||||
state["oneHundred${childAppID}"] = true
|
||||
//send command here like shut off the water
|
||||
|
||||
|
||||
|
||||
}
|
||||
if (state["endOfGoalPeriod${childAppID}"] == true) // changing the start value to the most recent cumulative value for goal reset.
|
||||
{state["Start${childAppID}"] = cumulative
|
||||
state["endOfGoalPeriod${childAppID}"] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def waterConversionPreference(cumul, measurementType1) // convert the current cumulation to one of the four options below - since cumulative is initially in gallons, then the options to change them is easy
|
||||
{
|
||||
switch (measurementType1)
|
||||
{
|
||||
case "Cubic Feet":
|
||||
return (cumul * 0.133681)
|
||||
break
|
||||
|
||||
case "Liters":
|
||||
return (cumul * 3.78541)
|
||||
break
|
||||
|
||||
case "Cubic Meters":
|
||||
return (cumul * 0.00378541)
|
||||
break
|
||||
|
||||
case "Gallons":
|
||||
return cumul
|
||||
break
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
def costConversionPreference(cumul, measurementType1) // convert the current cumulation to one of the four options below - since cumulative is initially in gallons, then the options to change them is easy
|
||||
{
|
||||
switch (measurementType1)
|
||||
{
|
||||
case "Cubic Feet":
|
||||
return (cumul / 0.133681)
|
||||
break
|
||||
|
||||
case "Liters":
|
||||
return (cumul / 3.78541)
|
||||
break
|
||||
|
||||
case "Cubic Meters":
|
||||
return (cumul / 0.00378541)
|
||||
break
|
||||
|
||||
case "Gallons":
|
||||
return cumul
|
||||
break
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
def notify(myMsg) // method for both push notifications and for text messaging.
|
||||
{
|
||||
log.debug("Sending Notification")
|
||||
if (pushNotification) {sendPush(myMsg)} else {sendNotificationEvent(myMsg)}
|
||||
if (smsNotification) {sendSms(phone, myMsg)}
|
||||
}
|
||||
|
||||
def uninstalled() {
|
||||
// external cleanup. No need to unsubscribe or remove scheduled jobs
|
||||
unsubscribe()
|
||||
unschedule()
|
||||
}
|
||||
@@ -27,10 +27,9 @@ definition(
|
||||
|
||||
preferences {
|
||||
page(name: "selectButton")
|
||||
page(name: "configureButton1")
|
||||
page(name: "configureButton2")
|
||||
page(name: "configureButton3")
|
||||
page(name: "configureButton4")
|
||||
for (def i=1; i<=8; i++) {
|
||||
page(name: "configureButton$i")
|
||||
}
|
||||
|
||||
page(name: "timeIntervalInput", title: "Only during a certain time") {
|
||||
section {
|
||||
@@ -60,22 +59,45 @@ def selectButton() {
|
||||
}
|
||||
}
|
||||
|
||||
def createPage(pageNum) {
|
||||
if ((state.numButton == pageNum) || (pageNum == 8))
|
||||
state.installCondition = true
|
||||
dynamicPage(name: "configureButton$pageNum", title: "Set up button $pageNum here",
|
||||
nextPage: "configureButton${pageNum+1}", install: state.installCondition, uninstall: configured(), getButtonSections(pageNum))
|
||||
}
|
||||
|
||||
def configureButton1() {
|
||||
dynamicPage(name: "configureButton1", title: "Now let's decide how to use the first button",
|
||||
nextPage: "configureButton2", uninstall: configured(), getButtonSections(1))
|
||||
state.numButton = buttonDevice.currentState("numberOfButtons")?.longValue ?: 4
|
||||
log.debug "state variable numButton: ${state.numButton}"
|
||||
state.installCondition = false
|
||||
createPage(1)
|
||||
}
|
||||
def configureButton2() {
|
||||
dynamicPage(name: "configureButton2", title: "If you have a second button, set it up here",
|
||||
nextPage: "configureButton3", uninstall: configured(), getButtonSections(2))
|
||||
createPage(2)
|
||||
}
|
||||
|
||||
def configureButton3() {
|
||||
dynamicPage(name: "configureButton3", title: "If you have a third button, you can do even more here",
|
||||
nextPage: "configureButton4", uninstall: configured(), getButtonSections(3))
|
||||
createPage(3)
|
||||
}
|
||||
|
||||
def configureButton4() {
|
||||
dynamicPage(name: "configureButton4", title: "If you have a fourth button, you rule, and can set it up here",
|
||||
install: true, uninstall: true, getButtonSections(4))
|
||||
createPage(4)
|
||||
}
|
||||
|
||||
def configureButton5() {
|
||||
createPage(5)
|
||||
}
|
||||
|
||||
def configureButton6() {
|
||||
createPage(6)
|
||||
}
|
||||
|
||||
def configureButton7() {
|
||||
createPage(7)
|
||||
}
|
||||
|
||||
def configureButton8() {
|
||||
createPage(8)
|
||||
}
|
||||
|
||||
def getButtonSections(buttonNumber) {
|
||||
|
||||
@@ -202,7 +202,8 @@ def inputSelectionPage() {
|
||||
|
||||
section("options variations") {
|
||||
paragraph "tap these elements and look at the differences when selecting an option"
|
||||
input(type: "enum", name: "selectionSimple", title: "Simple options", description: "no separators in the selectable options", groupedOptions: addGroup(englishOptions + spanishOptions))
|
||||
input(type: "enum", name: "selectionSimple", title: "Simple options", description: "no separators in the selectable options", options: ["Thing 1", "Thing 2", "(Complicated) Thing 3"])
|
||||
input(type: "enum", name: "selectionSimpleGrouped", title: "Simple (Grouped) options", description: "no separators in the selectable options", groupedOptions: addGroup(englishOptions + spanishOptions))
|
||||
input(type: "enum", name: "selectionGrouped", title: "Grouped options", description: "separate groups of options with headers", groupedOptions: groupedOptions)
|
||||
}
|
||||
|
||||
@@ -214,15 +215,15 @@ def inputSelectionPage() {
|
||||
|
||||
section("segmented") {
|
||||
paragraph "segmented should only work if there are either 2 or 3 options to choose from"
|
||||
input(type: "enum", name: "selectionSegmented1", style: "segmented", title: "1 option", groupedOptions: addGroup(["One"]))
|
||||
input(type: "enum", name: "selectionSegmented4", style: "segmented", title: "4 options", groupedOptions: addGroup(["One", "Two", "Three", "Four"]))
|
||||
input(type: "enum", name: "selectionSegmented1", style: "segmented", title: "1 option", options: ["One"])
|
||||
input(type: "enum", name: "selectionSegmented4", style: "segmented", title: "4 options", options: ["One", "Two", "Three", "Four"])
|
||||
|
||||
paragraph "multiple and required will have no effect on segmented selection elements. There will always be exactly 1 option selected"
|
||||
input(type: "enum", name: "selectionSegmented2", style: "segmented", title: "2 options", options: ["One", "Two"])
|
||||
input(type: "enum", name: "selectionSegmented3", style: "segmented", title: "3 options", options: ["One", "Two", "Three"])
|
||||
|
||||
paragraph "specifying defaultValue still works with segmented selection elements"
|
||||
input(type: "enum", name: "selectionSegmentedWithDefault", title: "defaulted to 'two'", groupedOptions: addGroup(["One", "Two", "Three"]), defaultValue: "Two")
|
||||
input(type: "enum", name: "selectionSegmentedWithDefault", style: "segmented", title: "defaulted to 'two'", options: ["One", "Two", "Three"], defaultValue: "Two")
|
||||
}
|
||||
|
||||
section("required: true") {
|
||||
@@ -231,6 +232,8 @@ def inputSelectionPage() {
|
||||
|
||||
section("multiple: true") {
|
||||
input(type: "enum", name: "selectionMultiple", title: "This allows multiple selections", description: "It should look different when nothing is selected", groupedOptions: addGroup(["an option", "another option", "no way, one more?"]), multiple: true)
|
||||
input(type: "enum", name: "selectionMultipleDefault1", title: "This allows multiple selections with a single default", description: "It should look different when nothing is selected", groupedOptions: addGroup(["an option", "another option", "no way, one more?"]), multiple: true, defaultValue: "an option")
|
||||
input(type: "enum", name: "selectionMultipleDefault2", title: "This allows multiple selections with multiple defaults", description: "It should look different when nothing is selected", groupedOptions: addGroup(["an option", "another option", "no way, one more?"]), multiple: true, defaultValue: ["an option", "another option"])
|
||||
}
|
||||
|
||||
section("with image") {
|
||||
|
||||
@@ -72,7 +72,7 @@ def authPage() {
|
||||
log.debug "have LIFX access token"
|
||||
|
||||
def options = locationOptions() ?: []
|
||||
def count = options.size()
|
||||
def count = options.size().toString()
|
||||
|
||||
return dynamicPage(name:"Credentials", title:"", nextPage:"", install:true, uninstall: true) {
|
||||
section("Select your location") {
|
||||
|
||||
Reference in New Issue
Block a user