I really like to monitor things, to catch issues early on. In our home we have a couple ChromeCasts, both Audio and Video. They are all connected to the openHAB system, Once in a while they stop working, and need to be restarted (unplugged and plugged in again). Unfortunately you usually only find that out when you want to stream something, and wonder why either the ChromeCast does not show up in the device list, or does show up but does not accept the media.
Therefore I decided to monitor the devices in openHAB.
That’s quite easy, a rule can react on a status change of the
Inside of the rule any notification can be sent (email, Telegram, Pushover, …).
However more often than not the ChromeCast will only go offline for a moment. The log looks like this:
2020-01-01 00:00:42.911 [WARN ] [su.litvak.chromecast.api.v2.Channel ] - Error while reading, caused by su.litvak.chromecast.api.v2.ChromeCastException: Remote socket closed 2020-01-01 00:00:42.915 [WARN ] [su.litvak.chromecast.api.v2.Channel ] - <-- null payload in message 2020-01-01 00:00:42.937 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'ChromeCast Living Room status changed': The name 'ChromeCastStatus' cannot be resolved to an item or type; line 97, column 9, length 16
There is a blib, and the rule is triggered and will send a notification. Then a couple seconds later the Binding reconnects to the ChromeCast and everything is fine again. It would be much better if the notification is only sent if the device stays offline for a certain time. This is possible by using a Timer and a Lambda function in the rule. It also requires two rules: one for triggering the timer when the device goes offline, one for canceling the timer when the device comes online.
ChromeCast Living Room offline - timer rule will create a timer and at the end of the timer execute the inline Lambda function. If the timer finishes and was not canceled before, the inline function will send the notification that the device is offline.
ChromeCast Living Room online - timer has two jobs: if the timer is already expired, the downtime was for longer than a minute. Write this into the log. And if the timer is not yet expired, cancel the timer - because the device is online again and no notification is required.