Is there a way to display a different icon for the status of devices monitored through the Network Health binding?

Using the switch item to represent the status of items monitored through the Network Health binding has a minor problem. Since it’s displayed as a generic switch, some family members tries to use the widget to switch the devices on and off, which of course doesn’t work and only results in repeated explanations.

Ideally I would like to use something like a green/red light indicator or even a text label. I can’t find anything about this possibility so I guess either nobody thought about it or it’s simply not possible. I tend to think that it’s not possible, am I right in this case?

You can put the Switch Item on your map as a Text and use one of the icons that has an ON and OFF version. The icon to the left will use the appropriate icon based on its state and because it is put on the sitemap as Text there will be no switch toggle. You can see which icons have an ON and OFF version by looking in <openhab home>/webapps/images. Those having versions ending in “-on.png” and “-off.png” will choose the on version if the switch is on and the off version if the switch is off. And if there is an icon you want to use that instead uses open.png and closed.png you can copy those to an on and off version and the sitemap will choose the appropriate one.

You can also use the visibility option on the sitemap to not even show the Switch in cases where everything is fine and only show it when there is a problem. That is what I do.

Text item=gAlarmNet label="The entry sensors are offline!" visibility=[gAlarmNet!="ON"]

In both of the above approaches you are required to put each item on the sitemap by hand. You can’t do this using groups.

All of these options and more are documented in the Sitemap wiki page.

1 Like

That’s great I’ll sure try as soon as possible. Thank you a lot!

I found the following solution for this problem: instead of a Switch, use a Contact item like this:

Contact Presence_MyDevice "My Device" <network> (gNetwork) ["Status"] {channel="network:pingdevice:<id>:online"}

Contact items don’t have the states on / off but open / closed. So I put the following icons in my /etc/openhab/icons/classic directory:

  • network.svg: a copy of the original network.svg from openHAB
  • network-open.svg: a copy of network-on.svg from openHAB
  • network-closed.svg: a copy of network-off.svg from openHAB

Unfortunately I found out that the item states do not refresh properly when using Contact items. This is probably because the states ON / OFF are incompatible with OPEN / CLOSED.

I ended up using Number items. These are set to 0 if a devices is offline and 1 (or 1.0 to be specific) if the device is online. So I added the following icons:

  • network.svg: a copy of the original network.svg from openHAB
  • network-on.svg and network-off.svg: copies of the original icons from openHAB (to ensure compatibility with items with “proper” ON / OFF states)
  • network-0.svg for the offline state
  • network-1.svg and network-1.0 for the online state (not sure if one of those is not needed)
  • *.png versions of all icons above

Refer to this topic for instructions on where to locate the original openHAB icons.

To display the state properly as online and offline instead of 0 / 1, I installed the Map Transformation plugin and added the following map file to /etc/openhab/transform/NumberToOnlineOffline.map:

0=offline
1=online
1.0=online
=offline

Items look like this:

Number Presence_Mobile_Dave "Dave's Mobile [MAP(NumberToOnlineOffline.map):%s]" <network> (gNetwork) ["Status"] {channel="network:pingdevice:6d5264bb21:online"}

On some UIs, the icons wouldn’t change dynamically. I found out that this has to be activated explicitly that it works on all UIs as described in this post.

Finally, on the user interface it looks like this:

As a result, there are no more confusing switches, the status is shown as online or offline and the icons adapt according to the ping state.