Add-on to send events when battery is low or items offline

Your Rule is cool. Do you can help me for two things?

I have switches for LowBat all my Devices switch ON if the battery is low. But i’m too stupid to change the rule against switches.
The second rule i need is to check the status of things. I want an email if a thing goes offline. I searched and testet a lot, but i dont get an working rule for my problem.

You are going to have to be a bit more specific
What items?
What switches?
Are they in a group?

Sorry. I mean things. I want a message if a thing goes offline. I created the things via paperUI and the items via *.items file. I add a group to one item per thing for the online status.

Also I add a other group to every lowBattery Switch item. If the lowBattery switch goes ON I wanted a message too.

I hope you understand my behavior :slight_smile:

It would really help if we saw this file…

It’s just a normal items file. I created an item per channel. The first item of a thing i added a group named „gOnline“.

My first idea was to iterate all items with the group „gOnline“ and check the state, but I don’t know how I can get the thing of an item. Tomorrow I can show you the files. Actually I havent access to my pc.

There is no way to add Things to a Group. There is no way to link an Item to the Online status of a Thing.

There is a way to trigger a Rule based on the Online/Offline status of an Item. https://www.openhab.org/docs/configuration/rules-dsl.html#thing-based-triggers

Thing <thingUID> changed to OFFLINE

It is not possible to get the Thing linked to an Item as far as I know, unless you directly query the REST API from your Rule.

But Design Patterns: Generic Is Alive or even just https://www.openhab.org/addons/bindings/expire1/ might be sufficient.

I use this rule for a thing:

rule "Zwave Node5 status"
when
  Thing "zwave:device:512:node5" changed 
then

var thingStatusInfo = getThingStatusInfo("zwave:device:512:node5")

if ((thingStatusInfo !== null) && (thingStatusInfo.getStatus().toString() == "ONLINE")) {
    logInfo("ThingStatus", "ZwaveNode5 is online.")
  ZWaveNode5_status.postUpdate(ON)
} else {
    logError("ThingStatus", "ZwaveNode5 is offline or doesn't exist.")
  ZWaveNode5_status.postUpdate(OFF)

}
end

It requires a proxy item “ZwaveNode5_status”.

As Rich says, your cant group things, and you cant link an item directly to the thing status. So this is the only way I have got it to work. And you´ll have to make a simular rule as well as a simular proxy item for each thing.

Unfortunatly it´s a rule which means, when restarting openhab, and the thing is offline when the rule run, the rule will see the device as offline, and it will never change, for some reason I still havnt figured :frowning:

Because the by the time the Rules are loaded, the Thing is already offline so there is no change to trigger the Rule to run. Put another way, the Rule missed the offline event.

You would need a System started Rule to somehow query all your Things to see which ones are already offline and manage them appropriately. Though I suspect adding a System started trigger to your already existing Rule might be sufficient.

I knew it somehow had to do with the rule running while the thing beeing offline at startup… I have thought about this, I just havn´t figured how to. I dont want to change the proxy item state to online, unless the thing is actually online. Thats the part I´m seem to get stucked on.

When you add a System started trigger to that Rule, at System startup is will look at that thing and only set the related Item to ON only if it is actually marked as ONLINE. In all other cases it sets the related Item to OFF.

Like I said, just adding a System started trigger to your existing Rules will be sufficient.

Hmm so what you basicly are saying, this is the way to do it:

rule "Zwave Node5 status"
when
  Thing "zwave:device:512:node5" changed or
System started
then
...

?

Yes

That simple, and yet I didnt get it :face_with_raised_eyebrow:
I´ll give it a try… Thx Rich!