Skip to content

Commit

Permalink
Merge pull request SmartThingsCommunity#2 from simonjgreen/master
Browse files Browse the repository at this point in the history
Updated API URL based on changes at Hive's end
  • Loading branch information
alyc100 authored Sep 10, 2016
2 parents 82aa356 + ca0f357 commit ce80822
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
Expand Down Expand Up @@ -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()
}
}
4 changes: 2 additions & 2 deletions smartapps/alyc100/hive-connect.src/hive-connect.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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) {
Expand Down Expand Up @@ -1171,4 +1171,4 @@ def logErrors(options = [errorReturn: null, logObject: log], Closure c) {
}
}

def appName() { return "${parent ? "Hive Mode Automation" : "Hive (Connect)"}" }
def appName() { return "${parent ? "Hive Mode Automation" : "Hive (Connect)"}" }

0 comments on commit ce80822

Please sign in to comment.