Is there a way to add a last battery change custom attribute to all devices with a battery?

I would like to keep track of battery changes on devices and while I am happy to record the date myself having this separate to the device seems silly. So I thought it might make sense to have a custom attribute I can assign to all devices with batteries.
Is there a way to do this or do I have to add custom attributes to each device by hand?
I have never tried to add a custom attribute to anything so this is still all a mystery to me.

Thank you for any suggestions,
Chris.

Hey, Chris.

There’s an integration in HACS called “Battery Notes” that may provide what you’re after. If you use HACS, search under integrations for ‘battery’

Hi Robert,

Thank you, I will have a look at that.
I have since looked at adding custome attributes and there is a way through the rest API and also in YAM, but it looks very problematic for my use case as I would want to store statistics on the date stored in the attribute so that I can look back and see if there is a skew indicating deterioration of a rechargable or if one device uses its battery faster than another.

Grocy has a battery management feature and keeps a journal of replacements/recharges. It can be set up to forecast the next change. There’s an HA add-on for Grocy.

Thank you, I will have a look at that.

I just monitor the battery levels and fire an automation whenever any of them get close to requiring replacement:

I also use an auto-entities card to display only devices that have a low battery on my information page so I don’t have to scroll through a long list of them:

type: custom:auto-entities
card:
  title: Low Battery
  type: entities
filter:
  include:
    - entity_id: sensor.*battery*
      state: <=15
  exclude:
    - entity_id: sensor.*temperature*
    - entity_id: sensor.*power*
    - entity_id: sensor.*low*
    - entity_id: sensor.*s9*
    - entity_id: sensor.*s22*
    - entity_id: sensor.*titan*
sort:
  method: state
  numeric: true

The exclusions may or may not be needed for your setup. The first three filter out various sensors created by tablets and phones. Then the bottom three ignore mine and my wife’s phones, and ignores my water shutoff valve (no idea why it has a battery sensor since it doesn’t have batteries. Kind of dumb.)

Thank you, that is useful and I will definitely use some of it, I had not seen the auto entity card used before, I like it…
I have many devices with different battery reporting information so it might not quite work the same for me. i.e. some devices, Hive Home sensors, report 8% when full, though for a few hours or days after a battery change they report 100%, never worked this out. Also my ikea blinds sometimes report much higher than 100% for a short while after charging.

Many devices expose a sensor to tell you whether or not they are charging. This could easily be accounted for with a bit of code.

Take a look at the video for ideas on how to use code to manage the battery levels.

As for devices reporting 8% when full - those would be HIGH on my list for replacement with products that don’t suck. LOL

For the blinds you have to take the battery out to re-charge. It is after putting the battery back in they show 200% for a random length of time (I have seen this last for 4 or so days) before settling on 100% and then acting normally.

Well, if the goal is to identify a low battery condition, the 200% is not really an issue since you’re only interested in identifying devices below 20% or something, right?

You can streamline the process by adding a custom attribute to devices with batteries. It’ll save you time and make things more organized. While I haven’t explored custom attributes myself, you might find some useful tips on pkcellpower.com. They often have great resources for battery-related queries.