[Custom Component] Battery Notes

Hi Tim,

If it absolutely requires a very specific battery I’d suggest AAA Lithium as the battery type.

I’d maybe leave out the HomeSeer if it’s an optional battery and let people add it it manually if they use it battery powered as I guess most will prefer the repeater functionality.

If it’s got the same manufacturer/model/battery that’s all good, I wouldn’t be able to cope with something that didn’t have the same battery so would have to leave that out.

I’m happy for submissions to be bundled or separate, go with what you feel comfortable with, those damn commas and brackets throw so many people, including me!

With version 1.3.3 just released you can now track when batteries were replaced.
A manual button and a service are available for you to reset the replaced date.

2 Likes

I also don’t know how to do it in GitHub, but here is a list for HomeMatic (IP) Devices:

Block9   					= "HM-LC-SW1-BA-PCB|HM-LC-SW4-PCB|HM-LC-SW4-WM|HM-MOD-EM-8|HM-MOD-RE-8|HM-OU-CM-PCB|HM-SEN-RD-O|";
cr2016  					= "HM-RC-4|HM-RC-4-B|HM-RC-KEY3|HM-RC-KEY3-B|HM-RC-P1|HM-RC-SEC3|HM-RC-SEC3-B|ZEL STG RM HS 4|";
cr2032   					= "HM-PB-2-WM|HM-PB-4-WM|HM-PBI-4-FM|HM-SCI-3-FM|HM-SEC-TIS|HM-SWI-3-FM|HMIP-DLS|HMIP-FCI1|";
2 x Baby C (LR14)   		= "HM-OU-CFM-TW|HM-SEC-SIR-WM|";
3 x Baby C (LR14)			= "HMIP-MP3P|";
1 x Micro AAA (LR3) 		= "HM-RC-4-2|HM-RC-4-3|HM-RC-KEY4-2|HM-RC-KEY4-3|HM-RC-SEC4-2|HM-RC-SEC4-3|HM-SEC-RHS-2|HM-SEC-SCO|HMIP-KRC4|HMIP-KRCA|HMIP-RC8|HMIP-SRH|HMIP-SWDO|HMIP-DBB|HMIP-KRCK|";
2 x Micro AAA (LR3)    		= "HM-DIS-WM55|HM-DIS-EP-WM55|HM-PB-2-WM55|HM-PB-2-WM55-2|HM-PB-6-WM55|HM-PBI-2-FM|HM-RC-8|HM-SEN-DB-PCB|HM-SEN-EP|HM-SEN-MDIR-SM|HM-SEN-MDIR-WM55|HM-TC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ASIR-B1|HMIP-ASIR-O|HMIP-ASIR-2|HMIP-SWO-B|HMIP-SWO-PL|HMIP-DLD|";
4 x Mignon AA (LR6)    		= "HM-CCU-1|HM-ES-TX-WM|HM-WDC7000|";
Festbatterie (Gerät austauschen)    = "HM-SEC-SD-2|HMIP-SWSD|HMIP-MIO16-PCB|HMIP-PCBS|HMIP-PCBS2|HMIP-PCBS-BAT|HMIP-MOD-RC8|HMIP-MOD-OC8|HMIP-USBSM|HMIP-FWI|HMIP-SFD|ELV-SH-WSC|";
Akku aufladen				= "HM-SEC-WIN|HM-SEC-SFA-SM|";

List is from “Servicemeldungen (per zPNP)

Unfortunately I need a manufacturer and model as it’s displayed in Home Assistant’s device screen.

What we need to end up with is something like this per device, happy to handle the GitHub insertions.

{
    "manufacturer": "Philips",
    "model": "Hue motion sensor (9290012607)",
    "battery_type": "AAA",
    "battery_quantity": 2
},

Andrew- NICE set of changes in v 1.3.3 !!

I’ve got a question: Is it possible to manually edit the Battery Last Replaced property on a device?

1 Like

Thanks, it’s been good to have a week off of work and get to play with this.

Not without hacking away at some horrible hidden file. I don’t think many will go and guess when they put a battery in so went for the easier approach of letting it be set when you next replace a battery.
A lot of people are talking about making automations that detect a device going to 100% battery and setting the replaced via the service automatically.

OK, thanks; I understand. I had started doing some battery tracking in my manual device-by-device documentation. But only had a few change dates so far. I’ll just hit “Set” on them, & let it treat today as last-change date.

I sort of like the idea to set date automatically when battery level goes to 100%. But I’ll continue to set mine manually, as I’ve seen too much flakiness in device battery level reporting.

Thanks Andrew,

This is a great custom component. Did you or anyone else come up with a card that can display all the information and allow the battery change date? I would like to add it to my system monitor tab.

Thanks, no card as yet, I don’t use custom cards much myself, I tend to use auto entities a lot to create lists of devices needing attention and have never looked into them, cards are quite a different skill to learn.
It may be something I will explore when I get some free time unless someone else comes up with one.

I have one that I’ve been using for a while. I just need to update it to use some of the new features of this integration and can post it when I get time.

It uses auto-entities and config-template-card. I’ll try and break it out into a single piece of YAML at some point.

The battery type is only shown if there’s a a matching entity for it. My aim will be to have the icon act as the “replace” button with the rest of the cars being more-info.

Screenshot just in case you decide it’s too ugly for you. :rofl:

2 Likes

Can you post your yaml code?

Try this, hopefully it’ll provide you a starter.

You’ll need to have the following custom cards installed: -

If the battery is managed by Battery Notes you will see the battery type in parentheses after the name and the icon tap action will prompt for confirmation that you’ve replaced the battery.

If the battery is not managed by Battery Notes then the card behaves like the normal Tile card (i.e. will display more-info)

