Update thermostat.groovy
[smartapps.git] / third-party / influxdb-logger.groovy
index 3cba6e31e2b15650727af527747bec9f3b50c66e..e00fd7d841de2d8ca82f092e091a9e454315fffa 100755 (executable)
@@ -86,9 +86,9 @@ preferences {
         input "beacons", "capability.beacon", title: "Beacons", multiple: true, required: false
         input "buttons", "capability.button", title: "Buttons", multiple: true, required: false
         input "cos", "capability.carbonMonoxideDetector", title: "Carbon Monoxide Detectors", multiple: true, required: false
-        input "co2s", "capability.carbonDioxideMeasurement", title: "Carbon Dioxide Detectors", multiple: true, required: false
+        input "co2s", "capability.carbonDioxideMeasurement", title: "Carbon Dioxide Detectors", multiple: true, required: false//1
         input "colors", "capability.colorControl", title: "Color Controllers", multiple: true, required: false
-        input "consumables", "capability.consumable", title: "Consumables", multiple: true, required: false
+        input "consumables", "capability.consumable", title: "Consumables", multiple: true, required: false//2
         input "contacts", "capability.contactSensor", title: "Contact Sensors", multiple: true, required: false
         input "doorsControllers", "capability.doorControl", title: "Door Controllers", multiple: true, required: false
         input "energyMeters", "capability.energyMeter", title: "Energy Meters", multiple: true, required: false
@@ -98,28 +98,28 @@ preferences {
         input "motions", "capability.motionSensor", title: "Motion Sensors", multiple: true, required: false
         input "musicPlayers", "capability.musicPlayer", title: "Music Players", multiple: true, required: false
         input "peds", "capability.stepSensor", title: "Pedometers", multiple: true, required: false
-        input "phMeters", "capability.pHMeasurement", title: "pH Meters", multiple: true, required: false
+        input "phMeters", "capability.pHMeasurement", title: "pH Meters", multiple: true, required: false//3
         input "powerMeters", "capability.powerMeter", title: "Power Meters", multiple: true, required: false
         input "presences", "capability.presenceSensor", title: "Presence Sensors", multiple: true, required: false
         input "pressures", "capability.sensor", title: "Pressure Sensors", multiple: true, required: false
-        input "shockSensors", "capability.shockSensor", title: "Shock Sensors", multiple: true, required: false
-        input "signalStrengthMeters", "capability.signalStrength", title: "Signal Strength Meters", multiple: true, required: false
+        input "shockSensors", "capability.shockSensor", title: "Shock Sensors", multiple: true, required: false//4
+        input "signalStrengthMeters", "capability.signalStrength", title: "Signal Strength Meters", multiple: true, required: false//5
         input "sleepSensors", "capability.sleepSensor", title: "Sleep Sensors", multiple: true, required: false
         input "smokeDetectors", "capability.smokeDetector", title: "Smoke Detectors", multiple: true, required: false
-        input "soundSensors", "capability.soundSensor", title: "Sound Sensors", multiple: true, required: false
-               input "spls", "capability.soundPressureLevel", title: "Sound Pressure Level Sensors", multiple: true, required: false
-               input "switches", "capability.switch", title: "Switches", multiple: true, required: false
+        input "soundSensors", "capability.soundSensor", title: "Sound Sensors", multiple: true, required: false//6
+       input "spls", "capability.soundPressureLevel", title: "Sound Pressure Level Sensors", multiple: true, required: false//7
+       input "switches", "capability.switch", title: "Switches", multiple: true, required: false
         input "switchLevels", "capability.switchLevel", title: "Switch Levels", multiple: true, required: false
-        input "tamperAlerts", "capability.tamperAlert", title: "Tamper Alerts", multiple: true, required: false
+        input "tamperAlerts", "capability.tamperAlert", title: "Tamper Alerts", multiple: true, required: false//8
         input "temperatures", "capability.temperatureMeasurement", title: "Temperature Sensors", multiple: true, required: false
         input "thermostats", "capability.thermostat", title: "Thermostats", multiple: true, required: false
         input "threeAxis", "capability.threeAxis", title: "Three-axis (Orientation) Sensors", multiple: true, required: false
         input "touchs", "capability.touchSensor", title: "Touch Sensors", multiple: true, required: false
-        input "uvs", "capability.ultravioletIndex", title: "UV Sensors", multiple: true, required: false
+        input "uvs", "capability.ultravioletIndex", title: "UV Sensors", multiple: true, required: false//9
         input "valves", "capability.valve", title: "Valves", multiple: true, required: false
-        input "volts", "capability.voltageMeasurement", title: "Voltage Meters", multiple: true, required: false
+        input "volts", "capability.voltageMeasurement", title: "Voltage Meters", multiple: true, required: false//10
         input "waterSensors", "capability.waterSensor", title: "Water Sensors", multiple: true, required: false
-        input "windowShades", "capability.windowShade", title: "Window Shades", multiple: true, required: false
+        input "windowShades", "capability.windowShade", title: "Window Shades", multiple: true, required: false//11
     }
 
 }
