Can somebody define what the first argument to state() actually means?

Hi all,

I’m trying to find out what the subject says I am… In the documentation, somewhere, I read

The first argument of the state() method should be the value of the attribute this state applies to.

Looks clear, but it must be wrong. If it isn’t, how does the following work (in Zen’s thermostat code)?

valueTile("thermostatSetpoint", "device.thermostatSetpoint", width: 2, height: 2) {
    state "off", label:'${currentValue}°', unit: "C", backgroundColor:"#e8e3d8"
    state "heat", label:'${currentValue}°', unit: "C", backgroundColor:"#e8e3d8"
    state "cool", label:'${currentValue}°', unit: "C", backgroundColor:"#e8e3d8"
}

This works: a number is displayed, with different colors depending on the thermostat mode. Clearly ${currentValue}, which is a number, is different from any of the strings specified in the first state argument, so the definition above must be wrong. I searched high and low, but couldn’t find a proper definition. I found this gem:

… the name of the attribute value for which to display this state for.

Argh.

Any help?

Thanks!

You can see a lot of examples of “State” in action in the SmartThings device code base.

Where is the full code for “Zen’s Thermostat” ? I don’t see how this code could do as you say because all three colors listed have the same value of #e8e3d8 so even it it did work colors would not change.

If you look at the Smart Things thermostat samples (there are several) they code the temp color coding like this.

valueTile("temperature", "device.temperature", width: 2, height: 2) {
			state("temperature", label:'${currentValue}°',
				backgroundColors:[
					[value: 32, color: "#153591"],
					[value: 44, color: "#1e9cbb"],
					[value: 59, color: "#90d2a7"],
					[value: 74, color: "#44b621"],
					[value: 84, color: "#f1d801"],
					[value: 92, color: "#d04e00"],
					[value: 98, color: "#bc2323"]
				]
			)
		}

It is here. I see the colors have the same value - I was getting confused with something else. Is it the case, then, that the official code from Zen is just wrong?

Edit: the reason I’m asking this question is because I want to achieve something like I described: display a value based on one attribute, with a background color that I can only seem to get by looking at another attribute. I did look at the Zen code and it seemed to indicate that the “state” and ${currentValue} can have different values.

Probably. :confused:

That one tile definition doesn’t make sense; but, frankly, when sometimes just “reading” code its possible to overlook something.

They may be exploiting something about the state (or attribute) that you could trace with some debugging.

Or it’s just wrong.

It’s wrong. It will work in the sense that all three “states” are the same, so what you can’t tell is that it will only ever use the “off” line because it’s first. When an attribute state doesn’t match any of the states delineated it will use the one defined as the default; and if no default is assigned, it will use the first one.

If you want to use information from more than one attribute then you need to create a new attribute that combines the two in some way that lets you create your intended solution.

If in this case you wanted the color to be dependent on the temp setpoint, but display the mode; you could create a new attribute with values like “off low”, “off med”, “off high” where the state label would be “off” and the color would be different for low, med and high. Repeat for each mode.

1 Like

Thanks all. That’s not the first weird thing on Zen’s code.

What I can do does not seem possible then, I’ll just use another tile. For the record: I wanted a tile showing the cooling setpoint temperature, which could be pressed to set the thermostat mode to “cool”, and that would turn blue when that happened. I can do the first two only.