[SOLVED] Check if Shelly device is online?

Hello…
Is it possible to check if a Shelly device is online?

I am using Openhab 2.5.3 with an MQTT broker. The Shellies send their MQTT messages to the broker.
When i turn on the shellies sends
/ shellies / device / online: true

I am using some shelly plugs and want to know if the plug is offline and display it via sitemap.

How do i manage this?

Thanks
Andre

Network binding.

Shelly binding with things created.

I think your solution is to ping the Shelly device every x minutes? But how do this work on more than 6 Plug devices? Must i create for each device a rule or something else?
And how is the evaluation by a rule?
Do you have an example?

@hmerk
How does it work?
I create an mqtt.thing for the Devices and switch on the Mqtt feature in the Shelly. Will the Mqtt and Shelly Binding work together? I work with the Files and not with the PaperUI… :man_shrugging:

You can put all your pingable Items in a Group, and trigger one rule from the Group.
What do you want to happen when one goes offline?

If you use the Shelly Binding, there is no need to use MQTT for them at all. But both would work parallell. You can configure the Shelly binding Things via config files as well.
Using the Shelly Binding, you can create a rule to check if the Thing is ONLINE or OFFLINE.

I want to display it on a sitemap of the Device by a color changing point
red for offline
green for online
to make status visible.

Okay, so have your rule postUpdate the text to some Item
Display the Item using colour options -

1 Like

I have done this myself and will post an example later tonight or tomorrow.
It is not that difficult.

  1. Create dummy items to hold the state.
  2. Create a rule for each thing you want to monitor, triggered by change to offline and post update to according dummy item.
  3. Create Sitemap entrys with visibility pattern.

Ok, here we go:

Things:

Thing shelly:shelly2-roller:559470 "Dachfenster" @ "Arbeitszimmer" [ deviceIp="192.168.0.180", coap="true", eventsRelayButton="false", eventsRelaySwitch="false", eventsCoIoT="true" ]
Thing shelly:shellyflood:68fa6f "WasserSchaden" @ "Waschküche" [ deviceIp="192.168.0.187", coap="true", eventsSensorReport="false", eventsCoIoT="true" ]

Dummy-Items and Group:

Group:Switch:OR(OFF, ON) 	DeviceHealth	"Gerätestatus [(%d)]"	<status>	(All)

Switch FloodLaundryHealth		"Shelly Flood Waschküche"		(DeviceHealth)
Switch ShellyWindowOfficeHealth		"Fensterantrieb Arbeitszimmer"		(DeviceHealth)

Map-Transformation "health.map"

OFF=OFFLINE
ON=ONLINE
NULL=undefiniert

Rules

val mailActions = getActions("mail","mail:smtp:xxxx")
rule "ONLINE/OFFLINE Alert"
	when
		Member of DeviceHealth changed
	then
		if (triggeringItem.state == OFF) {
			var message = triggeringItem.label + " ist OFFLINE"
			//sendBroadcastNotification(triggeringItem.label + " ist OFFLINE")
			mailActions.sendMail("xxx@xxx.dd", "openHAB Gerätealarm", message)
		}
end

rule "Dachfensterantrieb Arbeitszimmer Health"
	when
		Thing "shelly:shelly2-roller:559470" changed
		then
			var message = "Shelly Dachfensterantrieb ist " + getThingStatusInfo("shelly:shelly2-roller:559470").getStatus.toString()
			logInfo("shelly2-roller:559470", message)
			if (getThingStatusInfo("shelly:shelly2-roller:559470").getStatus.toString() == "ONLINE") {
			ShellyWindowOfficeHealth.sendCommand(ON)
			} else {
			ShellyWindowOfficeHealth.sendCommand(OFF)
			}
end
rule "ShellyFlood Health"
	when
		Thing "shelly:shellyflood:68fa6f" changed
		then
			var message = "ShellyFlood ist " + getThingStatusInfo("shelly:shellyflood:68fa6f").getStatus.toString()
			logInfo("shellyflood:68fa6f", message)
			if (getThingStatusInfo("shelly:shellyflood:68fa6f").getStatus.toString() == "ONLINE") {
			FloodLaundryHealth.sendCommand(ON)
			} else {
			FloodLaundryHealth.sendCommand(OFF)
			}
