Please help with rule logic

Firstly, I understand that monitoring batteries for most devices is an exercise in frustration. I wrote this rule prior to finding this out and learning about Device Activity Check. My question concerns creating a rule that does what I intended. If the battery level for a device is <= 40, then I want to receive a notification to that effect for any devices <= 40%. The problem is, the front door lock is now at 40% which triggered the rule. But the ONLY device it will report is the Porch Motion Sensor battery which is at 100%.

What do I need to do to report any devices that are <= 40%?

-Thanks

This is the explanation (and solution, should you want to continue to use this approach) for what you see:

5 Likes

Thanks. I figured out how to add the "OR" logic. But I'm still stuck. Even though the Front Door Lock is the only device at 40%, I'm still getting notifications for devices at 100%. I'm trying to get a handle on creating this logic in Rule Machine for other purposes.

-Thanks

Those need to be the triggers, not the required expressions

5 Likes

I had (have) a similar issue with a similar rule. One of about five sensors had a low battery but I’d get the notification as if it were from one of the sensors where the battery was at a normal level. It continued daily reporting different sensors until I replaced the correct battery.

It seemed that using %device% was populating the last device from those included as triggers that reported anything, rather than the one that actually sent the low battery that triggered the rule.

I never bothered to diagnose the problem at the time. It might be possible to replicate it by adding one virtual motion sensor in with the others and altering its battery level (though I’m not sure whether a virtual motion sensor has the battery level attribute?)

I think this is essentially what I interpret as happening, based on what has been explained previously. As I understand it each of the battery sensors selected will "trigger" the rule by reporting an updated battery percentage, then the rule will assess if any of the devices selected satisfy the condition defined. So for example, sensors A, B and C are selected as being "any under X%".... Battery A drops below X and the rule reports this when it happens, as would be expected. Battery B then reports a percentage, above or below X, triggering the rule to check sensors A, B and C, noticing that A is still below X, so sends the notification again, but references device B since it triggered the rule.

I could be wrong in this understanding. But would make sense to me and why separating the sensors out into separate trigger or even separate rules, or using an alternate monitoring app or approach would make more sense.

Device Watchdog (available on Hubitat Package Manager) does this well [RELEASE] Device Watchdog

3 Likes

Yes, this is correct. It has nothing to do with %device% per se; it's just a consequence of the fact that this variable gets set to the name of the triggering device (and that is what happened).

It should be noted that Device Activity Check, which the OP has already explored, can also look at battery level. It seems they are just interested in this rule behavior.

3 Likes

Yes I seem to remember this coming up previously on the forum.

I've managed to modify my rule and fix the issue - it was relatively simple:

1 Like

LOL....

If you still want to monitor the batteries one of the apps mentioned in recent discussions are more likely to be your best option.

Well, I did add the "OR" operators to the trigger. Then I deleted the trigger and for the life of me I am unable to add these OR operators again! Can someone show me how to enter events using using OR logic?

-Thanks

You don't explicitly add "OR" between trigger events. That's just the UI's way of saying that any matching trigger event will cause the rule to trigger: event 1 happening or event 2 happening or…. (You can't put trigger events together with any logic because they are events, not states, and events do not have truth values -- they just happen. See: Rule 5.1 | Hubitat Documentation for more.)

If the screenshot above is you current rule, that's exactly what you're looking for. If not, you just need to add one trigger event for each device, as mentioned above.

2 Likes

Then I guess the question is, how did the "OR" operators get there? As I said regardless of what I do I can't seem to replicate them.

-Thanks

Nevermind, I just found that Rule Machine added these OR operators AFTER I added the trigger commands. That was driving me nuts!

-Thanks

Yes, that is what I meant with this:

and is explained in the section of documentation I linked to:

And it is why the solution you found, to add each trigger event, is what I suggested to address your question:

I'd suggest reading the linked docs to learn more about RM if you haven't. Good luck!

4 Likes

Separate to the suggested solutions and reading....

It is worth noting that, if only for others that may come across this discussion... this general space in automation, being the interplay between triggers, conditions and actions, can be something that some people do genuinely struggle to grasp, if only in part. I'm not suggesting this is entirely true for you @zbernie123 , but I do think it is worth pointing out to people that it is not uncommon to struggle with some of these concepts, and that discussions like this are an example of how to engage with others in the Community and learn from others.

So, asking questions, being curious, reading the documentation and pointing out areas of confusion (in a constructive manor), all help.

Don't worry, I feel as uncomfortable as anyone with these types of posts... But I keep posting them... :thinking: Let's get back to solving problems... :slight_smile:

1 Like

Thanks again. Now back to my Geofence issue! :slight_smile:

I haven't seen anything about your issues with Geofencing, at least in your list of topics recently posted, but I'm sure you will find people happy to help you in that space as well.

Can someone explain to me why the local variable %device% is being assigned "Water Sensor - Master Bath Vanity", a device that is not included in this rule?

This is not about battery monitoring per se, I'm just trying to understand this logic.

-Thanks

Was it previously included as a trigger in this rule?

Or are the two triggers in the screenshot the only two that were ever used in this rule?

2 Likes