type: custom:auto-entities
card:
  type: vertical-stack
card_param: cards
filter:
  exclude:
    - state: unavailable
  include:
    - attributes:
        device_class: battery
      options:
        type: custom:config-template-card
        entities:
          - this.entity_id
        variables:
          getBatteryLabel: |
            () => {
              let battery_label = states[this._config.entities[0]].attributes.friendly_name.replace(/(battery|level)/gi, '').trim()
              let battery_type = states[this._config.entities[0] + "_type"]
              if (battery_type) {
                return `${battery_label} (${battery_type.state})`
              }
              return battery_label
            }
          getIconAction: |
            () => {
              let battery_button = states['button.' + this._config.entities[0].split('.')[1] + '_replaced']
              let ret = {'action': 'more-info'}
              if (battery_button) {
                ret.action = 'call-service'
                ret.confirmation = {'text': 'Battery replaced?'}
                ret.data = {'entity_id': battery_button.entity_id}
                ret.service = 'button.press'
              }
              return ret
            }
        card:
          type: tile
          entity: this.entity_id
          icon_tap_action: ${getIconAction()}
          name: ${getBatteryLabel()}
      sort:
        method: name
sort:
  method: state
  numeric: true

4 Likes

Thanks. This works. From here it is easy to see what needs changing. Is there anyway to configure the change date other than through the integration?

You’ll need to dig in to the JSON files that hold the entities in the storage location. Much of that isn’t documented overly well by the Home Assistant team and probably for good reason; bad config could cause issues.

First of all - I pretty much like batterynotes.
I have a question or request.
After last update the names of new devices are not anymore in english even though I have not changed anything in my setup and in my profile I have alected english as language. It seems to me language of browser is used in new releases.
Is there a way to configure or will it be changed in the future and language is derived from user profile ?

I’m just relying on HA’s translation capabilities so this should be standard for all devices, not just Battery Notes.
Can you give me a screenshot of where this is happening?

Thank for following up so fast.
Maybe its a user problem, but I don’t know how to solve. Besides english as language setting for HA I also switched firefox to english on my German Windos desktop. Even in the android app with language set to english I get german names.

Here some info:
This water sensor was installed with the englisch entityname with earlier versions of batterynotes, update with later versions lead to german names for the replacement entities.


After removing and adding again also “battery_type” now is german "batterieart.

My language settings:


My log file for recent battery notes acticities

2024-01-02 22:43:32.695 DEBUG (MainThread) [custom_components.battery_notes] Removed Device a64665fc65e6081666c5fa39ba466b68
2024-01-02 22:45:48.059 DEBUG (MainThread) [custom_components.battery_notes.library_coordinator] Skipping library updates
2024-01-02 22:45:48.059 DEBUG (MainThread) [custom_components.battery_notes] Finished fetching battery_notes data in 0.001 seconds (success: True)
2024-01-02 22:45:48.063 DEBUG (MainThread) [custom_components.battery_notes.config_flow] Looking up device Xiaomi LYWSD03MMC
2024-01-02 22:45:48.064 DEBUG (MainThread) [custom_components.battery_notes.config_flow] Found device Xiaomi LYWSD03MMC
2024-01-02 22:45:57.112 DEBUG (MainThread) [custom_components.battery_notes.coordinator] Update coordinator
2024-01-02 22:45:57.113 DEBUG (MainThread) [custom_components.battery_notes.coordinator] Finished fetching battery_notes data in 0.001 seconds (success: True)
2024-01-02 22:45:57.188 DEBUG (MainThread) [custom_components.battery_notes.library_coordinator] Skipping library updates
2024-01-02 22:45:57.189 DEBUG (MainThread) [custom_components.battery_notes] Finished fetching battery_notes data in 0.001 seconds (success: True)
2024-01-02 22:49:14.947 DEBUG (MainThread) [custom_components.battery_notes] Removed Device a0da0025c623821e7583404ba7645c4b
2024-01-02 22:49:24.166 DEBUG (MainThread) [custom_components.battery_notes.library_coordinator] Skipping library updates
2024-01-02 22:49:24.167 DEBUG (MainThread) [custom_components.battery_notes] Finished fetching battery_notes data in 0.001 seconds (success: True)
2024-01-02 22:49:24.174 DEBUG (MainThread) [custom_components.battery_notes.config_flow] Looking up device LUMI lumi.sensor_wleak.aq1
2024-01-02 22:49:24.174 DEBUG (MainThread) [custom_components.battery_notes.config_flow] Found device LUMI lumi.sensor_wleak.aq1
2024-01-02 22:49:26.562 DEBUG (MainThread) [custom_components.battery_notes.coordinator] Update coordinator
2024-01-02 22:49:26.562 DEBUG (MainThread) [custom_components.battery_notes.coordinator] Finished fetching battery_notes data in 0.001 seconds (success: True)
2024-01-02 22:49:26.645 DEBUG (MainThread) [custom_components.battery_notes.library_coordinator] Skipping library updates
2024-01-02 22:49:26.646 DEBUG (MainThread) [custom_components.battery_notes] Finished fetching battery_notes data in 0.001 seconds (success: True)"

I managed to reproduce this by going to Home Assistant Settings → System → General and changing the language there and restarting HA.

It is a bug with Battery Notes, the sensor entity ID’s should be English so button.xxxx_battery_replaced

The actual name displayed against the sensor is the System language, rather than what the user has selected in their profile. This is consistent with other integrations I’ve checked and seems to be an omission within HA’s translation implementation.

I have a fix for the entity id I’m currently testing and will hope to get that out today.

Thanks a lot for the fast fix.
I reinstalled everything from scratch and it works properly now.

Thanks for the confirmation and the coffee :smiley: