I am writing an mqtt driver for a virtual dimmer, i have it sending and receiving"on", "off" and level to and from an mqtt server, the status of the tile updates on and off but not the level. What code am i missing to update the tile??
Can you provide more information? Among other questions I have after reading your post:
- What tile? Hubitat Dashboard? If so, that's really a secondary concern; as long as the device attribute is getting correctly updated, Hubitat Dashboard will just pull from that, so it's really not anything to do with the tile per se (side from what template the tile is using, which determines what attribute[s] it looks at)
- How are you doing on and off? Presumably, you have something like this somewhere:
sendEvent(name: "switch", value: "on", descriptionText: "$device.displayName is on"). For level, you'd do something similar, except it would be more like:sendEvent(name: "level", value: "100", descriptionText: "$device.displayName level is 100%", unit: "%"). These generate events on Hubitat that update the device's attribute value with the given information.
Yes it is the Hubitat Dashboard.. and yes sendEvent(name: "switch", value: "off")
I could have sworn I tried something like thissendEvent(name: "level", value: "100", descriptionText: "$device.displayName level is 100%", unit: "%").. but I guess i messed it up some how.. It is now working well with Home assistant.. THANK YOU so much..
I have very limited programming skills from many years ago ..(rexx, basic, VB and c).. but have only coded apps not drivers.. Just need to clean the code up ..
Small problem.. if mqtt server goes offline..driver makes no attempt to reconnect.. So i'm using this to catch it and retry.
"def mqttClientStatus(String status){
if (logEnable) log.debug "MQTTStatus- error: ${status}"
//** if the status message is anything but a successful connection, wait 10 seconds and try to initialize again **
if ((status) == "Status: Connection succeeded") return
log.warn "Trying to reconnect"
pauseExecution(10000)
initialize()
}
"
Only problem is re-initializing runs in a loop forever.. I need to start a counter so that i can set the max number of retries.
a simple int counter = counter +1.. but can not for the life of me find a way to set a global integer. The reference material for this stuff is very difficult to find