Combining 2 item states in a sitemap section display?

  • openHAB version: 2.3

in items

Switch OD_OAC_power "Office AC Power" { channel="opendaikin:ac_unit:192_168_2_61:power"}
Number OD_OAC_tempin "Office inside temp [%.1f °C]" <temperature> { channel="opendaikin:ac_unit:192_168_2_61:indoortemp"}

in sitemap
This shows me a section with a static icon (doesn’t change depending on state) and the room’s temperature:

Text item=OD_OAC_tempin label="Office AirCon" icon=climate {

This shows me a section with a dynamic icon (aircon on or off) but no temperature.

Text item=OD_OAC_power label="Office Aircon" icon=climate {

Each value comes from a different item. And the dynamic icon changes according to the ON/OFF state of OD_OAC_power, while OD_OAC_tempin is the item that holds the temperature. Is it possible to have both: section has dynamic icon depending if aircon is on or off and also shows the current temperature?

I’d normally want try to have the icon state controlled by the power switch, while augmenting the label with the addition of the tempin value. I checked around the forums and there were a couple of people that asked something similar but only got a couple or so replies and they involved rules and in the rules imports of modules and the such. I haven’t got around to rules yet - so far I’ve got several bindings, lots of things and items but they mostly show state and control via bindings works well enough (Opendaikin, SamsungTV, Enigma, etc). I wanted to get it to look right before venturing to rules.

Concatenating strings in sitemap, is it possible?

Yes but not easily.

In some cases you can create a new Item to combine the states into one Item using Rules. This usually works when you are dealing with wanting two pieces of information on the label.

For cases where you want to control the icon, you need to use the visibility option and custom icons.

Here is an example for one of my garage doors.

Switch item=aGarageOpener1 icon="garagedoorclosed" mappings=[ON=Open]  visibility=[vGarageOpener1 == CLOSED]
Switch item=aGarageOpener1 icon="garagedooropen"   mappings=[ON=Close] visibility=[vGarageOpener1 == OPEN]

When vGarageOpener1 is CLOSED, the line that uses the garagedoorclosed icon and the Open button (mappings) is shown. vGarageOpener1 is OPEN, then the line that uses the garagedooropen icon and the Close button is shown.

Sometimes you just have to go to Rules. This isn’t one of those cases though.

I’m not sure if you got my point (or perhaps I didn’t get yours :slight_smile: ).

What you suggest works on simple states but in my example above the climate icon should show if the aircon is on or off and yet still show the temperature in the label. Thus needing 2 item states in one section display:
Text item label icon {


}

At a glance I can see both if aircon is on (icon state) and the inside temp. In one line and not two. With 2 lines it is trivial to do. How to combine the left icon to represent on/off state with the right hand side space to show temperature.

This is extremely useful for at a glance and space saving so I’m surprised more people aren’t asking for this.

Here I found 2 links that discuss something similar but it seems it’s not possible:

Switch, adjust item label depending on current - #7 by rossko57

If the icon has to reflect item state then for on/off I have to use the switch item reference. Now, the label is text/string. Feels odd that this string can’t contain a reference to an external variable (state of a different item eg. temperature)

edit: you did answer ‘yes but not easily’. I would be very grateful if you have suggestions/examples specifically for the on/off and temperature case. I guess I’m not advanced enough yet to extrapolate from the garage door example. :frowning:

edit 2: ok I get it now. I was missing that visibility can be applied to sections!

Hi @r4m235,

you could to that with the visibility-tag. But you can not control the ac with it.

You would need two different icons for your AC (AC-On / AC-Off).
Like this:

Text item=OD_OAC_tempin label="Office Aircon" icon=climate_ON} visibility=[OD_OAC_power == ON]
Text item=OD_OAC_tempin label="Office Aircon" icon=climate_OFF} visibility=[OD_OAC_power == OFF]

So in the end, only one line is shown.

Best regards,
Alex

Yes, it is not
The icon displayed depends on the state displayed
For example for a switch there is a switch.svg icon and then two more icons switch-on.svg and switch-off.svg

See: https://www.openhab.org/docs/configuration/sitemaps.html#icons

As your sitemap line displays the temperature which is somewhat independent of the AC being ofn or off, you will not be able to achieve this.

