Have one item drive icon behavior for a different item

  • Platform information:
    • Hardware:Raspberry Pi 2
    • openHAB version: 2.1

I was wondering if it was possible to use one item to control an icon or something on another items sitemap entry. My lighting system has pushbuttons with LEDs in them. The LEDs don’t necessarily relate to a particular load’s condition and need to be accounted for independently. I am able to code switches and LEDs as items, but I would like the sitemap indicator on a sitemap switch to reflect what the real physical indicator is on the real physical switch. I can get it to work if I use 2 separate item entries on the sitemap, but was hoping there was a way to use just one entry. I tried changing the text color, but for some reason, I need to hit the browser refresh for it to work properly. Can this be done?

Thanks,
Tim

//The code below works fine without having to hit the browser refresh - it uses 2 different entries which are placed side-by-side
Switch item=kp12sw0 icon="none" labelcolor=["black"] mappings=[1="P/R", 2="P/H", 3="Rel"]
Text item=kp12led0 icon="light" label=""

//The code below does not work unless the browser window is refreshed, at which point it works.  It seems that changes to kp12led0 state does not cause an automatic browser refresh.
Switch item=kp12sw0 icon="none" labelcolor=[kp12led0==OFF="black", kp12led0==ON="green"] mappings=[1="P/R", 2="P/H", 3="Rel"]

This cannot be done directly. The closest you can get is to use the visibility element in the sitemap and show the switch with the right icon and hide the rest.

For example, here is how I show the garage door open/closed icon for the separate Switch Item I use to trigger the door to open/close:

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

Since the icon is not related to the state of the Item you are showing, you cannot use dynamic icons so you might have to make copies of the icons you want.

The Items that start with a are the actuators (i.e. they cause the door to open/close). Those that start with v are the sensors (i.e. report when the door is open or closed.

1 Like

Thanks Rich. Your suggestion worked great for the chrome browser. Funny thing, is it doesn’t work for the IOS App. It needs to be refreshed. Also, different font colors don’t work for the app as well.

Tim

Just wanted to say thanks, this works for me. I have a virtual item that controls the heating with mappings “ON”, “OFF” and “AUTO”, but I would like icon to show whether the physical heater item is “on” or “off” whilst virtual item is in AUTO.
Meaning, virtual item needs to show icon state independent of its own state, but based on another item.
I had to copy icons (in .png so that they would show in android app).

Accomplished by

Switch item=RuleAutoHeatingLivingroomOven label=“Heating” icon=“heatingison” mappings=[“ON”=“On”, “OFF”=“Off”, “AUTO”=“AUTO”] visibility=[LivingroomWallHeater_Switch==“ON”]

Switch item=RuleAutoHeatingLivingroomOven label=“Heating” icon=“heatingisoff” mappings=[“ON”=“On”, “OFF”=“Off”, “AUTO”=“AUTO”] visibility=[LivingroomWallHeater_Switch==“OFF”]