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.
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”.
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.
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)
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>").
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
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
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:
ON: