OH3 - Set iconColor

Hi All,

i have created a Floor Plan with a permanent tooltip icon.

this is my YAML.

component: oh-plan-marker
  name: Kind1 Temperatur
  coords: 123.15197102896981,26.71450448474576
  icon: f7:flame
  useTooltipAsLabel: false
  tooltipPermanent: true
  iconSize: 25
  iconColor: "=(items.KNX_KIND1_HEIZUNG_STATUS_STELLWERT.state <= 0.05) ? 'green'
    : (items.KNX_KIND1_HEIZUNG_STATUS_STELLWERT.state <= 0.1) ? 'yellow' :
  default: []

I want to change the color of the icon in several steps.
I know that i can do this via if else short form like in my YAML

But i want to use serveral colors and limits.

< 0.05 => green
< 0.1 => yellow
< 0.3 => orange
< 0.5 => another orange
else => red

this will create a very long statement.

Is it possible to use a function instead?

something like:

iconColor = function() { var a = items.KNX_KIND1_HEIZUNG_STATUS_STELLWERT.state; if ...  return 'green'; }

Unfortunately you cannot. The parser that processes the yaml is only a limited expression parser, not a full JavaScript implementation. So, you cannot do full declarations or control loops, etc.

For your use case the lengthy nested if-then is the best option.

One other suggestion is to use Scale - Transformation Services | openHAB, either with a state description “pattern” or a profile.
So you would need to write a file like:


Then you will have to duplicate your KNX_KIND1_HEIZUNG_STATUS_STELLWERT item, linking it to the same channel, and naming it KNX_KIND1_HEIZUNG_STATUS_STELLWERT_color for example, and either:

  1. set its state description to `SCALE(yourfile.scale):%s (in this case your item remains of the Number type)
  2. configure the link with the “SCALE” profile, configuring it appropriately with the .scale file name (in this case your item should be of the String type)

In the former case you should then get the appropriate color string (“green”, “yellow” etc.) with items.KNX_KIND1_HEIZUNG_STATUS_STELLWERT_color.displayState, in the latter case though, your item’s actual state will be the result of the transformation so you should use items.KNX_KIND1_HEIZUNG_STATUS_STELLWERT_color.state

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.