From d45bc4c24f8d29e77c42edfc42ed7f1de4c95f08 Mon Sep 17 00:00:00 2001 From: Simon Green Date: Thu, 8 Sep 2016 18:21:46 +0100 Subject: [PATCH 1/2] Updated API URL based on changes at Hive's end See comments on http://www.smartofthehome.com/2016/05/hive-rest-api-v6/ for corroboration. --- smartapps/alyc100/hive-connect.src/hive-connect.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smartapps/alyc100/hive-connect.src/hive-connect.groovy b/smartapps/alyc100/hive-connect.src/hive-connect.groovy index c975b6da708..2ca099a3844 100644 --- a/smartapps/alyc100/hive-connect.src/hive-connect.groovy +++ b/smartapps/alyc100/hive-connect.src/hive-connect.groovy @@ -60,7 +60,7 @@ preferences { page(name: "tmaConfigurePAGE") } -def apiURL(path = '/') { return "https://api.prod.bgchprod.info:443/omnia${path}" } +def apiURL(path = '/') { return "https://api-prod.bgchprod.info:443/omnia${path}" } def startPage() { if (parent) { @@ -1155,4 +1155,4 @@ def logErrors(options = [errorReturn: null, logObject: log], Closure c) { } } -def appName() { return "${parent ? "Hive Mode Automation" : "Hive (Connect)"}" } \ No newline at end of file +def appName() { return "${parent ? "Hive Mode Automation" : "Hive (Connect)"}" } From 231ef343eb47d951c54b84b6b1bdb45c31adfd89 Mon Sep 17 00:00:00 2001 From: Simon Green Date: Sat, 10 Sep 2016 20:15:02 +0100 Subject: [PATCH 2/2] v1.1 Added support for temperature (the contact sensor has a temperature sensor in it) and battery level reading. Properly defined capabilities and attributes for use in other smartapps. --- .../hive-contact-sensor.groovy | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/devicetypes/alyc100/hive-contact-sensor.src/hive-contact-sensor.groovy b/devicetypes/alyc100/hive-contact-sensor.src/hive-contact-sensor.groovy index b99df4672fc..b16580ffe25 100644 --- a/devicetypes/alyc100/hive-contact-sensor.src/hive-contact-sensor.groovy +++ b/devicetypes/alyc100/hive-contact-sensor.src/hive-contact-sensor.groovy @@ -15,14 +15,22 @@ * VERSION HISTORY * 4th Sept. '16 * v1.0 Initial Release +* + * 10th Sept. '16 + * v1.1 Added support for temperature (the contact sensor has a temperature sensor in it) and battery level reading. Properly defined capabilities and attributes for use in other smartapps. */ metadata { definition (name: "Hive Window or Door Sensor V1.0", namespace: "simonjgreen", author: "Simon Green") { - capability "Actuator" capability "Polling" capability "Refresh" - capability "Contact Sensor" + capability "Contact Sensor" // "contact" string ("open" | "closed") + capability "Temperature Measurement" // "temperature" number + capability "Battery" // "battery" any + + attribute "contact", "string", ["open", "closed"] + attribute "temperature", "number" + attribute "battery", "string" } simulator { @@ -31,10 +39,16 @@ metadata { } tiles(scale: 2){ - standardTile("state", "device.state", width: 6, height: 4, key:"PRIMARY_CONTROL") { + standardTile("contact", "device.contact", width: 6, height: 4, key:"PRIMARY_CONTROL") { state "open", label: "open", icon: "st.contact.contact.open", backgroundColor: "#FF0000" state "closed", label: "closed", icon: "st.contact.contact.closed", backgroundColor: "#00CC00" } + standardTile("temperature", "device.temperature", inactiveLabel: true, decoration: "flat", width: 2, height: 2) { + state("temperature", label: '${currentValue} °C', icon:"st.Weather.weather2") + } + standardTile("battery", "device.battery", inactiveLabel: true, decoration: "flat", width: 2, height: 2) { + state("battery", label: '${currentValue}', icon:"st.Appliances.appliances17") + } standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) { state("default", label:'refresh', action:"polling.poll", icon:"st.secondary.refresh-icon") } @@ -63,21 +77,29 @@ def poll() { def statusMsg = "Currently" // determine contact sensor state - def state = data.nodes.attributes.state.reportedValue[0] + def contact = data.nodes.attributes.state.reportedValue[0] + def temperature = data.nodes.attributes.temperature.reportedValue[0] + def battery = data.nodes.attributes.batteryState.reportedValue[0] - log.debug "state: $state" + log.debug "contact: $contact" + log.debug "temperature: $temperature" + log.debug "battery: $battery" - if (state == "OPEN") { + if (contact == "OPEN") { statusMsg = statusMsg + " Open" + contact = "open" } - else if (state == "CLOSED") { + else if (contact == "CLOSED") { statusMsg = statusMsg + " Closed" + contact = "closed" } - sendEvent(name: 'state', value: state) + sendEvent(name: 'contact', value: contact) + sendEvent(name: 'temperature', value: temperature) + sendEvent(name: 'battery', value: battery) } def refresh() { log.debug "Executing 'refresh'" poll() -} \ No newline at end of file +}