Dynamic icons in sitemap according to an item state

Hi
I’m currently writing the sitemap for my house. We have a large number of heating zones and so for the heating portion I’m trying to minimise the space the display uses so that it will be manageable on a mobile phone screen.
For each zone I have a current temperature line and a setpoint line

Setpoint item=Bedroom_Target label=“Bedroom [%.1f °C]” minValue=14 maxValue=27 step=0.5 icon=“heating”
Text item=Bedroom_Temp label=“Bedroom[%.1f °C]” icon=“temperature”<

I would also like to display whether or not the heating is active in a zone or not. There is an item

String Bedroom_State “Bedroom State”(Bedroom) {channel = “neohub:neostat:myhubname:Bedroom:thermostatOutputState”}<

which I could display but that would take another line of display. Is there a way of setting the icon for the Bedroom_Temp line according to the value of the Bedroom_State item ?

Thanks
Tim

The simplest way I could come up with, is by using the visbility= Item attribute in your sitemap. In essence, you’d duplicate a line so you can assign another icon depending on whether the heating is on or off, as in:

Default item=Bedroom_Target icon="heating_off" visibility=[Bedroom_State==OFF]
Default item=Bedroom_Target icon="heating_on" visibility=[Bedroom_State==ON]

This of course assumes that Bedroom_State is always set to either OFF or ON, which may not always be true (e.g. at startup or when the binding loses contact to the things it controls).

Also, to make it work, you will have to create icons (heating_off and heating_off in /etc/openhab2/icons/classic/ with extension SVG and/or PNG) as I couldn’t yet find a way to use a dynamic icon’s static counterpart (with defined state) for a static item on a sitemap…

You could even go one step further and define colors depending on the temperature in the room, e.g. as in:

// Change the value color of the outside temperature depending on value:
Default item=Wx_OWM_Current_Temperature
	valuecolor=[
			>=30="red", >=25="orange", >=15="green", 0="silver", <0="purple", <15="blue"
	]

Note that using valuecolor works as follows:

  1. the rules are read and evaluated left-to-right
  2. the first expression which evaluates to True will define the color

For this reason, the condition <15="blue" has been placed at the end to correctly manage the 0°C case and the (Celsius) freezing case. Otherwise the following conditions would never be evaluated: 0="silver", <0="purple".

3 Likes

Thank-you for the detailed reply, I will try this out

This worked an absolute charm using stock icons. So a flame icon if heating and blank if not

Setpoint item=Bedroom_Target label=“Bedroom [%.1f °C]” minValue=14 maxValue=27 step=0.5 icon=“heating”
Text item=Bedroom_Temp label=“Bedroom[%.1f °C]” icon=“fire” visibility=[Bedroom_State==“Heating”]
Text item=Bedroom_Temp label=“Bedroom[%.1f °C]” visibility=[Bedroom_State==“Off”]<

1 Like