Background color of main tile based on variable value?


#1

I am writing a device handler for the Chinese NEO Coolcam power plug. I have it working but I would like to add one feature that I cannot seem to get the way I want.

I want the background of the main tile to be dependent on the Watt consumption AND I want the Watt consumption to show in the main list of Things. The idea is that I can have all my metered devices in one ‘Room’ and in a glance see if the power usage is below what I expect (yellow), above what I expect (orange) or ok (green) based on a range you can configure in the settings.

I have managed to show the value of the Watt consumption in the Things list by using:

multiAttributeTile(name:"status", type: "generic", width: 6, height: 6, canChangeIcon: false){
	tileAttribute ("device.power", key: "PRIMARY_CONTROL") {
		attributeState "val", 
			label:'${currentValue} W', 
			backgroundColor:"#79b821",
			icon:"st.switches.switch.on"
		}

I have also managed to get the correct color in the main screen (after you select the Thing) by using:

multiAttributeTile(name:"status", type: "thermostat", width: 6, height: 6, canChangeIcon: true){
	tileAttribute("device.power", key: "PRIMARY_CONTROL") {
		attributeState("val", label:'${currentValue} W')
	}
	tileAttribute("device.powerState", key: "OPERATING_STATE") {
		attributeState("off", backgroundColor:"#ffffff")
		attributeState("low", backgroundColor:"#ffde00")
		attributeState("ok", backgroundColor:"#79b821")
		attributeState("high", backgroundColor:"#e86d13")
	}
}

and now I would like to combine them but I can’t figure out how to do that.


(Martin Verbeek) #2

domoticzpowerReport This might help you further.


#3

@dudz40 Thanks for the link. This is the part that I managed to do already, coloring based on fixed values for the ranges. What I want is that the ranges are flexible, so for example I expect the socket for my NAS to be between 40 and 50, below is bad, above is bad, but for the chargers I expect it to be below 20. Am I missing the essence of your link?


(Martin Verbeek) #4

Tiles are not that flexible. There is an example somewhere with Celsius and
Fahrenheit and the values that relate to colours, but that switch can be
done once. Tiles are setting these values at device init time.

Thought your question was : I want the background of the main tile to be dependent on the Watt consumption AND I want the Watt consumption to show in the main list of Things.

met vriendelijke groeten,

Martin