Howto create battery alert without creating a template for every device

In the code I shared the line that says “self.get_state()” gets the state and attributes of every entity in all of Home Assistant. The rest of the code flips through them looking for battery attributes and such.

1 Like

That sounds great, very keen to try it out.
Now for the fun part, how on earth do I batch delete this component and all the battery sensors it’s created?

I tried deleting the package but all that does is ungroup all the sensors and everything becomes a mess…

What I did to uninstall:

  1. Remove package
  2. Using MQTTExplorer, delete all retained messages
  3. Edit Lovelace and remove battery related entities

Not sure if this is all that’s needed though?

1 Like

That worked great, thanks!
Now time to try appdaemon, worse comes to worst and I have difficulties with it, I can install this package every few months to get an update on my sensor batteries then remove again :slight_smile:

The Xiaomi and Hue sensors seem to last for ever!

Hello, first off all, thanks NotoriousBDG for the work.
This battery thing is something very usefull into HA.
I tried to install but i didn’t succeed.

What is did:
I’m using Hassio

  • Install the official addon: Mosquitto broker
  • Start it.
  • Created a user for mqtt
  • Added it with “Integrate” (i did not have to full in the username and password)
  • Added the battery_alert.yaml to the packages folder
  • Restart

This i what happened in HA:
A group created.

Nothing else happened, i don’t have the sensors in HA now that wil show the battery level from my devices.
Did i do something wrong?
Is my mqtt not working as it should be?

Scrolled back in this topic but i did not find the answer.

Thanks

Lovelace wont automatically add the items.

look into “group-card” - Howto create battery alert without creating a template for every device

Can someone help me?

Only you would be able to figure out which devices are which, but if I had to guess, you might have tried the Home Assistant iOS beta app on one or more devices. The iOS beta app uses the “Battery Level” name by default unless you change it.

You can rename this easily from the UI. Go to Configuration -> Integrations -> Mobile App: Stefano’s iPhone (or whatever it might be called). Find the “sensor.battery_level” and then rename it like this:

Then it should not show up as duplicated. Hope this helps.

Created the group-card.js.
And added it to my lovelace page.
The battery sensors, should they be created automatically now?

Tnx

card:
  show_header_toggle: false
  title: Battery Status
  type: entities
group: group.battery_status
type: 'custom:group-card'

It’s working! Had to wait a little for the battery entities to show up one by one.

Tnx!! :smile:

Thanks a lot for your help!!
Sorry for my late response but i’m In vacancy!! :slight_smile:
I have also other duplicated sensor how can I hide or delete the other sensor?
It’s seems that the script have make the battery sensor for all my devices so can read the Battery value from my sensor and the battery value from sensor created by the script…

Low Battery Levels

Pulsante Faro Parcheggio (87) ( battery from my sensor)

Pulsante Faro Parcheggio Battery (87) (Created by the script)

Is it still working for you with hass 0.98.x ?
My battery levels stop updating after upgrade.

I’m on 0.98.1 and as far as i can tell, it still works as with previous versions (although my devices somehow are reporting the same level for moths, but that is both through this code as well as directly when viewing the devices/entities/attributes)…

I use google_maps component and it reports my phone battery level.
And since 0.98 it’s stuck at 52% (few days ago since I use 0.98 since first beta).

Don’t know how to debug that.

Are you using the latest version of the code for google_maps? See for instance Google Maps Location tracker - #2 by eggman .

It looks like you’re right.
Sorry about that but I was sure I had checked the value in the device_tracker and it was correct.
I’ve updated my cookie and now it looks fine.
I’ll continue monitoring this.

I manually installed this as a package. Can somebody please point me to the code I need to add to my lovelace to get this view?

Thanks @NotoriousBDG for this great package. A few people have asked about the issue with the Xiaomi Temp sensors and how they create 3 sensors per device (temp, pressure and humidity) which results in 3 battery entities. The advice has been to use the “battery_sensor_creation_disabled” flag to remove the excess.

Trouble is for me I have a lot of these and some others that have 2 sensors so the inhibit list is way bigger that the list of actual batteries I want to monitor which kind of defeats the purpose of this script.

My question is - Is it possible to wildcard the list so it gets smaller. For example I would like to go from this (which is not my complete list!)

sensor.air_quality_sensor_pms_70_0_0:
battery_sensor_creation_disabled: true
sensor.air_quality_sensor_pms_70_0_1:
battery_sensor_creation_disabled: true
sensor.air_quality_sensor_pms_70_0_2:
battery_sensor_creation_disabled: true
sensor.pressure_158d0001f505f1:
battery_sensor_creation_disabled: true
sensor.pressure_158d0001fa38b3:
battery_sensor_creation_disabled: true
sensor.pressure_158d0001fa38df:
battery_sensor_creation_disabled: true
sensor.pressure_158d0001b95353:
battery_sensor_creation_disabled: true
sensor.humidity_158d0001b95353:
battery_sensor_creation_disabled: true

to

sensor.air_quality_sensor_:
battery_sensor_creation_disabled: true
sensor.pressure_:
battery_sensor_creation_disabled: true
sensor.humidity_:
battery_sensor_creation_disabled: true

I was hoping to get this working too, but at the moment, I don’t believe this is compatible with LoveLace. At least, I can’t get the configuration screen either :frowning: