Battery Status of laptop running Home Assistant OS in Docker

I followed home assistant battery configuration

# Loads default set of integrations. Do not remove.
default_config:
# Example configuration.yaml entry
sensor:
  - platform: linux_battery
# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

restarted home assistant:

$ sudo docker stop homeassistant
homeassistant
$ sudo docker start homeassistant
homeassistant
$

here is my battery information:

g$ upower -i /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          BAT0
  vendor:               Hewlett-Packard
  model:                Primary
  power supply:         yes
  updated:              Sun 09 Nov 2025 09:01:12 PM UTC (0 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               fully-charged
    warning-level:       none
    energy:              25.764 Wh
    energy-empty:        0 Wh
    energy-full:         25.764 Wh
    energy-full-design:  25.764 Wh
    energy-rate:         0 W
    voltage:             12.576 V
    charge-cycles:       231
    percentage:          100%
    capacity:            100%
    technology:          lithium-ion
    icon-name:          'battery-full-charged-symbolic'
  History (charge):
    1762722072  100.000 fully-charged
    1762722072  0.000   unknown
  History (rate):
    1762722072  0.000   unknown

then I tried this:


# Loads default set of integrations. Do not remove.
default_config:
# Example configuration.yaml entry
- platform: linux_battery
  name: Host battery monitor
  battery: 0 <-- your battery number default is 1
  system: linux <-- linux is the default you can also not applie
# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
$ sudo docker restart homeassistant  

It does not work as described in home assistant.
Can someone please guide me into the right direction.

I want to know whether or not the laptop is connected to AC and also what the battery % is when it is not.

Comment: Not sure what your underlying platform is, but in another life I know that Windows WMI calls will also get you this info.

Right now you are telling HA configuration ( in the docker container) to look for battery 0 and report that info.
Does your HA container have access to the device you want to monitor? If it cannot access the battery_BAT0, it cannot report on it.
Also, the default setting for number if battery is 1, did you change it on purpose to 0 for testing?

# Loads default set of integrations. Do not remove.
default_config:
# Example configuration.yaml entry
- platform: linux_battery
  name: Host battery monitor
  battery: 0 <-- your battery number default is 1
  system: linux <-- linux is the default you can also not applie
# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

ubuntu server

~$ upower -i /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          BAT0
  vendor:               Hewlett-Packard
  model:                Primary
  power supply:         yes
  updated:              Mon 10 Nov 2025 10:32:55 PM UTC (20 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               fully-charged
    warning-level:       none
    energy:              25.764 Wh
    energy-empty:        0 Wh
    energy-full:         25.764 Wh
    energy-full-design:  25.764 Wh
    energy-rate:         0 W
    voltage:             12.565 V
    charge-cycles:       231
    percentage:          100%
    capacity:            100%
    technology:          lithium-ion
    icon-name:          'battery-full-charged-symbolic'
~$ upower -i /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          (null)
  power supply:         no
  updated:              Thu 01 Jan 1970 12:00:00 AM UTC (1762814001 seconds ago)
  has history:          no
  has statistics:       no
  unknown
    warning-level:       unknown
    battery-level:       unknown
    percentage:          0% (should be ignored)
    icon-name:          '(null)'

The lack of a valid date and empty data in your variables would tend to indicate the second part is not being called or is isolated from the machine.

I have a similar setup, official HA container running in docker on Linux Lite (on a really really really old Acer Aspire with 2gb ram and 32gb emmc storage - BUT IT WORKS, for now!)

Here’s how I got it working:

In docker-compose.yaml add:

volumes:
  - /sys/class/power_supply/BAT0/capacity:/sys/class/power_supply/BAT0/capacity:ro
  - /sys/class/power_supply/BAT0/status:/sys/class/power_supply/BAT0/status:ro

security_opt:
  - apparmor=unconfined

user: "0:0"

some of that could be redundant, I was doing a lot of copying/pasting from all over the place to get it working!

You can find your battery id via:

ls /sys/class/power_supply

which will show something like:
ACAD BAT0

Therefore, in my case, battery id is ‘BAT0’ (BATzero)

This is my full docker-compose.yaml if it helps:

services:
  homeassistant:
    container_name: homeassistant
    image: ghcr.io/home-assistant/home-assistant:stable
    restart: unless-stopped
    network_mode: host
    volumes:
      - ~/homeassistant/config:/config
      - /sys/class/power_supply/BAT0/capacity:/sys/class/power_supply/BAT0/capacity:ro
      - /sys/class/power_supply/BAT0/status:/sys/class/power_supply/BAT0/status:ro

  security_opt:
    - apparmor=unconfined

  user: "0:0"

Then in your config/configuration.yaml file:

command_line:
  - sensor:
      name: Laptop Battery Level
      command: "cat /sys/class/power_supply/BAT0/capacity"
      unit_of_measurement: "%"
      device_class: battery
      state_class: measurement
      scan_interval: 60

  - sensor:
      name: Laptop Battery Status
      command: "cat /sys/class/power_supply/BAT0/status"
      scan_interval: 60

scan_interval = the polling interval in seconds

Status returns (text) one of: ‘Charging’, ‘Discharging’, ‘Full’

Next:

docker compose down
docker compose up -d
docker exec -it homeassistant sh

# this should give a numeric value - ie: battery level atm
cat /sys/class/power_supply/BAT0/capacity

# this will give current battery status (charging, discharging, full)
cat /sys/class/power_supply/BAT0/status

#if the above two cat calls do not work then either you have a mistake/typo somewhere - or your setup is different(??) - or i have made a typo somewhere as I am typing this from my desktop, not my HA laptop

If you get expected values from the cat calls above then the docker container is seeing your battery level & status, and so that info is also available to HA.

In HA go to Developer Tools → States:
in ‘Filter Entities’ field type laptop and you should see both entries listed with actual values. Mine show as:

sensor.laptop_battery_level
Laptop Battery Level

sensor.laptop_battery_status
Laptop Battery Status

You should also see them listed in Settings → Devices & Services → Entities

Took me a whole weekend to work this out!
I now have the laptop plugged into a smart socket and have an automation going to turn on/off smart socket when battery level thresholds are reached.

Hope that helps

Good luck! :+1:

Your Acer charger doesn’t do battery management at the hardware/BIOS firmware level, independent of any software running on the device?

Not sure, but given that its a 12 y/o machine that was very likely designed for the cheaper end of the market, I very much doubt it.

Also, I don’t like the idea of chargers being left plugged in and on, and left to their own devices. I know the smart socket is also a simialr concept but hopefully that draws a lower amount of power to be a fire hazard. I could be totally wrong!

Battery life is often determined by number of cycles of full charge/discharge chemical stresses, rather than a small level of float charging when permanently powered on. Worth looking in the Acer manual which you should still find online.

As a general comment: Acer equipment is very carefully designed to outlast the warranty by exactly one day. If your warranty is one year, it will break down on the 366th day. Three years - 36months plus one day. Consistently. This comes from years of corporate experience of deploying thousands of their devices, not just personal observation. If they can save half a cent by replacing a screw with a plastic clip, they will do so, and the clip will break one day after the warranty runs out. Always buy the cheap aftermarket extended replacement warranty the greedy salesman offers, and you will always have new shiny functioning Acer equipment to smile about! Yes it is usually good value for money, and even their cheapest devices are well designed, getting churned our by the millions. This consistency is a brand feature.