Script to track all devices with a battery_level

You could not find documentation because it did’t exist. :grin:

I have set up a new repo for my custom components with appropriate documentation in case somebody wants to contribute and maybe later can be merged into HA.

1 Like

@pilotak this looks useful. Could you make a PR for the main repo?

1 Like

@andrey So I pushed it into the main repo, but it was refused. We should use sensor.template was answered.
Never mind I still think it is useful and will continue using it as it’s easier and looks cleaner in config.

1 Like

I made a PR to @pilotak repo recently which gets the friendly name of the original entity, if you don’t specify any friendly_name in the attributes config.

merged yesterday…

Creating a template for each battery is a ballache.
Creating a value template for icon is even more… especially with sensors with batteries. I have 20-30 batteries to track.
Thanks for this I will give it a try…

1 Like

@pilotak maybe make a small note that it has to go into custom_components/sensor/ i bumped my head into this thing, since it was my first component and the first topic it was also in custom_components/ directly. Could not find install instruction of the .py itself in your repo so not sure if you wanted it there.

@riemers i have updated repo readme so it’s clear to everybody

Is this script suppose to get battery from device_trackers to?

I have this:

- platform: attributes
  friendly_name: "Batteries"
  attribute: battery
  unit_of_measurement: "%"
  entities:
    - device_tracker.matte_api
    - device_tracker.asa_api
    - device_tracker.cod_api

The device_tracker have this attributes:

{
  "friendly_name": "Asa_Api",
  "latitude": xx.xxxxxx,
  "battery": "41",
  "source_type": "gps",
  "longitude": xx.xxxxxx,
  "gps_accuracy": 0.2,
  "entity_picture": "/local/tasker.png"
}

But my sensor.asa_api_battery gets this:

State: unknown
Attribute:

{
  "unit_of_measurement": "%",
  "friendly_name": "Batteries"
}

@pilotak: A nice adition to this is Howto create battery alert without creating a template for every device although the nice side of that template is that it automaticly picks up all the battery powered devices. I don’t know if that is possible in your script too? That would save creating a list of devices for the attribute. Just a thought, might help others too, alerting if low is nice to have.

P.s. using templates to create what you made imho i don’t see how that would be done anyways.

I had a quick look at the automations, what a clever way to do! anyway i’m working on different custom component at the moment so i don’t have much time to alter attribute sensor. But it is set in Github so anyone willing to contribute is welcome.

How do i exclude an entity?

Hi Awesome component been using for a while, I have added about 40 battery powered sensors since so was glad to see you have modified the original code to add a whitelist.

I updated the code and added to my config.yaml but I get this error…

Invalid config for [battery_state]: required key not provided @ data['platform']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/battery_state/

snippet of config

battery_state:
  include:
    - sensor.door_window_sensor_158d0001a6469f_battery
    - sensor.door_window_sensor_158d0001b704f9_battery
    - sensor.door_window_sensor_158d0001b70953_battery
    - sensor.door_window_sensor_158d0001b7acc5_battery
    - sensor.door_window_sensor_158d0002019ae3_battery
    - sensor.door_window_sensor_158d0002019b2a_battery

Hi guys… This is my code, acording to this post - I am using it to show Ikea Tradfri dimmer battery… I have the battery state but in badge, and I would like to have it in a list and remove the badge…

But I am getting the error below… Any suggestion?

Unable to find component sensor.attributes

sensor:
- platform: yr
- platform: attributes
friendly_name: “Batteries”
attribute: battery_level
unit_of_measurement: “%”
entities:
- sensor.boravak
- sensor.blagovaona
- sensor.kuhinja
- sensor.hodnik_ulaz
- sensor.kupaona