Howto create battery alert without creating a template for every device


Yeah thats the version i had, after a restart of hass the other automations showed up and only 1 of my sensors. Now the next morning i see all my sensor battery levels there thanks!


I’ve got the same problem: no battery stats on PIRs, just on the illuminance part.


Sorry, I haven’t had any free time to work on home automation in a while. This is still on my todo list. I hope to resolve it soon.

You shouldn’t need to do that. The package should create separate sensor for each device that has a battery_level attribute. That sensor is the one that will be included in the group.

There is nothing special about Just follow the instructions in the package file on github.

Can you post a screenshot of the kitchen door sensor from the states page? I need to see the attributes to identify a cause.

Can you provide more info on the sensor? How was it created? Can you post a screenshot from the states page so I can see the state and attributes?

You just need to clear the mqtt topics. Copy the topic names from the attibutes of the sensor and paste them into the MQTT Topic to Clear input_text box.


No problem, you cant always work on home automation (sadly).
I was diggin around in the code in hope to find something that might solve my problem (the value beeing 2 insteak of 2.4 and therefore the battery_template doesnt work…)
Does it maybe have to do something with the value needing “value | int” somewhere??

  battery_template: '{%- if value | int < 2,4 -%} "Low" {%- else -%} "Full" {%- endif -%}'

instead of

  battery_template: '{%- if value < 2,4 -%} "Low" {%- else -%} "Full" {%- endif -%}'

but maybe this is just all wrong…

Like I said above, if I can help you with anything here let me know


Thanks for understanding. I think I may have found the culprit. Can you try the updated version I just checked? I don’t have any sensors that use floats, so I don’t know for sure if this is the only issue. To access the float value, you’ll have to leave the battery_template on the sensor like you’ve got.

Edit: Try this template with the above package.

{%- if value_json.value | float < 2.4 -%}
{%- else -%}
{%- endif -%}


Can you try the latest version to see if that eliminates the error?


I will try right away, just two questions:

  1. should I remove all the created battery sensors that have the problem we are talking about before using the new version?
  2. sry to ask again, but which entity gets the battery_template in customize.yaml? the original one (in my case a thermostat) or the created battery sensor that got created out of the thermostat from your automations?

from customize.yaml :

sensor.kuche_heizung_battery: # this is the battery sensor
  battery_template: '{%- if value < 2.4 -%} "Low" {%- else -%} "Full" {%- endif -%}'
climate.oeq1709806: # this is the thermostat
  friendly_name: Küche Heizung
  battery_template: '{%- if value < 2.4 -%} "Low" {%- else -%} "Full" {%- endif -%}'


You shouldn’t need to.

On the thermostat entity.

climate.oeq1709806: # this is the thermostat
  friendly_name: Küche Heizung
  battery_template: '{%- if value_json.value | float < 2.4 -%} Low {%- else -%} Full {%- endif -%}'


@walaj, and @pdobrien3, I just found and fixed the issue causing TypeError: object of type 'NoneType' has no len(). Please try the latest code and let me know if you still see the errors.

@Nightcat, please update to this latest version. The fix for the error mentioned above may help your issue as well.


thanks for the fast update, I installed the lastest version ( 1.1.4 )

It fixed my problem of getting a 2% sensor, it now shows full!!
But I got some strange notification about an unknown device having low battery, I will dismiss that and see if it comes back again…
I dont have any other batteries that would trigger a notification right now…


Just a few more minor things:
Would it be possible to adjust the icon from those battery sensors now, just showing a full battery and an almost empty one and not the icon with the “?” in it??
clicking on one of them shows me a graph with a value… I dont know where that value is coming from since the battery sensor does not have a value shown on the state screen, and it shows “2” again, instead of the actual 2.6V
And could you remove the “%” after the “Full” on those sensors??


