On Sitemap R/O Switch with Dynamic Icon?

Tags: #<Tag:0x00007f1737bb4590> #<Tag:0x00007f1737bb44c8> #<Tag:0x00007f1737bb4400>

hi,

I am running OpenHAB2 on Raspbian.

I have a thing which prints “0” or “1” (through MQTT) for it’s state. No write commands possible (read-only state).

I would like to see this on my sitemap with the “” icon showing in green if it is 1 and red if it 0 (~off).

If I configure my sitemap entry as switch this works really fine. Exept if offers to change the value (which will not have any effect because it is r/o). It would be perfect to have a switch configured which does not allow to change values.

How can I get to this?

Thanks!

/KNEBB

Use a Text widget? You might need to add [%s] to your state description to get a textual display instead of switch widget.

Sorry, this is unclear to me. What do you mean with “widget”?

What should I change? Item? Thing? Sitemap-Entry?

And how?

/KNEBB

Hi,

just to make it clear:

This is how it looks currently. Fine so far. But I would like to have the red switch icon when the text is “0” and to see the green icon when it is “1”.
grafik

Where do I need to reconfigure?

Thanks!
/KNEBB

By widget, I mean the sitemap line that displays your Item

Can we know what type of Item you have, definition? What the current sitemap line is?

Hi,

that’s the line currently:
Text item=Heizung_r_wp label="Heizung - Relais Wärmepumpe"

I have read the doc but I did not see any entry how to do this…

/KNEBB

Perhaps you are after dynamic icons?

Yeah, I have seen these dynamic icons. But they are for Switches and change when I switch to OFF (or ON). But I have a read-only item which I can not switch. So it should not be switchable on the GUI, either. Therefore I can not use a switch item.

/KNEBB

You have to also show the item definition. Is it a switch, number or string? The type of the item is one concept, while the display on the sitemap is a different concept (you can have a switch type item displayed as text or as switch on a sitemap)

Hi,

ok, I tried a little bit and got further.

When I configure my item as “Contact” (which is really the closest type) and do NOT configure any icon on the widget I am getting the window icon which opens or closes according to the item state.

This is the item now:
Contact Heizung_r_ehzg "Heizung - Relais Elektroheizung" { channel = "mqtt:topic:17ed64b6:hzg_r_ehzg" }

And this the widget config in sitemap:
Text item=Heizung_r_ehzg label="Heizung - Relais Elektroheizung"

If I add “icon=“switch” to the widget configuration I am getting the switch icon, but it is not dynamically. Same applies when adding the icon definition to the item (”<switch>").

/KNEBB

Contact may have values CLOSED or OPEN. While a switch have ON or OFF. A dynamic icon require that exact values appended to the name.
There are a number of default dynamic icons in OPENHAB but not all possible combinations are available by default.
You can display a dynamic icon by placing two icon files in the icons/classic folder. The files should be named switch-closed.png and switch-open.png. You simply have to find where the switch-off and switch-on icon files are located.

Hi,
this is how i solved a similar problem with phones:
Phone items declared as switches

Switch IIP_120_PING “Phone 2” (OVR_002_PRESENCE_2, GRP_006_PRESENCE_NOOVR) { channel=“network:pingdevice:IP_120_PING:online” }
Switch IIP_121_PING “Phone 1” (OVR_001_PRESENCE_1, GRP_006_PRESENCE_NOOVR) { channel=“network:pingdevice:IP_121_PING:online” }
Switch IIP_122_PING “Phone 3” (OVR_003_PRESENCE_3, GRP_006_PRESENCE_NOOVR) { channel=“network:pingdevice:IP_122_PING:online” }
Switch IIP_123_PING “Phone 4” (OVR_004_PRESENCE_4, GRP_006_PRESENCE_NOOVR) { channel=“network:pingdevice:IP_123_PING:online” }

sitemap frame with the items declared as text:

Frame label=“Phones” {
Text item=IIP_120_PING icon=“contact_green_no”
Text item=IIP_121_PING icon=“contact_green_no”
Text item=IIP_122_PING icon=“contact_green_no”
Text item=IIP_123_PING icon=“contact_green_no”
Text item=IIP_153_PING icon=“contact_green_no”
Text item=IIP_155_PING icon=“contact_green_no”
}

and 3 icons in the icon\classic folder named:

contact_green_no.svg
contact_green_no-on.svg
contact_green_no-off.svg

and this is the result:

2 Likes

Minor quibble - advise against re-using the filename of an existing built in icon for a new custom icon set. Recommend instead new filenames, like myswitch-open.png
Don’t forget you also always need a default image to complete a set myswitch.png

Hi @aRGiRob ,

works like a champ now!

I needed to create the channel within MQTT as switch, too. Once done I linked it as you suggested to a switch item:
Switch Heizung_r_uwp "Heizung - Relais Umwälzpumpe" { channel = "mqtt:topic:17ed64b6:hzgr_uwp" }

and added a text widget to the sitemap by using the build-in icon for a switch:
Text item=Heizung_r_uwp icon="switch"
OFF:
grafik
ON:
grafik

Thanks for helping!

/KNEBB