yes, thanks, this is cool but I don’t think you can use this method for section labels right? The section then controls all the other appropriate controls and info (settemp, fan speed, fan mode, etc) and using the visibility tag there to hide or show what is appropriate based on switch state.

It’s the section I’m interested in getting this to work with. I don’t mind not being able to control the ac with it since I can do that when I enter the section.

I was on my phone before but now I’m able to post a screenshot:

You can see it shows inside temperatures at a glance, and for more controls one can enter the section. But at a glance I can’t see if any aircon is on.

you get this but the answer is :sob:

You need an item that tell you if the AC is on or off. I suggest a switch Item
Post your sitemap, please
We can work with the section bit

Hi @r4m235,

you need to use two different icons! Maybe use custom icons.
I just tried it (without section) and it works. But i don´t see, why it should not work with them.
Btw. i am also using daikin ACs in my house.

Best regards,
Alex

EDIT: I just tried it - it works also with sections.

1 Like

@Casshern so you mean create 2 sections? Duplicate them and then show the appropriate one based on off state? I wasn’t aware visibility was doable with sections? Having different icons is not a problem, I can sort that :slight_smile:

@r4m235,
exactly ! It works like a charme. Thanks for the idea - i will use it here :slight_smile:

Please post your final working code, so others will understand it fully when they find this thread.

Best regards,
Alex

1 Like
Text item=OD_LRAC_tempin label="LR AirCon" icon=climate {
	// this only changes climate icon based on on/off state but doesn't show temperature in the section
        //Text item=OD_LRAC_power label="LR Aircon [%s ]" icon=climate {
		Switch item=OD_LRAC_power
		Setpoint item=OD_LRAC_settemp minValue=20 maxValue=28 step=1 visibility=[OD_LRAC_power==ON]
		Text item=OD_LRAC_tempin
		Text item=OD_LRAC_tempout
		Switch item=OD_LRAC_mode mappings=["COLD"="Cold", "HEAT"="Heat", "FAN"="Fan"] visibility=[OD_LRAC_power==ON]
		Switch item=OD_LRAC_fanspeed mappings=["AUTO"="Auto", "SILENCE"="Quiet", "LEVEL_1"="Lo", "LEVEL_3"="Med", "LEVEL_5"="Hi"] visibility=[OD_LRAC_power==ON]
		}

Holy fruit loops it works!

Thank you so much for the pointers, testing, and confirmation. I learned something new about sections and visibility and got a solution!

This is my solution, 2 sections with different icons, shown based on aircon state. Both sections include showing the temperature.:

Text item=OD_OAC_tempin label="Office AirCon" icon=climateon visibility=[OD_OAC_power==ON] {
		Switch item=OD_OAC_power
		Setpoint item=OD_OAC_settemp minValue=20 maxValue=28 step=1 visibility=[OD_OAC_power==ON]
		Text item=OD_OAC_tempin
		Text item=OD_OAC_tempout
		Switch item=OD_OAC_mode mappings=["COLD"="Cold", "HEAT"="Heat", "FAN"="Fan"] visibility=[OD_OAC_power==ON]
		Switch item=OD_OAC_fanspeed mappings=["AUTO"="Auto", "SILENCE"="Quiet", "LEVEL_1"="Lo", "LEVEL_3"="Med", "LEVEL_5"="Hi"] visibility=[OD_OAC_power==ON]
		}
	
	Text item=OD_OAC_tempin label="Office AirCon" icon=climateoff visibility=[OD_OAC_power==OFF] {
		Switch item=OD_OAC_power
		Setpoint item=OD_OAC_settemp minValue=20 maxValue=28 step=1 visibility=[OD_OAC_power==ON]
		Text item=OD_OAC_tempin
		Text item=OD_OAC_tempout
		Switch item=OD_OAC_mode mappings=["COLD"="Cold", "HEAT"="Heat", "FAN"="Fan"] visibility=[OD_OAC_power==ON]
		Switch item=OD_OAC_fanspeed mappings=["AUTO"="Auto", "SILENCE"="Quiet", "LEVEL_1"="Lo", "LEVEL_3"="Med", "LEVEL_5"="Hi"] visibility=[OD_OAC_power==ON]
		}
5 Likes

Very nice use of the sitemap.
I stand corrected

1 Like