Out of simple curiosity of trying to use a http get in a device handler I made a shell program for this device. Since they arn’t giving out codes I can’t test it but if anyone else gets one they hopefully can use something in here. Figured I’d most it before deleting it out of my IDE:
/**
* AWAIR
*
* 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.
*
* Change History:
*
* Date Who What
* ---- --- ----
* 2017-10-13 Allan (vseven) Initial creation
*
*/
metadata {
definition (name: "AWAIR Sensor", namespace: "vseven", author: "Allan (vseven)") {
capability "Temperature Measurement"
capability "Sensor"
capability "Relative Humidity Measurement"
attribute "co2", "number"
attribute "voc", "number"
attribute "dust", "number"
attribute "lastUpdated", "String"
}
simulator {
}
tiles(scale: 2) {
multiAttributeTile(name: "temperature", type: "generic", width: 6, height: 4, canChangeIcon: true) {
tileAttribute("device.temperature", key: "PRIMARY_CONTROL") {
attributeState("temperature", label: '${currentValue}°', unit:"F", defaultState: true,
backgroundColors: [
// Celsius
[value: 0, color: "#153591"],
[value: 7, color: "#1e9cbb"],
[value: 15, color: "#90d2a7"],
[value: 23, color: "#44b621"],
[value: 28, color: "#f1d801"],
[value: 35, color: "#d04e00"],
[value: 37, color: "#bc2323"],
// Fahrenheit
[value: 32, color: "#153591"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 95, color: "#d04e00"],
[value: 96, color: "#bc2323"]
])
}
tileAttribute("device.humidity", key: "SECONDARY_CONTROL") {
attributeState "humidity", label:'${currentValue}%', icon:"st.Weather.weather12"
}
}
valueTile("co2", "device.co2", width: 2, height: 2,decoration: "flat") {
state "default", label:'${currentValue} co2 ppm'
}
valueTile("voc", "device.voc", width: 2, height: 2,decoration: "flat") {
state "default", label:'${currentValue}% voc ppm'
}
valueTile("dust", "device.dust", width: 2, height: 2,decoration: "flat") {
state "default", label:'${currentValue}% dust ppm'
}
valueTile("lastUpdated", "device.lastUpdated", inactiveLabel: false, decoration: "flat", width: 6, height: 2) {
state "default", label:'Last Updated ${currentValue}', backgroundColor:"#ffffff"
}
main(["temperature"])
details(["temperature", "humidity", "co2", "voc", "dust" ,"lastUpdated"])
}
}
def installed() {
runEvery15Minutes(getData)
}
def uninstalled() {
unschedule()
}
def getData() {
log.debug("getData run")
def params = [
uri: 'https://beta-api.awair.is/v1/devices/1/events/15min-avg',
headers: ['Authorization': 'Bearer {access_token}'],
contentType: 'application/json'
]
try {
httpGet(params) {resp ->
log.debug "resp data: ${resp.data}"
// Do stuff with the data
resp.headers.each {
log.debug "${it.name} : ${it.value}"
}
log.debug "temp: ${resp.data.sensor.temp}"
}
// Update lastUpdated date and time
def nowDay = new Date().format("MMM dd", location.timeZone)
def nowTime = new Date().format("h:mm a", location.timeZone)
sendEvent(name: "lastUpdated", value: nowDay + " at " + nowTime, displayed: false)
} catch (e) {
log.error "error: $e"
}
}