Using an attribute as value for a tile

Hi everyone,

I am struggling today with displaying a value I store in an attribute so that it shows up in the tile label independently from my state value that I use to select tile state to display as they have different weather icons I extract from a weather service.

So here is my code extracts:

    capability "sensor"
    attribute "weather", "string"

Then in my Tile:

standardTile(“UGW_Icon_UrlIcon”, “device.UGW_Icon_UrlIcon”, decoration: “flat”, width: 2, height: 2) {

state “hazy”,icon:“https://raw.githubusercontent.com/philippeportesppo/AirMentorPro2_SmartThings/master/images/hazy.png”,label: ‘${currentWeather}’

In my Parse function:

   events << createEvent( name:"weather", value: "Smocky" /* normaly should be my html.body.table.tr[1].td[15].text()*/, display:true)

This event is well fired from what I see in the log

   	events <<   createEvent(name: "UGW_Icon_UrlIcon", value: UGW_Icon_Nt.toString()+UGW_Icon_Url.toString())

This even is also well fired as the right icon is displayed in my Tile.

But the tile displays “null” as label.

I checked about the usage of attributes in tiles and understood the concatenation of the current state with the attribute name, but it seems the value is not returned.

Any idea?

Thanks!

This same question just came up a week ago, but darned if I remember the Topic title to search for it … nor even the conclusive answer.

If I recall correctly, though, I/we concluded that a “standardTile” cannot display an arbitrary Attribute Value. It can only display currentValue or name.

Keep in mind that the “definition” section of a DTH is not “real” Groovy code. It is handled by a pre-processor with specific “sandbox” limitations.

http://docs.smartthings.com/en/latest/device-type-developers-guide/tiles-metadata.html#state-labels
image

1 Like

You kind of can: Change labels of child device programatically?

With that said s better way is to limit the user to a list of choices. For example here is a modified contact sensor for used with the konnected system which gives a lot more options for open and closed :

1 Like

Hi @tgauchat

Thanks for your usual quick answer. I indeed tried everything I read in the documentation pages and other posts but they are always having a tie between the state and the label. I didn’t find an example of something with a state and a label.

Using the label: '${name}", as my attribute is named “weather”, I modified my “string” attribute into an enum as the weather forecasts are finally a big set of predefined value, it could work :
attribute “weather”, “enum”, [“Smoke”]

Then my tile is now: state “NThazy”,icon:“https://raw.githubusercontent.com/philippeportesppo/AirMentorPro2_SmartThings/master/images/hazy.png”,label: ‘${weather}’

But this is not working either.

Right, this is something I also understood from the documentation.

Thanks @vseven

If I understand well this code, it allows the overload of the labels because this is based on a Multi-Tile and split in 2 messages the state sent to the primary control and the value to the tile hosting the primary tile states.
But in my case, I use standardTile as I have many:

The one I have troubles with are is the clouds one.

Thanks

No … You are misreading the documentation.

If am I correct, then only valid values are EXPLICITLY these (no substitution allowed):

${currentValue}
or
${name} (i.e., the letters N-A-M-E, not “${weather}”).

I know … it is incredibly limiting, or I am outright wrong.

2 Likes

ha, you are right. I was too optimistic.

Ok, I’ll go for simpler solution then. I spit my tile in 2 tiles. One for the icon, one for the string.
That’s not what I wanted, but it looks to be anyway over the ST offer in term of UI.

Thanks again.

1 Like

Yep that’s correct. It’s a limitation going back years where we had this discussion about dynamic tiles. But those are the only options now. The workaround is to create attributes with dynamic values and then use the currentValue for that attribute in the tile.

1 Like

Hi,

do you have an example of this using StandardTile?

Thanks

attribute "weather", "string"
standardTile("weather", "device.weather", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
			state "default", label:'${currentValue}', action:"", icon:"st.secondary.refresh"
}
sendEvent(name:"weather", value:"Create some dynamic value")
1 Like

Thanks , I see now.

That one won’t work for me as my tile is a multi-state because of the icons I have to manage. I would have enjoyed to dynamically provide the icon name instead of having one state for one icon, but I guess for the same reasons we are discussing here on the label, there is no dynamic icon management either. So I had to stick to the multi-state, originally with labels that I removed since I split the label in another tile to solve my initial problem.

standardTile(“UGW_Icon_UrlIcon”, “device.UGW_Icon_UrlIcon”, decoration: “flat”, width: 2, height: 2) {
state “chancerain”, icon: “https://raw.githubusercontent.com/philippeportesppo/AirMentorPro2_SmartThings/master/images/chancerain.png
state “chancesleet”, icon:“https://raw.githubusercontent.com/philippeportesppo/AirMentorPro2_SmartThings/master/images/chancesleet.png
state “chancesnow”,icon:“https://raw.githubusercontent.com/philippeportesppo/AirMentorPro2_SmartThings/master/images/chancesnow.png
state “chancetstorms”,icon:“https://raw.githubusercontent.com/philippeportesppo/AirMentorPro2_SmartThings/master/images/chancetstorms.png
state “clear”,icon:“https://raw.githubusercontent.com/philippeportesppo/AirMentorPro2_SmartThings/master/images/clear.png
state “cloudy”,icon:“https://raw.githubusercontent.com/philippeportesppo/AirMentorPro2_SmartThings/master/images/cloudy.png
state “flurries”,icon:“https://raw.githubusercontent.com/philippeportesppo/AirMentorPro2_SmartThings/master/images/flurries.png
state “fog”,icon:“https://raw.githubusercontent.com/philippeportesppo/AirMentorPro2_SmartThings/master/images/fog.png
state “hazy”,icon:“https://raw.githubusercontent.com/philippeportesppo/AirMentorPro2_SmartThings/master/images/hazy.png

1 Like

If you states are unique why not use static text for each state? Why do you want dynamic text with limited tile space?

1 Like

Correct, that’s how I implemented it first. I am using UndergroundWeather API here.
I originally used the ‘icon’ string in their json as a state so that it was showing both the right icon and string, both hardly coded. Everything worked fine till last week. I am California and I got “flurries” for the weather instead of “smoke” because the ‘icon’ turned into “Smoke” and this wasn’t an icon name (hazy is the icon they use for that string).
So I should not use the ‘icon’ string as a ‘weather’ string, I have to get both of them from their json.
So I changed my implementation to use the ‘icon’ name and then needed something to pass the weather string in the same StandardTile.

2 Likes