Xiaomi_miio xiaomi-mi-robot-vacuum battery status

I see here Xiaomi Miio - Home Assistant that the existing api doesn’t cover also getting the percentage status of the battery of the robot.
It would be very helpful to have this api available since I’m currently having issues with my S50 Roborock complaining that it can’t charge anymore after battery is 100% charged (which is kind of normal). Therefore, I manually power off the TP link Kasa plug which powers the S50.
Taking into consideration that home assistant already suppors Kasa KP115(what I have) and if Home Assistant will be able to query the battery status of the S50, I could automatically power off the KP115 when S50 battery status reaches 100%. This will also increase the battery life.

It already supports the battery percentage as an attribute.

but can I have the attribute also to be persisted?
I can’t find it in my influx and also in HA I can’t get a chart for it.

I just stumbled over this as my battery seems pretty much end of life and I would like to see this on a chart for better understanding.

You can create a template sensor form the attribute to do this.

I just started with HA.
It is not a “helper” right?
That needs to be done as yaml? Is it a function I can diretly call in the yaml?
or create an entity and use a script?
sorry … just curious to learn the leanest way here in HA.


It needs to be done in the configuration.yaml

It needs to be like this you just need use the name of your vacuum.

  - sensor:
      - name: "Vacuum Battery"
        unit_of_measurement: "%"
        state: "{{ state_attr('vacuum.roborock_vacuum_s5', 'battery_level')|int }}"

It is working for me, when I try to restart

The system cannot restart because the configuration is not valid: Invalid config for [sensor.template]: [state] is an invalid option for [sensor.template]. Check: sensor.template->sensors->vacuumbattery->state. (See ?, line ?).
In template:

        unit_of_measurement: "%"
        state: "{{ state_attr('vacuum.roborock_vacuum_a15', 'battery_level')|int }}"