end

Sitemap, showing Status if at least one Thing is offline

Group item=DeviceHealth label="Geräte Alarme" icon="status" visibility=[ DeviceHealth==OFF]{
	Text item=FloodLaundryHealth label="ShellyFlood Waschküche [MAP(health.map):%s]" icon="status" visibility=[ FloodLaundryHealth==OFF]
	Text item=ShellyWindowOfficeHealth label="Dachfenster Arbeitszimmer [MAP(health.map):%s]" icon="status" visibility=[ ShellyWindowOfficeHealth==OFF]
}

Alternative Sitemap, showing status all the time :

Text item=FloodLaundryHealth label="ShellyFlood Waschküche [MAP(health.map):%s]" icon="status" valuecolor=[OFF="red"] visibility=[ FloodLaundryHealth==OFF] 
Text item=FloodLaundryHealth label="ShellyFlood Waschküche [MAP(health.map):%s]" icon="status" valuecolor=[ON="green"] visibility=[ FloodLaundryHealth==ON]
Text item=ShellyWindowOfficeHealth label="Dachfenster Arbeitszimmer [MAP(health.map):%s]" icon="status" valuecolor=[OFF="red"] visibility=[ ShellyWindowOfficeHealth==OFF]
Text item=ShellyWindowOfficeHealth label="Dachfenster Arbeitszimmer [MAP(health.map):%s]" icon="status" valuecolor=[ON="green"] visibility=[ ShellyWindowOfficeHealth==ON]

Thanks. I will give this an try and report the result…

Hi Hans-Jörg,
I notice in your examples here as well as in the “Shelly Binding” thread, that you have additional coap="true" in your thing definitions, e.g:

What is this needed for? Isn’t eventCoIoT="true" sufficient already?

This is just a leftover and can be igored, doesn‘t harm either.
It was needed before Markus made it a default.

O.k. makes sense.
Thanks for clarifying!

Hi I solved this problem with your help. Thanks! For anybody how search for something similar here my solution:
I use the Networkbinding and do a ping from this binding.

The network.things:

network:pingdevice:1_device "PlugS-01" [ hostname="192.168.xxx.yyy", retry=1, timeout=5000, refreshInterval=60000 ]
network:pingdevice:2_device "PlugS-02" [ hostname="192.168.xxx.yyy", retry=1, timeout=5000, refreshInterval=60000 ]
network:pingdevice:3_device "PlugS-03" [ hostname="192.168.xxx.yyy", retry=1, timeout=5000, refreshInterval=60000 ]
network:pingdevice:4_device "PlugS-04" [ hostname="192.168.xxx.yyy", retry=1, timeout=5000, refreshInterval=60000 ]
network:pingdevice:5_device "PlugS-05" [ hostname="192.168.xxx.yyy", retry=1, timeout=5000, refreshInterval=60000 ]
network:pingdevice:6_device "PlugS-06" [ hostname="192.168.xxx.yyy", retry=1, timeout=5000, refreshInterval=60000 ]

Here The network.items

Group:Switch:OR(OFF, ON) 	DeviceHealth	"Gerätestatus [(%d)]"	<status>	(All)

Switch 1_device		"online"		(DeviceHealth) { channel = " network:pingdevice:1_device:online " }
Switch 2_device		"online"		(DeviceHealth) { channel = " network:pingdevice:2_device:online " }
Switch 3_device		"online"		(DeviceHealth) { channel = " network:pingdevice:3_device:online " }
Switch 4_device		"online"		(DeviceHealth) { channel = " network:pingdevice:4_device:online " }
Switch 5_device		"online"		(DeviceHealth) { channel = " network:pingdevice:5_device:online " }
Switch 6_device		"online"		(DeviceHealth) { channel = " network:pingdevice:6_device:online " }

The net_status.rules
aktually there is only a Info in the Logfile written. later more…

