Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LYWSD03MMC always shows 109% on Battery value #24

Open
Ocean-85 opened this issue Sep 20, 2020 · 1 comment
Open

LYWSD03MMC always shows 109% on Battery value #24

Ocean-85 opened this issue Sep 20, 2020 · 1 comment

Comments

@Ocean-85
Copy link

Hi,

my tempsensors always show 109% of battery which in my eys can't be correct value here, or?
msg : Object object payload: object battery: 109 temperature: 20.9 humidity: 51 address: "a4:c1:xx:xx:xx:xx" _msgid: "ef91c9b2.cf4118"

This is now shown for some month so I even don't see any change in that value.
Can you check if your using the correct hex for the battery value here?

Kind regards

Ocean

@chaosblog
Copy link

For me, it's also 109% - I'm trying to debug it, but I'm not completely sure about the code.
msg.battery = data.toString().charCodeAt(0); Line 24, xiaomi-ble.js
This part gets the battery state - but data.toString() doesn't contain any battery information for me. It contains a domain name.

const prep = typeof data === typeof 's' ? data : JSON.stringify(data.toString('hex')).replace(/\"/gi, ''); Line 58, xiaomi-ble.js gets the data which contains temperature, humidity and battery voltage in it.
Temperatue are the first two hex numbers in little endian, followed by one hex numer big endian humidity. the other two hex numbers are the voltage in mV little endian.
Example:
prep contains b8083f030c

  • b8 08 convertes to 2232 (be aware of little endian!) the display states 22.3°C - this fits the 2232
  • 3f convertes to 63, the display shows also 63%
  • -03 0c_ convertes to 3075 (also little endian!), which means 3075 mV or 3.075 V. This could be plausible because I'm using a fresh coin cell. A CR2032 coin cell has a nominal voltage of 3V.

So the doesn't report a percentage, it reports the voltage. A percentage could be calculated, based on the coin-cell discharge curve. There is already some code at zigbee-herdsman-converters which could be used for the conversion from voltage to percent.
Also it could be possible to return two battery fields, on with the percentage, one with the voltage.

I could prepare a pull request for all of that, I changed the code for me already and tested it.
But I only have LYWSD03MMC, so I can't check if my changes would work with other devices too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants