Dynamic Icons in DTH - it's possible!

Am I right to think that there is no way to dynamically set an icon in a child device handler? I’m wanting to set an icon background as a URL (which works when set in the DTH), but need to set the URL parameters based on SmartApp values.

Alternatively, can anyone think of any work-arounds where I could reference a ‘static’ url which is populated separately by an HTTPPost or similar from the smart app? I was wondering whether I could set the icon in the DTH to be a link to my smart app as a web services call, and the smart app then returns the content of the dynamic page, rendered as a PNG or JPEG?

Essentially, within the Tiles section, you can have no run-time defined variables. The only exception is the attribute states (i.e., on/off/value) and the text label (can be the current value of the state or can be set text).

That being said, the system does accept url icons. However, these must be “static” names in the Icon section of the attribute state line. a simple (non-url) example is below. Other than the icon path/url/name being static, I do not know of other limitations.

standardTile("playpause", "device.playpause", decoration: "flat") {
    state "pause", label:'', icon:'st.sonos.play-btn', action:'music Player.play'
    state "play", label:'', icon:'st.sonos.pause-btn', action:'music Player.pause'
}

Success!! I’ve managed to dynamically display a map in my child device hander by doing the following:

in the DTH, set the icon to be a WebApi call to my SmartApp (https://[URL].api.smartthings.com/api/token/[token]/smartapps/installations/[appid]/showMap

In the SmartApp, turn on OAuth, create a mapping for showMap to run the following:
def streamMapData() {
def params = [
uri: “https://maps.googleapis.com/maps/api/staticmap?center=${state.gpsLat},${state.gpsLon}&size=440x330&zoom=16&markers=icon:https://tinyurl.com/[iconpath]|size:small|${state.gpsLat},${state.gpsLon}&key=${googleMapsApi}”,
contentType: ‘image/png’
]
try {
httpGet(params) { resp ->
//log.debug "response contentType: ${resp.contentType}"
state.mapcontentType = resp.contentType
state.mapdata = resp.data
//log.debug “response data: ${resp.data}”
}
} catch (e) {
log.error "something went wrong: $e"
state.mapdata = “Something went wrong: $e”
}
render contentType: state.mapcontentType, data: state.mapdata, status: 200
}

All I now have to work out is whether in the DTH it’s possible to set the token and appID in the settings / parameters rather than it being hard coded…

Hi @Needlerp

Dumb question but this is my first stab at this.
When you say “Create a mapping for showMap to run the following…” is “showMap” the appName or a function within the app?