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 originalnetwork.svg
from openHABnetwork-open.svg
: a copy ofnetwork-on.svg
from openHABnetwork-closed.svg
: a copy ofnetwork-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 originalnetwork.svg
from openHAB -
network-on.svg
andnetwork-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
andnetwork-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.