Power values into labels


#1

Hi!

Im trying to create a custom device type for my ventilation system.

I have a power tile

    }

	valueTile("power", "device.power", decoration: "flat", width: 3, height: 2, canChangeIcon: true) {
    	state "power", label:'${currentValue} W'
	}

But instead of displaying current value in watts, I want to display “Low”, “Medium” and “High” depending on how much power the system is using.

Is this possible?


(Ben W) #2

Not 100% sure this will work, but you could try what background color range does:

    valueTile("bgColorRange", "device.integer", width: 2, height: 2) {
    state "val", label:'${currentValue}', defaultState: true, backgroundColors: [
        [value: 10, color: "#ff0000"],
        [value: 90, color: "#0000ff"]
    ]
}

Another option is to find the place where it is set sent in the code and add an case statement to send a value instead.


#3

I have already played with the color option, and I can get it to change in three different colors matching the three different settings on my system.

If only there was a similar way to change the text also


(Ben W) #4

Where you are calling set the tile instead of sending the power amount you can send a value.

There should be a something like (this is from smartOutlet DH)

sendEvent(name: "power", value: powerValue, descriptionText: '{{ device.displayName }} power is {{ value }} Watts', translatable: true )

You can create a new function that replaces that line. Pass in powerValue and do a check on the value and send it to the tile as Low/Medium/High.