Hi,
I am trying to write a device handler where a refresh button will do a local http get and the JSON output will be used to change a label to red or green.
This is what I have so far. But it doesn’t work.
import groovy.json.JsonSlurper
metadata {
definition (name: "My Device", namespace: "mydevice", author: "kaznad") {
capability "Refresh"
attribute "level", "string"
}
simulator {
// TODO: define status and reply messages here
}
tiles {
standardTile("level", "device.level", width: 1, height: 1, inactiveLabel: false, canChangeIcon: false) {
state ("default", label:'unknown')
state ("low", label:'Battery Low', backgroundColor: "#bc2323")
state ("ok", label:'Battery OK', backgroundColor: "#79b821")
}
standardTile("refresh", "device.lock", inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
main "level"
details(["level","refresh"])
}
}
// parse events into attributes
def parse(String description) {
log.debug "Parsing '${description}'"
def slurper = new JsonSlurper()
def result = slurper.parseText(description)
switch (result.state.bri) {
case "0":
sendEvent(name: "level", value: "low", isStateChange: true)
log.debug "Failure"
break;
case "254":
sendEvent(name: "level", value: "ok", isStateChange: true)
log.debug "Success"
break;
}
}
// handle commands
def refresh() {
log.debug "Executing 'refresh'"
def hubAction = new physicalgraph.device.HubAction(
method: "GET",
path: "/api/username/lights/1922029999",
headers: [HOST: "192.168.8.3:80", Accept: "application/json"])
log.debug hubAction
return hubAction
}
what am I missing? Thanks.