Switch that shows communication failure

I would like to make my mqtt Switch to use a 3:rd icon if by any reason a change don’t come in for a coupple of seconds. This indicates that ther are some sort of failure in the communication…

E.g. When all is OK I get this communication
2017-02-22 13:31:49.677 [ItemCommandEvent ] - Item ‘Light_S20_0885’ received command OFF
2017-02-22 13:31:49.702 [GroupItemStateChangedEvent] - Lights changed from ON to OFF through Light_S20_0885
2017-02-22 13:31:49.709 [ItemStateChangedEvent ] - Light_S20_0885 changed from ON to OFF

But is someone have unplugged my smart plug, I only get
2017-02-22 13:31:49.677 [ItemCommandEvent ] - Item ‘Light_S20_0885’ received command OFF

In this case I would like to display an icon “switch-unknown”

I have not been able to come up with a good implementation for this.
My best guess is that I have ta have a second item for each of my switches in my item file. Then write some tricky rule which is my problem for the monent.
Then use visability to hide my “real” switch in favor for the “disable” switch.
If I try to switch my disable switch, and it gets a response I change state of my “second item”, to show my real switch again…

Home.itemsSwitch Light_S20_0885 "S20_0885" (Sonoff, Lights) { mqtt=">[broker:cmnd/S20_0885/power:command:*:default], <[broker:stat/S20_0885/POWER:state:default]", autoupdate="false" } Number Light_S20_0885_Fail "S20_0885" (Sonoff, Lights) { mqtt=">[broker:cmnd/S20_0885/power:command:*:default], <[broker:stat/S20_0885/POWER:state:default]", autoupdate="false" }
Home.sitemapSwitch item=Switch Light_S20_0885 visibility=[Number Light_S20_0885_Fail =0] Switch item=Switch Light_S20_0885 icon="switch-unknown" visibility=[Number Light_S20_0885_Fail =1]
MQTT-Offline.rule
??? I have no clue how to trigger on the missing GroupItemStateChangedEvent or ItemStateChangedEvent

Does this make any sense?
Any iders on how to write the rule…?
Any other suggestions?

Have you seen the Expire binding? Allows an Item to be set to NULL if activity stops. That would rely on periodic updates from your device though.

1 Like

Yes, I have. It looked promising in the beginning, but I did have a hard time to get my ”Smart plug” to send regular updates.

So, I guess it kind of out of scope until I manage a way to get the plugs to send updates.

Have you used it?
Can you send an example of how it would look like?
Perhaps I will have another go on changing the sw in the plug…

I’ve used Expire as per the wiki, but in OH1

If you don’t get reliable updates from your devices, it is simply not possible to reliably determine failure. The best you can do is as you suspected, create a partner item to indicate failure to respond to a command…

Have a rule triggered by the real item receiving a command. That rules starts a timer, for which you must keep a global reference (handle). When the timer expires in N seconds, you have it set your partner item to indicate failure. (You might also want some cosmetic action to tidy up the state of the real item, which might be left displaying a false state for the failed command.)

Have another rule triggered by update of the real item - I’m asusming you do get feedback from the target device in response to commands. When this update is received, cancel any running timer (this is what you need the global handle for) and also unset the partner item to indicate no-failure.

On your sitemap, use visibility based on the partner item state to show a normal or broken real switch item.