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

Battery value problem #108

Closed
ciotlosm opened this issue Jun 9, 2018 · 10 comments
Closed

Battery value problem #108

ciotlosm opened this issue Jun 9, 2018 · 10 comments

Comments

@ciotlosm
Copy link
Contributor

ciotlosm commented Jun 9, 2018

I see the battery value is calculated based on fixed values. My buttons show 100% and I'm sure that is not true. While this is a possible approach, I've checked smartthings and it seems they somehow get battery directly from zigbee messages?

https://github.com/a4refillpad/Xiaomi/blob/master/devicetypes/a4refillpad/xiaomi-zigbee-button.src/xiaomi-zigbee-button.groovy

@Koenkk
Copy link
Owner

Koenkk commented Jun 9, 2018

What is the voltage of your battery? (it should report that together with the battery %)

@ciotlosm
Copy link
Contributor Author

ciotlosm commented Jun 9, 2018

3015 which is correctly calculated to 100%, but that can't be. I will pair this device with my gateway and see what battery % does it report.

@ciotlosm
Copy link
Contributor Author

ciotlosm commented Jun 9, 2018

Using the gateway with exact same device I get battery level 43

@Koenkk
Copy link
Owner

Koenkk commented Jun 9, 2018

so it seems that the gateway calculates the percentage with a different algorithm. We have to check at what voltage a new battery starts and at which points it stops working.

@ciotlosm
Copy link
Contributor Author

ciotlosm commented Jun 9, 2018

Is there no way to get inspiration from the smartthings setup? How did @kirovilya extract battery %?

@ciotlosm
Copy link
Contributor Author

ciotlosm commented Jun 9, 2018

it seems xiaomi_aqara component that was reporting my value also calculates it:

    def parse_voltage(self, data):
        """Parse battery level data sent by gateway."""
        if 'voltage' not in data:
            return False
        max_volt = 3300
        min_volt = 2800
        voltage = data['voltage']
        voltage = min(voltage, max_volt)
        voltage = max(voltage, min_volt)
        percent = ((voltage - min_volt) / (max_volt - min_volt)) * 100
        self._device_state_attributes[ATTR_BATTERY_LEVEL] = round(percent, 1)
        return True

@Koenkk
Copy link
Owner

Koenkk commented Jun 9, 2018

It uses a different range so that explains it. We have to do some test what the value is when we put in a new battery.

@ciotlosm
Copy link
Contributor Author

ciotlosm commented Jun 9, 2018

Agree. But for transition would be nice to have it consistent. Our range is wrong anyway because we have 3000 as 100% and I already have on a used battery 3015.

I recommend we adopt the xiaomi_aqara component approach and do more math when getting a new battery.

@kirovilya
Copy link
Contributor

Hello. Earlier, I considered the percentage here according to this formula:
= (battery - 2700) / 5
this means that the maximum value of voltage is taken 2700 + 500 = 3200

@ciotlosm
Copy link
Contributor Author

I've created Koenkk/zigbee-herdsman-converters#13 to improve a bit, but we can readjust once we have more samples and details.

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

3 participants