rule "ONLINE/OFFLINE Alert"
	when
		Member of DeviceHealth changed
	then
		if (triggeringItem.state == OFF) {
			var message = triggeringItem.name + " ist OFFLINE"
			logInfo("RULE", "--> Geräte status: "+ message)
		}
		if (triggeringItem.state == ON) {
			var message = triggeringItem.name + " ist ONLINE"
			logInfo("RULE", "--> Geräte status: "+ message)
		}
end

An the
Sitemap
the code is shortened

sitemap plug_s label="Plugs " {
    	Text item=1_device label="Plug 01 [MAP(health.map):%s]"  valuecolor=[OFF="red"] visibility=[ 1_device==OFF] 
	Text item=1_device label="Plug 01 [MAP(health.map):%s]"  valuecolor=[ON="green"] visibility=[ 1_device==ON] 
	{
    
            Frame label="Plug 01" 
			{
                Default item=Plug_S_01_relay label="Plug_S_01 Ein / Aus "
                Default item=Plug_S_01_power label="Leistung"
                Default item=Plug_S_01_energy label="W Zähler"
            }
            Frame label="Leistung"
			{
					Switch item=Chart_Zeitraum_D_W_M_Y label="" mappings=[0="Stunde", 1="12 h", 2="Tag", 3="Woche", 4="Monat"]
					Chart item=Plug_S_01_power period=h refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==0, Chart_Zeitraum_D_W_M_Y=="Uninitialized"]
					Chart item=Plug_S_01_power period=12h refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==1]
					Chart item=Plug_S_01_power period=D refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==2]
					Chart item=Plug_S_01_power period=W refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==3]
					Chart item=Plug_S_01_power period=M refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==4]
			}
			Frame label="Temperatur"
			{
					Chart item=Plug_S_01_temp period=h refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==0, Chart_Zeitraum_D_W_M_Y=="Uninitialized"]
					Chart item=Plug_S_01_temp period=12h refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==1]
					Chart item=Plug_S_01_temp period=D refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==2]
					Chart item=Plug_S_01_temp period=W refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==3]
					Chart item=Plug_S_01_temp period=M refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==4]
			}
	}
	
	//Text label="Plug_S : Plug 03" 
		Text item=3_device label="Plug 03 [MAP(health.map):%s]"  valuecolor=[OFF="red"] visibility=[ 3_device==OFF] 
		Text item=3_device label="Plug 03 [MAP(health.map):%s]"  valuecolor=[ON="green"] visibility=[ 3_device==ON]
		{
    
            Frame label="Plug 03" 
			{
                Default item=Plug_S_03_relay label="Plug_S_01 Ein / Aus "
                Default item=Plug_S_03_power label="Leistung"
                Default item=Plug_S_03_energy label="W Zähler"
            }
            Frame label="Leistung"
				{
					Switch item=Chart_Zeitraum_D_W_M_Y label="" mappings=[0="Stunde", 1="12 h", 2="Tag", 3="Woche", 4="Monat"]
					Chart item=Plug_S_03_power period=h refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==0, Chart_Zeitraum_D_W_M_Y=="Uninitialized"]
					Chart item=Plug_S_03_power period=12h refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==1]
					Chart item=Plug_S_03_power period=D refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==2]
					Chart item=Plug_S_03_power period=W refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==3]
					Chart item=Plug_S_03_power period=M refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==4]
				}
			Frame label="Temperatur"
				{
					Chart item=Plug_S_03_temp period=h refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==0, Chart_Zeitraum_D_W_M_Y=="Uninitialized"]
					Chart item=Plug_S_03_temp period=12h refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==1]
					Chart item=Plug_S_03_temp period=D refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==2]
					Chart item=Plug_S_03_temp period=W refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==3]
					Chart item=Plug_S_03_temp period=M refresh=60000 service="rrd4j" visibility=[Chart_Zeitraum_D_W_M_Y==4]
				}
		}

}

The Transform Map is as like the map from hmerk.

Look of the Sitemap:

Thanks again…
And I hope I can help someone with that too…