I have a current OpenHAB installation and several custom sensors (temp/humidity and garage door control) that I have been able to integrate using a custom device handler and REST. I am able to get updates when hitting an update button but have not yet been able to set an update schedule using the scheduler. I tried to add the command runEvery5Seconds() to the device handler as shown below as well as trying to write a smartapp with the sole purpose of updating the temps. Any help here would be GREATLY appreciated.
Pete
Device Handler:
metadata {
definition (name: "Temp", namespace: "pjacobs4", author: "Peter Jacobsen") {
capability "Relative Humidity Measurement"
capability "Temperature Measurement"
capability "Refresh"
command "get_status"
}
simulator {
// TODO: define status and reply messages here
}
preferences {
input name: "t_path", type: "text", title: "Temp Path", description: "", required: true, displayDuringSetup: true
input name: "h_path", type: "text", title: "Humid Path", description: "", required: true, displayDuringSetup: true
}
tiles
{
valueTile("temperature", "device.temperature", inactiveLabel: false, decoration: "flat") {
state "temperature", label:'${currentValue}°',
backgroundColors:[
[value: 31, 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"]
]
}
valueTile("humidity", "device.humidity", inactiveLabel: false, decoration: "flat") {
state "humidity", label:'${currentValue}% humidity', unit:""
}
standardTile("refresh", "device.door", inactiveLabel: false, decoration: "flat") {
state "default", label:'refresh', action:"refresh.refresh", icon:"st.secondary.refresh"
}
main "temperature"
details(["temperature", "humidity", "refresh"])
}
}
// parse events into attributes
def parse(String description) {
log.debug "Parsing '${description}'"
// TODO: handle 'humidity' attribute
// TODO: handle 'temperature' attribute
}
def poll(){
get_status()
}
def refresh() {
runEvery5Minutes(get_status())
get_status()
}
def configure() {
runEvery5Minutes(get_status())
}
def get_status() {
def params = [
uri: "http://xxxxxx",
path: "/rest/items/${t_path}/state"
]
def aa
try
{
httpGet(params) { resp ->
aa = resp
aa=aa.data.text
log.debug "${aa}"
sendEvent(name: "temperature", value: aa)
}
}
catch (e)
{
log.error "something went wrong: $e"
}
params = [
uri: "xxxx",
path: "/rest/items/${h_path}/state"
]
try
{
httpGet(params) { resp ->
aa = resp
aa=aa.data.text
log.debug "${aa}"
sendEvent(name: "humidity", value: aa)
}
}
catch (e)
{
log.error "something went wrong: $e"
}
}
Smartapp:
definition(
name: "temp_updater",
namespace: "pjacobs4",
author: "Peter Jacobsen",
description: "updates openhab temps",
category: "Convenience",
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 {
section {
input "ref", "capability.refresh", multiple: false
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def refresher(){
ref.refresh()
}
def initialize() {
refresher()
runEvery5Minutes(refresher())
}