Battery level event subscriptions

I have tried several ways to get accurate battery level warning but they all failed. It sounds like the:

sendEvent(name: "battery", value: 45)

works once in the odd time only. Yes, I have hard coded this line to test this. But now, that I'm using the influxDB logger, it became obvious that the event is not always catched by the system. The influxDB logger will log every event it catches through the handleEvent function. The very first line in that function is to log the event. I can manually run this sendEvent line above and the influxDB logger might catch this event only in the odd times. Sometime, i may run that line 20 times before one of them goes through. That explains why the notification about the battery low only reported sometimes.

I would really like to get this bug solved and I can help testing this if you like. I have about 20 battery devices so it's kind of easy to see the problem.

What device are you using? It sounds like a custom driver? It sounds like you may have forgotten to declare the Battery capability. The behavior for undefined attributes is not defined, but user experiences suggests it displays for a bit but does not persist on device page reload, and I have no idea whether an event is actually generated.

1 Like

If you ran it 20 times it would only trigger once since the value is the same. Events only “fire” if the value is different. Add isStateChange: true and I bet it gets caught every time.

2 Likes

Yes it does have the Battery capability. But this is consistent on all the drivers.... it is the battery event that is the problem. But I used a custom driver so I can change things around for testing. I use the ikea blind driver.

But I think @dman2306 might have the solution....

That sounds like it. Not sure where to add this, but I’ll find it. Thanks.

You’d have to add it whenever the event is raised. But why do you want to do this? If the battery is t changing what are you trying to learn? This will likely increase the size of your db significantly

1 Like

@dman2306, i also found this in the same line of idea...

options - Optional values to configure the subscribe. Possible values:

filterEvents - Used for device subscriptions. Set to false to receive all events, defaults to true and events that do not have a changed value will not be processed.

Actually, the decision to say that the « battery level changed or not » does not belong to the « sender ». It belongs to the « receiver ». I’m using the dblogger (the receiver) to log the battery level. It is up to it to check if the last valu received was already in its logs.

Also, my need was mainly for the ikea blinds. They are sending the battery level so rarely that i had to create an RM to request the battery level every night.

A big thanks @dman2306 for the idea. The problem was in the dblogger when subscribing to the event. I just changed the line to:

subscribe(devs, attr, handleEvent, [filterEvents: false])

That solved the problem.

Please note this is NOT the model HE follows and many drivers will not even send an event if the value didn’t change so what you put in place here will work with some devices it will not work with others.

How about using the built-in Notifications app? It can be set up to catch battery events below a specific threshold.

1 Like