Xiaomi Aqara > Battery level

Tags: #<Tag:0x00007f739bf890d8> #<Tag:0x00007f739bf88fe8> #<Tag:0x00007f739bf88f20>

Hi,

I just received xiaomi aqara devices and add it to my Home Assistant instance.
Then, I show there is a battery level indicator in HASS, so I add it to a sensor template (states.sensor.temperature_xxxxxxxxx.attributes.battery_level).

Below the graph of the this sensor :

Is this normal that the sensor battery decrease 10% in 12 hours ?
Is the reported battery level correct ?

Thanks in advance,
BDR

I’ve seen the same battery level drop in mine…

How long have your sensor been in place ? A day after the drop continue, the sensor mentionned above is now 41%. From what I’ve read the battery level isn’t sent clearly to the gateway, it’s a converted voltage.

Hi, how and where did you get the graph of this battery level. i have a few wireless buttons/switches but putting the states.sensor.[].attributes.battery_level in my groups dint work.

You have to create a template sensor for each. I am using the following code.

      battery_xiaomi_voordeur:
        friendly_name: 'Voordeur' 
        unit_of_measurement: '%'
        value_template: >
            {%- if states.binary_sensor.door_window_sensor_158d0001a1ecd5.attributes.battery_level %}
                {{ states.binary_sensor.door_window_sensor_158d0001a1ecd5.attributes.battery_level|round }}
            {% else %}
                {{ states.binary_sensor.door_window_sensor_158d0001a1ecd5.state }}
            {%- endif %}
        icon_template: '{%- if  states.binary_sensor.door_window_sensor_158d0001a1ecd5.attributes.battery_level <= 5 %}mdi:battery-outline{%- elif states.binary_sensor.door_window_sensor_158d0001a1ecd5.attributes.battery_level >= 95 %}mdi:battery{% else %}mdi:battery-{{(states.binary_sensor.door_window_sensor_158d0001a1ecd5.attributes.battery_level|float / 10)|round*10}}{%- endif %}'
1 Like

Just set an Aqara set yesterday. Most of the sensors showed 41% straight out of the box. No drop no ticked after 24 hours. How do the batteries fare in the long run?
Also, can’t find info on the type of batteries used in the door sensor. Other sensors use cr2032. Is that also the case for this sensor?

The batteries are CR1632

1 Like

Some backround to the battery level of the sub devices:

Every Aqara sub-device provides a voltage property:

[xiaomi_gateway] _send_cmd resp << {'sid': '158d00016dc0d8', 'cmd': 'read_ack', 'short_id': 14573, 'model': 'sensor_motion.aq2', 'data': '{"voltage":3005,"lux":"72"}'}
[xiaomi_gateway] read_ack << {'sid': '158d00016dc0d8', 'cmd': 'read_ack', 'short_id': 14573, 'model': 'sensor_motion.aq2', 'data': '{"voltage":3005,"lux":"72"}'}
[homeassistant.components.xiaomi_aqara] PUSH >> <Entity Illumination_158d00016dc0d8: 72.0>: {'lux': '72', 'voltage': 3005}
[homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00016dc0d8: on>: {'lux': '72', 'voltage': 3005}
[xiaomi_gateway] _send_cmd >> b'{ "cmd":"read","sid":"158d0001871038"}'
[xiaomi_gateway] _send_cmd resp << {'sid': '158d0001871038', 'cmd': 'read_ack', 'short_id': 21065, 'model': 'magnet', 'data': '{"voltage":3025,"status":"open"}'}
[xiaomi_gateway] read_ack << {'sid': '158d0001871038', 'cmd': 'read_ack', 'short_id': 21065, 'model': 'magnet', 'data': '{"voltage":3025,"status":"open"}'}
[homeassistant.components.xiaomi_aqara] PUSH >> <Entity Door Window Sensor_158d0001871038: on>: {'status': 'open', 'voltage': 3025}

This voltage is mapped to a new range: [2.8V...3.3V] -> [0...100]: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/xiaomi_aqara.py#L292-L303

>>> max_volt = 3300
>>> min_volt = 2800
>>> voltage = 3005
>>> voltage = min(voltage, max_volt)
>>> voltage
3005
>>> voltage = max(voltage, min_volt)
>>> voltage
3005
>>> ((voltage - min_volt) / (max_volt - min_volt))
0.41
>>> percent = ((voltage - min_volt) / (max_volt - min_volt)) * 100
>>> percent
41.0
>>> 

I would be happy if somebody tries to run a sensor with a laboratory power supply. Is the measurement of the sub device accurate?

7 Likes

Using node-red and github I see the following reports image. It’s reporting a battery level of 91% and 77% whilst in HA they are 61 and 33. @syssi

Just different implementations/ranges of the voltage to percentage mapping:

Guess it’s not useful at all :zipper_mouth_face:. Anyway, thanks for the time and the effort you are dedicating!

hi All folk,
I been wordering if xiaomi mi home give low battery alarm and it does give the low batt alarm for temperature sensor.
I am checking on home assistant and it shows battery level is 0. So i guess we are pretty accurate on the battery level

Thanks for this!

here’s a formula I found for calculating the battery level

Math.min(Math.round((voltage - 2200) / 10), 100);

from here: https://github.com/pierrecle/node-red-contrib-mi-devices/blob/4c8978decf996006a952588413fce228d99d6a6c/src/utils.js