Dynamic label using settings on standardTile

(Roger Chui) #1

I am trying to allow the user to customize the text on the tile In my device type handler. I have under metadata:

preferences {
    input ("friendlyName", "string", title: "Switch Description", 
        description: "User-Readable Description for Switch.", defaultValue: "Generic Switch",
        required: false)


tiles (scale:2) {
    standardTile("switch", "device.switch", decoration: "flat", width: 3, height: 3) {
        state "on", label: "${friendlyName} On", action: "off1", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState: "turningOff"
        state "off", label: "${friendlyName} Off", action: "on1", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "turningOn"
        state "turningOn", label: "${friendlyName} Turning On", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState: "turningOff"
        state "turningOff", label: "${friendlyName} Turning Off", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState: "turningOn"

However, using either the ‘friendlyName’ variable or the full ‘settings.friendlyName’ variable results in NULL. I presume this is because at the time of setting up the tiles the preferences closure has not been bound yet.

Is there any way to dynamically define the text on a standardTile? I am trying to avoid using a valueTile as the documentation warns against binding actions to valueTiles but I suppose I can if I must.

Change labels of child device programatically?
(Tim Slagle) #2

Try using “text” as your input type.

(Roger Chui) #3

Thanks for the tip, but it still doesn’t seem to work. I don’t think the settings map is available when the tiles are created because both are in metadata.

(George) #4

The only dynamic option for tile labels is ${currentValue} of the attribute

These are also available but are not really “dynamic” since they are hard-coded in the tile properties

  • ${name} of state
  • ${unit}

Also note (from API docs):

Dynamic device state values like ‘${currentValue}’ and ‘${name}’ must be used inside single quotes. This is in contrast to Groovy’s string interpolation that requires double quotes.

This is required because when the platform executes the tiles() builder, it doesn’t know anything about the actual device yet. Using single quotes will allow the platform to manually substitute the actual value when the device is rendered on the mobile app.

(Ben W) #5

This is correct spent a lot of time trying to get this to work with my DH.

You may be able to set it with an action and once set it should always be set. First load will be missing, but future loads should be ok.