Update Tile States - How?


(Jack) #1

Hi,
I know there’s been a bunch of posts about changing tile states already, but I haven’t really got a solid answer that works. So if anyone can help, that’d be great.

Problem:
Battery percent is sometimes inaccurate and can fluctuate. So I’ve been trying to make a battery indicator that can show the battery’s life - full, medium, low, dead. However, when I try to update the state (refer to Parse code), it doesn’t work. And I always see the “batt” tile in the “full” state. The tile won’t update. So how can I get this to work?

Code:
In definition…

attribute “battLife”, “enum”, [“full”, “medium”, “low”, “dead”]

In tiles…

standardTile("batt", "device.battLife", inactiveLabel: false, decoration: "flat", width: 2, height: 1) {
   state "full", logo: "Full"
   state "medium", logo: "Medium"
   state "low", logo: "Low"
   state "dead", logo: "Dead"
}

In parse…

                if (value >= 90){
                	log.debug "Full: " + value
                    sendEvent(name: "batt", value: "full", isStateChange: true)
                }
				else if (value >= 70 && value < 90){
                	log.debug "Medium: " + value
                	sendEvent(name: "batt", value: "medium", isStateChange: true)
                }
                else if (value >= 50 && value < 70){
                	log.debug "Low: " + value
                	sendEvent(name: "batt", value: "low", isStateChange: true)
                }
                else if (value < 50){
                	log.debug "Dead: " + value
                	sendEvent(name: "batt", value: "dead", isStateChange: true)
                }

(Jack) #2

Turns out when I did sendEvent, I used the wrong name.