Here are the MQTT messages, I dont know if you need them, might help:

  "device_class" : "battery",
  "name" : "Arbeitszimmer Heizung Battery",
  "state_topic" : "homeassistant/sensor/oeq1710001_battery/state",
  "unit_of_measurement" : "%",
  "value_template" : "{%- if value_json.value | float < 2.4 -%} Low {%- else -%} Full {%- endif -%}",
  "unique_id" : "oeq1710001_battery",
  "json_attributes" : [ "entity_id", "attribute", "mqtt_config_topic", "mqtt_state_topic" ]


“entity_id”: “climate.oeq1710001”,
“attribute”: “battery”,
“mqtt_config_topic”: “homeassistant/sensor/oeq1710001_battery/config”,
“mqtt_state_topic”: “homeassistant/sensor/oeq1710001_battery/state”


Woohoo! Glad to hear it.

Can you look at the Battery Status group to see if you see those entities there. Some screenshots of the group would help troubleshoot the issue.

Ahh. I know what’s causing that. I just need to adjust the config payload to handle string states to fix that. I’ll update the package to support that. Hopefully tomorrow…


I dont see any unknown entities…
but so far the notifications havent returned… so it might have been a one time only thing…

Could you also have a look at those two things if they are easy to change? No hurry!


I’ve got templates that return strings working now in the 1.1.5 release. You’ll need to change the attribute name in the customize section from battery_template to battery_template_string.

To fix the issue with the chart, try clearing the retained messages and restarting Home Assistant.

climate.oeq1709806: # this is the thermostat
  friendly_name: Küche Heizung
  battery_template_string: '{%- if value_json.value | float < 2.4 -%} Low {%- else -%} Full {%- endif -%}'


Did you get this resolved? I’ve just installed 1.1.5 and get the same thing. None of my customizations are working.

  battery_sensor_creation_disabled: true

  battery_sensor_creation_disabled: true

  battery_sensor_creation_disabled: true

  battery_sensor_creation_disabled: true

## Adjust Xaiomi Battery Levels x 150% ##
  battery_template: "{{ value_json.value | int * 1.5 }}"

  battery_template: "{{ value_json.value | int * 1.5 }}"

  battery_template: "{{ value_json.value | int * 1.5 }}"

  battery_template: "{{ value_json.value | int * 1.5 }}"


Those customizations need to be on the parent device that has the battery attribute.


Hi @xbmcnut,

like @NotoriousBDG said all those “battery_sensor_creation_disabled: true” and "battery_template: “{{ value_json.value | int * 1.5 }}” need to be set at the original device and not the battery sensor that was created by the package…

Are you adjusting the battery levels on all xiaomi devices? Cause I have a few door and window sensors and some of the Gen1 Buttons (round) and I also noticed that the battery levels never started around full (>80%) but rather low (starting around 50-60%).


@Nightcat @NotoriousBDG

I’ve done this to test:

  battery_sensor_creation_disabled: true

## Adjust Xaiomi Battery Levels x 2 ##
  battery_template: "{{ value_json.value | int * 2 }}" 

But the office Xaiomi switch still shows a battery level and the Xaiomi Landing smoke detector still shows the same battery percentage. And yes, I intend to tweak all of my Xaiomi sensors so I can set my min level to a realistic value for all battery levels of say 70% as I’m getting flooded with notifications at the moment.




Verify that you see battery_sensor_creation_disabled: true as an attribute on your states page for switch.plug_158d0001dc3a20. If it’s there, you’ll need to clear the retained MQTT messages. Copy / paste the values of mqtt_state_topic and mqtt_config_topic attributes into the MQTT Topic to Clear input text box, and it should go away. It should look like this:

For binary_sensor.smoke_sensor_landing, your screenshot shows that the battery_template attribute hasn’t been created. Have you restarted Home Assistant after making the change? It should look like this:


Thanks for your help. Getting there. Must have missed a restart for the smoke detector!


Might need some rounding to get the value correct though?

In regards the Xaiomi office switch, I put the config topic into MQTT topic to clear and hit enter (is that all I do?) and also the state topic and then restarted HA. It now appears as unknown.





@NotoriousBDG - running it now - will update in a day or so, but no issues thus far.

many many thanks.