Is it possible to take 2 device attributes, perform logic on them, create a new variable from the logic result and use that variable in a tile?

Hello Community,

Let me expand on the topic title a little more…

I understand that you can associate the value of a device attribute with a tile (standardTile, valueTile etc.), and also pull in multiple device attributes’ values using a multiAttributeTile too, but I have been playing around with the various types of tiles for a few days and have not managed to figure out how to achieve what I want in a single tile.

It’s important to note that the type of tile I wish to create will be displayed in the main Things view, using:

main(["<tile_name>"])

I want to take the values of both “device.thermostatMode” and “device.thermostatOperatingState”, perform some logic on those 2 values, possibly create a new variable with the result of the logic operation, and use that new variable’s value in a single tile, which is to be used in the main Things view. Here is some rough pseudo code for what I wish to achieve:

def newVariable = ""

if (device.thermostatMode == "manual" && device.thermostatOperatingState == "idle") {
   newVariable = "manualAndIdle"
}

else if (device.thermostatMode == "manual" && device.thermostatOperatingState == "heating") {
   newVariable = "manualAndHeating"
}
.....

standardTile("thermostatStatus", "newVariable", inactiveLabel: true, decoration: "flat", width: 2, height: 2) {
			state "manualAndIdle", label:'MANUAL', icon: "st.Weather.weather2"
			state "manualAndHeating", label:'MANUAL', icon: "st.Weather.weather2", backgroundColor:"#EC6E05"
		}

.....

main(["thermostatStatus"])

I’m aware that the above pseudo code probably contains errors that are obvious to people who are more of an expert than I am at SmartThings groovy coding, but hopefully it still communicates what I’m aiming to achieve. Put simply, I want to take the values of two device attributes, combine them, and visually represent them in the main Things view, using both (1) text and (2) colour, for example:

If the mode is MANUAL and the state is IDLE, then display the text “MANUAL” in grey colour
Else if the mode is MANUAL and the state is HEATING, then display the text “MANUAL” in orange colour

Is this possible at all? Any pointers would be much appreciated…

Many thanks in advance,
frazzlegod

Yes you can

  1. Define a new attribute in the metadata
  2. Define your new tile with the attribute values or use a single default value with {currentValue} if you want free flowing text
  3. Update your attribute using sendEvent or equivalent at the right time by combining your other attribute values. Where it’s done depends on your DH setup.
1 Like

Hi @RBoy,

Many apologies for this delayed reply to your suggestion above.

I had no issues understanding what you meant in your points 1 and 2, however tripped up a little in understanding how to use the sendEvent() method and when to use it (point 3) at first. Therefore, I had a look at other DTH code in some of the SmartThingsPublic forked repositories to try to gain a better understanding of how to use the sendEvent() method.

In the end I figured it out and managed to achieve exactly what I wanted with not too much code at all, so I just wanted to take this opportunity to thank you so much for your reply and pointing me in exactly the direction I needed to go in - thank you!

I just love this Community and the help / advice I receive from it.

Best regards,
frazzlegod

2 Likes