Displaying 2 batteries on Polybar

Hello everyone!, I have a thinkpad T460s which has two batteries. This seems to be a pretty common setup between thinkpads, so I’m sure someone has figured this out… but I can only seem to display 1 battery on polybar. My system has 2 batteries, BAT1 and BAT0, and I can only currently see BAT0 on my bar. I’d like to have a separate module right next to it to see both batteries on my bar. I used to think is was a battery issue, but it is just polybar displaying only one battery.

Thanks in advance for any help, much appreciated!

I have never used BSPWM so take this with a pinch of salt.
I just had a look at .config/polybar/config.ini

and I can see these lines:

; Use the following command to list batteries and adapters:
; $ ls -1 /sys/class/power_supply/
battery = BAT0
adapter = ADP1

Perhaps, in the meantime while you are waiting for the users in the know to respond, you could do some investigation on your own.

Good luck!

1 Like

I’ve tried to mess around with the [module/battery] to no avail. I think I might need a separate module that handles BAT1 instead of BAT0, but I can’t seem to do that either.

Thanks for the input, I’ll do a bit more digging :slight_smile:

1 Like

You might want to research lenovo for this. It may just be that the laptop is set up hardware wise with two batteries to just combine them as one cell. Do you know if it completely drains one battery before it switches to the other or does it just “pool” the resources?

You could create a basic module and then inherit values to other modules.

[module/bat0]
inherit = module/battery
battery = BAT0

[module/bat1]
inherit = module/battery
battery = BAT1

[module/battery]
type = internal/battery
full-at = 98

adapter = AC

poll-interval = 5
time-format = %H:%M

format-charging = <label-charging>
format-discharging = <label-discharging>
format-full = <label-full>

...

And then specify somewhere in the file correct modules that you want to see.
For example

modules-right = bat0 bat1

Names BAT0 and BAT1 should come from /sys/class/power_supply.

3 Likes

I used to use linux mint cinnamon, which seemed to handle the battery ok
BAT0 always drains before BAT1

Would I do all of this inside the polybar.conf file?

Yes, it all goes to polybar.config.

This example I posted is not complete since I have very specific formating (all those <> labels). Check polybar wiki for the basic setup.

I’ve added a second module, but the module just wont show up. I made another before and it crashed my polybar, but the second one I tried w/o referencing another module exists in the config but doesn’t show up.
At least its not crashing I guess…

on my X260 i3 setup i used xfce4-power-manager, and had it’s tray icon to show the combined percentage of my two batteries…

Hi new here and used Endeavour back in the days. Maybe I can help?

I also use a T460s with polybar on my bspwm. Configured it myself so nothing from EndeavourOS but I have the two batterys working. Just cloned the module for the battery and named it Battery2. Let’s se if I can paste it in here :slight_smile:

modules-right = pulseaudio battery battery2 date powermenurofi_bspwm
;==========================================================
[module/battery]
type = internal/battery
battery = BAT0
adapter = AC
full-at = 98

format-charging = <animation-charging> <label-charging>
format-charging-underline = #ffb52a

format-discharging = <animation-discharging> <label-discharging>
format-discharging-underline = ${self.format-charging-underline}


format-full-prefix = 
format-full-prefix-foreground = ${colors.foreground-alt}
format-full-underline = ${self.format-charging-underline}

ramp-capacity-0 = 
ramp-capacity-1 = 
ramp-capacity-2 = 
ramp-capacity-foreground = ${colors.foreground-alt}

animation-charging-0 = 
animation-charging-1 = 
animation-charging-2 = 
animation-charging-foreground = ${colors.foreground-alt}
animation-charging-framerate = 750

animation-discharging-0 = 
animation-discharging-1 = 
animation-discharging-2 = 
animation-discharging-foreground = ${colors.foreground-alt}
animation-discharging-framerate = 750
;======================== END =============================

;==========================================================
[module/battery2]
type = internal/battery
battery = BAT1
adapter = AC
full-at = 98

format-charging = <animation-charging> <label-charging>
format-charging-underline = #ffb52a

format-discharging = <animation-discharging> <label-discharging>
format-discharging-underline = ${self.format-charging-underline}

format-full-prefix =  
format-full-prefix-foreground = ${colors.foreground-alt}
format-full-underline = ${self.format-charging-underline}

ramp-capacity-0 = 
ramp-capacity-1 = 
ramp-capacity-2 = 
ramp-capacity-foreground = ${colors.foreground-alt}

animation-charging-0 = 
animation-charging-1 = 
animation-charging-2 = 
animation-charging-foreground = ${colors.foreground-alt}
animation-charging-framerate = 750

animation-discharging-0 = 
animation-discharging-1 = 
animation-discharging-2 = 
animation-discharging-foreground = ${colors.foreground-alt}
animation-discharging-framerate = 750
;======================== END =============================

Hope it will be of some help :slight_smile:

3 Likes

Unfortunately, I tried pasting this into my polybar/config.ini while replacing my old battery module. This for me just crashes polybar. I might just not be able to add a second module for whatever reason. Seems like messing with the config at all causes polybar to either crash, or not even implement any of my changes.

After a bit of fiddling and digging, I finally got it to work, this was super helpful!
Thanks so much!!!

2 Likes

That’s great work :slight_smile:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.