I am trying to get started writing smart apps and I don’t know why I have to press the refresh button to get the data from my thermostat. Is there a way to get the data when I go into the thermostat with out having to press the refresh button?
metadata {
definition (name: "mystat", namespace: "mystat", author: "Me") {
capability "ThermostatHeatingSetpoint"
capability "thermostatOperatingState"
capability "TemperatureMeasurement"
capability "Configuration"
capability "Refresh"
attribute "outdoorTemp", "string"
attribute "outputPercentDisplay", "number"
command "getThermo"
}
simulator {
// TODO: define status and reply messages here
}
tiles(scale: 2) {
multiAttributeTile(name:"temperature", type: "thermostat", width: 6, height: 4){
tileAttribute ("device.temperature", key: "PRIMARY_CONTROL") {
attributeState("temperatureMeasurement", label:'${currentValue}°', unit: "dF", backgroundColor:"#269bd2")
}
tileAttribute("device.heatingSetpoint", key: "VALUE_CONTROL") {
attributeState("VALUE_UP", action: "heatingSetpointUp")
attributeState("VALUE_DOWN", action: "heatingSetpointDown")
}
tileAttribute("device.thermostatOperatingState", key: "OPERATING_STATE",inactiveLabel: true) {
attributeState("idle",backgroundColor:"#44b621")
attributeState("heating",backgroundColor:"#ffa81e")
}
tileAttribute("device.humidity", key: "SECONDARY_CONTROL") {
attributeState("humidity", label: '${currentValue}%', unit: "%", defaultState: true)
}
tileAttribute("device.heatingSetpoint", key: "HEATING_SETPOINT") {
attributeState("default", label: '${currentValue}', unit: "dF")
}
}
// //Heating Set Point Controls
// controlTile("levelSliderControl", "device.heatingSetpoint", "slider", height: 1, width: 6, inactiveLabel: false, range:"(5..30)", decoration: "flat") {
// state "heatingSetpoint", action:"heatingSetpoint"
// }
standardTile("heatLevelDown", "device.heatingSetpoint", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "heatLevelDown", action:"heatingSetpointDown", icon:"st.thermostat.thermostat-down"
}
standardTile("heatLevelUp", "device.heatingSetpoint", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "heatLevelUp", action:"heatingSetpointUp", icon:"st.thermostat.thermostat-up"
}
controlTile("heatingSetpointSlider", "device.heatingSetpoint","slider", height: 2, width: 2, range:"5..86") {
state "heatingSetpoint", label:'${currentValue}', action:"setHeatingSetpoint"
}
valueTile("heatingSetpoint", "device.heatingSetpoint", width: 2, height: 2, inactiveLabel: false) {
state "heatingSetpoint", label:'${currentValue}', backgroundColor:"#153591"
}
standardTile("refresh", "device.thermostatMode", inactiveLabel: false, width: 2, height: 2, decoration: "flat") {
state "default", action:"refresh.refresh", icon:"st.secondary.refresh"
}
standardTile("error", "device.error", width: 4, height: 2, inactiveLabel: false, decoration: "flat") {
state "default", label:'${currentValue}', backgroundColor:"#ffffff", icon:"st.Office.office8"
}
main (["temperature"])
details(["temperature", /*"heatLevelDown", "heatingSetpoint", "heatLevelUp", */"refresh", "error"])
}
}
def getThermo() {
log.debug “thermo starting”
def destIp = “10.0.0.112”
def destPort = “80”
def hosthex = convertIPtoHex(destIp)
def porthex = convertPortToHex(destPort)
device.deviceNetworkId = “$hosthex:$porthex”
log.debug "device id is " + device.deviceNetworkId
def hubAction = new physicalgraph.device.HubAction(
'method': 'GET',
'path': "/query/info",
'headers': [ HOST: "$destIp:$destPort" ])
// log.debug "hubaction is: " + hubAction
def device = devices.find { it?.key?.contains(body?.device?.UDN?.text()) }
hubAction // also tried to “return hubAction”
}
def updated() {
log.debug “Executing ‘updated’”
unschedule()
runEvery5Minutes(refresh)
}
def initialize() {
// Device-Watch simply pings if no device events received for 32min(checkInterval)
log.debug “Inital”
// Poll device for additional data that will be updated by refresh tile
refresh()
}
def parse(description) {
def slurper = new groovy.json.JsonSlurper()
def msg = parseLanMessage(description)
def body = msg.body
def result = slurper.parseText(body)
//log.debug msg
log.debug msg.body
sendEvent(name: “temperature”, value:result.spacetemp, state: “refresh”)
sendEvent(name: “humidity”, value:result.hum, state: “refresh”)
}
private String convertIPtoHex(ipAddress) {
String hex = ipAddress.tokenize( ‘.’ ).collect { String.format( ‘%02X’, it.toInteger() ) }.join()
return hex
}
private String convertPortToHex(port) {
String hexport = port.toString().format( ‘%04X’, port.toInteger() )
return hexport
}
def refresh(){
log.trace(“Connexion verifiction - ${device.name}”)
def timeInSeconds = (Math.round(now()/1000))
getThermo()
}