Dynamic icons with UoM state?

Is there a way to assign dynamic icons to items bearing Unit of Measurement?

For instance, the item currentWindDirection could be of type Number:Angle.

I know how to proceed by using a proxy item and a rule or transform, but it would be nice if it were possible out of the box by properly naming the icons, as in wind_direction_0_deg.svg

So far as I know, the dynamic icon mechanism simply ignores UoM and uses the base number in the state.

I created a set of SVG icons and converted them to 128px PNG icons with rsvg-convert. They are named as follows:

  • wind_dir.png → (default) NULL state
  • wind_dir-null.png → NULL state
  • wind_dir-undef.png → UNDEF state
  • wind_dir-0.png → 0 degrees
  • wind_dir-5.png → 5 degrees
  • wind_dir-355.png → 355 degrees
  • wind_dir-360.png → 360 degrees (identical to 0 degrees, but used for rounding)

Whenever I try to render a wind direction, only the icon mapped to NULL state is rendered, irrespective of the value. This is also the default icon, so I suppose dynamic icons cannot be used with angles?

That may be because the icon “set” breaks the rules. only icon-0 to icon-100 are allowed.
Probably more to it than that though, I’d expect the “excess” icons to just be ignored.
I think to do this you would need to make a dummy number Item that took values 0-100, effectively percentage of a circle.

Try something simple. A temporary Number Item and a text sitemap. People often have trouble with icons while making changes, I think there’s more than one cache at work.

Out of interest, is that wind_dir-null.png or wind_dir.png ?

That’s what I thought, hence my convoluted initial approach (which works). I hoped it would be available out of the box.

However, I might try another convoluted approach in which I will create an item with a textual state which could then be mapped to any icon. If I then use a MAP transform, I can render the value. The approach would then be as follows:

  1. Update a proxy item and set the state to “val0”, “val1”, … “val359”, “val360”, “undef”, “null”
  2. Add corresponding icons with names “wind_dir-val0.svg”, “wind_dir-val1.svg”, … “wind_dir- val359.svg”, “wind_dir-val360.svg”, “wind_dir-undef.svg”, “wind_dir-null.svg”
  3. Define a MAP() transform so “val0” translates to “0°” … “val360” to “360°”, “-”, “null” and “undef” to a meaningful textual representation of either state.

EDIT: this approach works!

It was wind_dir.png (I changed the color of one element in the icon so I could disambiguate between wind_dir-null.png and wind_dir.png).

Sadly the wind direction hasn’t been in the 0→100 range since my test so I can’t yet confirm whether the dynamic icon is being picked up in those cases.

I think you could avoid having 360 icons (is there any visible diff between 344 and 345?) by -
Having a number proxy holding say divide-by-5 of the real value.
This allows to use the numeric icon ability to select the “next lowest icon” for interim values. Use as many/few icons as you wish to cover the 0 - 73 range
And a JS multiply-by-five transform to recreate the displayed number text.