Display Myopenhab cloud connection status

Sure! I am just in the migration phase to OH3.1 but I guess it will work the same way like in OH2.5.

So first of all I created a logreader thing:

And as Custom Patterns I used this string (please note the pipe-sign between the 2 strings):

Disconnected from the openHAB Cloud service|Connected to the openHAB Cloud service

I also increased the Refresh Rate from 1000 to 10000 milliseconds as this should be enough and events less than 10 seconds shouldn’t create panic.

Basically you need only 2 items - one for the custom event string and the other one is just a virtual switch to display the connection status:

String   LogReaderLastCustomEvent   "Last custom event [%s]"   <error> 
  {channel="logreader:reader:openhabcloud:lastCustomEvent"}

Switch   OpenHAB_CLOUD_connected   "OH Cloud Connected [%s]"   <network>

And a simple rule which triggers after a custom event string appeared:

rule "LogReader OpenHAB-Cloud"
when
	Channel "logreader:reader:openhabcloud:newCustomEvent" triggered
then
	if (LogReaderLastCustomEvent.toString.contains("Disconnected from")) {
		postUpdate(OpenHAB_CLOUD_connected, OFF)
		LineMessage.sendCommand ("Openhab Cloud disconnected")
	}
	if (LogReaderLastCustomEvent.toString.contains("Connected to")) {
		postUpdate(OpenHAB_CLOUD_connected, ON)
		LineMessage.sendCommand ("Openhab Cloud connected")
	}
end

!!! Please take care to NOT log the LogReaderLastCustomEvent-String with logInfo - you would run into an endless loop (trust me, I know “somebody” who did this :smiley:) !!!

Finally a small item in the sitemap:

Text item=OpenHAB_CLOUD_connected valuecolor=[=="OFF"="red",=="ON"="green"]

Here is the result:

image
image

A side note:

  • I used LineMessage which delivers a notification to my mobile as it doesn’t make sense to try sending a push notification to the Openhab mobile app via the Openhab-Cloud when it’s offline. As I am in the lucky situation of having a triple wan redundancy, I should be able to send out the notification anytime (as long as Murphy doesn’t hit me :slight_smile:). Of course you can use any other messaging tool like WhatsApp, PushSafer, PushBullet, PushOver, etc. or using a local gsm modem to send a sms.
5 Likes