rospogrigio / airbnk_mqtt

MQTT control of Airbnk locks.
GNU General Public License v3.0
27 stars 6 forks source link

Battery level incorrect? #5

Closed formatBCE closed 2 years ago

formatBCE commented 2 years ago

My lock was showing around 29% of battery level on batteries, that have worked for ~ 8 months. Today I replaced batteries to brand new ones, and it shows 34%.

Could it be, that percentage calculation is incorrect, or maybe, lock shows incorrect level itself, and we need to adjust that?

rospogrigio commented 2 years ago

Well, that could very possibly be wrong. Actually in the original app code, the numeric value found in the advert (or FFF3 characteristic) was divided by 100, and the result shown as "voltage". I thought it was wrong, divided by 10 and called it "percentage"... but probably I was wrong. The problem here is, how do we know which voltage corresponds to 100% battery? I couldn't find anywhere (neither in the app, nor in the cloud API call results) the battery value represented as a percentage... maybe I'll check the code again.

formatBCE commented 2 years ago

Well, that could very possibly be wrong. Actually in the original app code, the numeric value found in the advert (or FFF3 characteristic) was divided by 100, and the result shown as "voltage". I thought it was wrong, divided by 10 and called it "percentage"... but probably I was wrong. The problem here is, how do we know which voltage corresponds to 100% battery? I couldn't find anywhere (neither in the app, nor in the cloud API call results) the battery value represented as a percentage... maybe I'll check the code again.

Oh, I see. That makes more sense now:

There's basically 4 AA batteries, 2x2 in parallel. So 1.5 + 1.5 = 3 V seems to be operational voltage.

There's no perfect way to convert voltage to percentage for alkaline batteries. But we may try to make something approximate.

formatBCE commented 2 years ago

From what I see for my ZigBee sensors, which have same voltage, here's some calculated percentage with corresponding voltage:

3V -> 100% 2.995V -> 97% 2.985V -> 91% 2.975V -> 86% 2.900V -> 80% 2.900V -> 73.5% (yes, on other sensor different %) 2.935V -> 62% 2.895V -> 41% 2.875V -> 38%

As you might see, quite a few fluctuations are here. However, it has some correlation too.

rospogrigio commented 2 years ago

Well, that's not so easy. My M510 has 3 x 3V batteries, so my 100% battery corresponds to 9V... How should we handle this? With different conversions depending on the lock model maybe?

formatBCE commented 2 years ago

Well, that's not so easy. My M510 has 3 x 3V batteries, so my 100% battery corresponds to 9V... How should we handle this? With different conversions depending on the lock model maybe?

Question is - do you want to bother. It could be enough to make it "voltage" back. I see plenty of posts, where people just calculate that by themselves, according to their preference.

rospogrigio commented 2 years ago

Well, it's just for my convenience, and moreover I'd like to make the data reported by the integration as similar as possible to the App. Edit: I gave a quick view at the app code, and it just compares the voltage to 4 thresholds to show 4 levels (full, 2/3, 1/3, discharged). Now I'm trying to understand where these thresholds come from.

rospogrigio commented 2 years ago

OK found them, we can get them with a call from the cloud APIs. I'll implement this soon...

rospogrigio commented 2 years ago

@formatBCE I finished the conversion from voltage to percentage: can you please test PR #6 and tell me how it works on your device? Thank you

formatBCE commented 2 years ago

Thank you. I will try it a bit later. Sorry for delay - my integration code now is changed a lot, to comply with new gateway. Merge would be painful I guess.

rospogrigio commented 2 years ago

Well, they say "no pain, no gain"... Just provide some working code and I can help with the merging. Did you succeed in operating the lock, in the end?

formatBCE commented 2 years ago

Well, they say "no pain, no gain"... Just provide some working code and I can help with the merging. Did you succeed in operating the lock, in the end?

Yes I did. :) Check main issue, there's a lot to read.

formatBCE commented 2 years ago

Battery works. Well, at least it shows 100% in my case :) Thank you.