@@ -190,9 +190,9 @@ def updated() {
     state.deviceAttributes << [ devices: 'beacons', attributes: ['presence']]
     state.deviceAttributes << [ devices: 'buttons', attributes: ['button']]
     state.deviceAttributes << [ devices: 'cos', attributes: ['carbonMonoxide']]
-    state.deviceAttributes << [ devices: 'co2s', attributes: ['carbonDioxide']]
+    state.deviceAttributes << [ devices: 'co2s', attributes: ['carbonDioxide']]///
     state.deviceAttributes << [ devices: 'colors', attributes: ['hue','saturation','color']]
-    state.deviceAttributes << [ devices: 'consumables', attributes: ['consumableStatus']]
+    state.deviceAttributes << [ devices: 'consumables', attributes: ['consumableStatus']]///
     state.deviceAttributes << [ devices: 'contacts', attributes: ['contact']]
     state.deviceAttributes << [ devices: 'doorsControllers', attributes: ['door']]
     state.deviceAttributes << [ devices: 'energyMeters', attributes: ['energy']]
@@ -202,28 +202,28 @@ def updated() {
     state.deviceAttributes << [ devices: 'motions', attributes: ['motion']]
     state.deviceAttributes << [ devices: 'musicPlayers', attributes: ['status','level','trackDescription','trackData','mute']]
     state.deviceAttributes << [ devices: 'peds', attributes: ['steps','goal']]
-    state.deviceAttributes << [ devices: 'phMeters', attributes: ['pH']]
-    state.deviceAttributes << [ devices: 'powerMeters', attributes: ['power','voltage','current','powerFactor']]
+    state.deviceAttributes << [ devices: 'phMeters', attributes: ['pH']]///
+    state.deviceAttributes << [ devices: 'powerMeters', attributes: ['power']]
     state.deviceAttributes << [ devices: 'presences', attributes: ['presence']]
-    state.deviceAttributes << [ devices: 'pressures', attributes: ['pressure']]
-    state.deviceAttributes << [ devices: 'shockSensors', attributes: ['shock']]
-    state.deviceAttributes << [ devices: 'signalStrengthMeters', attributes: ['lqi','rssi']]
+    state.deviceAttributes << [ devices: 'pressures', attributes: ['pressure']]///
+    state.deviceAttributes << [ devices: 'shockSensors', attributes: ['shock']]///
+    state.deviceAttributes << [ devices: 'signalStrengthMeters', attributes: ['lqi','rssi']]///
     state.deviceAttributes << [ devices: 'sleepSensors', attributes: ['sleeping']]
     state.deviceAttributes << [ devices: 'smokeDetectors', attributes: ['smoke']]
-    state.deviceAttributes << [ devices: 'soundSensors', attributes: ['sound']]
-       state.deviceAttributes << [ devices: 'spls', attributes: ['soundPressureLevel']]
+    state.deviceAttributes << [ devices: 'soundSensors', attributes: ['sound']]///
+       state.deviceAttributes << [ devices: 'spls', attributes: ['soundPressureLevel']]///
        state.deviceAttributes << [ devices: 'switches', attributes: ['switch']]
     state.deviceAttributes << [ devices: 'switchLevels', attributes: ['level']]
-    state.deviceAttributes << [ devices: 'tamperAlerts', attributes: ['tamper']]
+    state.deviceAttributes << [ devices: 'tamperAlerts', attributes: ['tamper']]///
     state.deviceAttributes << [ devices: 'temperatures', attributes: ['temperature']]
-    state.deviceAttributes << [ devices: 'thermostats', attributes: ['temperature','heatingSetpoint','coolingSetpoint','thermostatSetpoint','thermostatMode','thermostatFanMode','thermostatOperatingState','thermostatSetpointMode','scheduledSetpoint','optimisation','windowFunction']]
+    state.deviceAttributes << [ devices: 'thermostats', attributes: ['temperature','heatingSetpoint','coolingSetpoint','thermostatSetpoint','thermostatMode','thermostatFanMode','thermostatOperatingState']]
     state.deviceAttributes << [ devices: 'threeAxis', attributes: ['threeAxis']]
     state.deviceAttributes << [ devices: 'touchs', attributes: ['touch']]
-    state.deviceAttributes << [ devices: 'uvs', attributes: ['ultravioletIndex']]
+    state.deviceAttributes << [ devices: 'uvs', attributes: ['ultravioletIndex']]///
     state.deviceAttributes << [ devices: 'valves', attributes: ['contact']]
-    state.deviceAttributes << [ devices: 'volts', attributes: ['voltage']]
+    state.deviceAttributes << [ devices: 'volts', attributes: ['voltage']]///
     state.deviceAttributes << [ devices: 'waterSensors', attributes: ['water']]
-    state.deviceAttributes << [ devices: 'windowShades', attributes: ['windowShade']]
+    state.deviceAttributes << [ devices: 'windowShades', attributes: ['windowShade']]///
 
     // Configure Scheduling:
     state.softPollingInterval = settings.prefSoftPollingInterval.toInteger()
@@ -598,7 +598,7 @@ def logSystemProperties() {
 def postToInfluxDB(data) {
     logger("postToInfluxDB(): Posting data to InfluxDB: Host: ${state.databaseHost}, Port: ${state.databasePort}, Database: ${state.databaseName}, Data: [${data}]","debug")
     
-    try {
+   /* try {
         def hubAction = new physicalgraph.device.HubAction(
                [
                 method: "POST",
@@ -614,7 +614,7 @@ def postToInfluxDB(data) {
     }
     catch (Exception e) {
                logger("postToInfluxDB(): Exception ${e} on ${hubAction}","error")
-    }
+    }*/
 
     // For reference, code that could be used for WAN hosts:
     // def url = "http://${state.databaseHost}:${state.databasePort}/write?db=${state.databaseName}" 
@@ -636,11 +636,11 @@ def postToInfluxDB(data) {
  *
  *  Handles response from post made in postToInfluxDB().
  **/
-def handleInfluxResponse(physicalgraph.device.HubResponse hubResponse) {
+/*def handleInfluxResponse(physicalgraph.device.HubResponse hubResponse) {
     if(hubResponse.status >= 400) {
                logger("postToInfluxDB(): Something went wrong! Response from InfluxDB: Headers: ${hubResponse.headers}, Body: ${hubResponse.body}","error")
     }
-}
+}*/
 
 
 /*****************************************************************************************************************
@@ -693,18 +693,60 @@ private manageSubscriptions() {
     // Subscribe to mode events:
     if (prefLogModeEvents) subscribe(location, "mode", handleModeEvent)
     
-    // Subscribe to device attributes (iterate over each attribute for each device collection in state.deviceAttributes):
-    def devs // dynamic variable holding device collection.
-    state.deviceAttributes.each { da ->
-        devs = settings."${da.devices}"
-        if (devs && (da.attributes)) {
-            da.attributes.each { attr ->
-                logger("manageSubscriptions(): Subscribing to attribute: ${attr}, for devices: ${da.devices}","info")
-                // There is no need to check if all devices in the collection have the attribute.
-                subscribe(devs, attr, handleEvent)
-            }
-        }
-    }
+    subscribe(accelerometers, "acceleration", handleEvent)
+    subscribe(alarms, "alarm", handleEvent)
+    subscribe(batteries, "battery", handleEvent)
+    subscribe(beacons, "presence", handleEvent)
+    subscribe(buttons, "button", handleEvent)
+    subscribe(cos, "carbonMonoxide", handleEvent)
+    subscribe(co2s, "carbonDioxide", handleEvent)
+    subscribe(colors, "hue", handleEvent)
+    subscribe(colors, "saturation", handleEvent)
+    subscribe(colors, "color", handleEvent)
+    subscribe(consumables, "consumableStatus", handleEvent)
+    subscribe(contacts, "contact", handleEvent)
+    subscribe(doorsControllers, "doorState", handleEvent)
+    subscribe(energyMeters, "energy", handleEvent)
+    subscribe(humidities, "humidity", handleEvent)
+    subscribe(illuminances, "illuminance", handleEvent)
+    subscribe(locks, "lock", handleEvent)
+    subscribe(motions, "motion", handleEvent)
+    subscribe(musicPlayers, "status", handleEvent)
+    subscribe(musicPlayers, "level", handleEvent)
+    subscribe(musicPlayers, "trackDescription", handleEvent)
+    subscribe(musicPlayers, "trackData", handleEvent)
+    subscribe(musicPlayers, "mute", handleEvent)
+    subscribe(peds, "steps", handleEvent)
+    subscribe(peds, "goal", handleEvent)
+    subscribe(phMeters, "pH", handleEvent)
+    subscribe(powerMeters, "power", handleEvent)
+    subscribe(presences, "presence", handleEvent)
+    subscribe(pressures, "pressure", handleEvent)
+    subscribe(shockSensors, "shock", handleEvent)
+    subscribe(signalStrengthMeters, "lqi", handleEvent)
+    subscribe(signalStrengthMeters, "rssi", handleEvent)
+    subscribe(sleepSensors, "sleeping", handleEvent)
+    subscribe(smokeDetectors, "smoke", handleEvent)
+    subscribe(soundSensors, "sound", handleEvent)
+    subscribe(spls, "soundPressureLevel", handleEvent)
+    subscribe(switches, "switch", handleEvent)
+    subscribe(switchLevels, "level", handleEvent)
+    subscribe(tamperAlerts, "tamper", handleEvent)
+    subscribe(temperatures, "temperature", handleEvent)
+    subscribe(thermostats, "temperature", handleEvent)
+    subscribe(thermostats, "heatingSetpoint", handleEvent)
+    subscribe(thermostats, "coolingSetpoint", handleEvent)
+    subscribe(thermostats, "thermostatSetpoint", handleEvent)
+    subscribe(thermostats, "thermostatMode", handleEvent)
+    subscribe(thermostats, "thermostatFanMode", handleEvent)
+    subscribe(thermostats, "thermostatOperatingState", handleEvent)
+    subscribe(threeAxis, "threeAxis", handleEvent)
+    subscribe(touchs, "touched", handleEvent)
+    subscribe(uvs, "ultravioletIndex", handleEvent)
+    subscribe(valves, "contact", handleEvent)
+    subscribe(volts, "voltage", handleEvent)
+    subscribe(waterSensors, "water", handleEvent)
+    subscribe(windowShades, "windowShade", handleEvent)
 }
 
 /**