Skip to main content
Topic: Setting charge threshold (daemon?) on openrc [SOLVED?] (Read 487 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Setting charge threshold (daemon?) on openrc [SOLVED?]

Hello guys

Before I write anything on topic, let me inform you that I am a complete newbie. I started playing with linux around a month ago with Arch. I decided to swap to Artix because of the absence of systemd, and now I experience my first real inconvenience that i cannot fix.

Namely, I want to have a charge threshold. I have a laptop that is plugged in nearly at all times when I am not at my university. Windows gave me the option to set the charge threshold to 60%, so that is what I want to stick with.

My goal:
Have my laptop charge to around 60%
Bonus goal: Let it fluctiate between 55 and 65%

What I've tried:
1. TLP
Here is a fragment of my tlp.conf file concerning charge thresholds

Code: [Select]
# BAT0: Primary / Main / Internal battery (values in %)
# Note: also use for batteries BATC, BATT and CMB0
# Default: <none>

START_CHARGE_THRESH_BAT0=0
STOP_CHARGE_THRESH_BAT0=60

# BAT1: Secondary / Ultrabay / Slice / Replaceable battery (values in %)
# Note: primary on some laptops
# Default: <none>

#START_CHARGE_THRESH_BAT1=75
#STOP_CHARGE_THRESH_BAT1=80

# Restore charge thresholds when AC is unplugged: 0=disable, 1=enable.
# Default: 0
RESTORE_THRESHOLDS_ON_BAT=1

# Control battery care drivers: 0=disable, 1=enable.
# Default: 1 (all)

NATACPI_ENABLE=1
#TPACPI_ENABLE=1
#TPSMAPI_ENABLE=1

and my tlp-stat -b with my quick fix

SkvShkr% sudo tlp-stat -b
Code: [Select]
--- TLP 1.5.0 --------------------------------------------

+++ Battery Care
Plugin: asus
Supported features: charge threshold
Driver usage:
* natacpi (asus_wmi) = active (charge threshold)
Parameter value range:
* STOP_CHARGE_THRESH_BAT0/1: 0(off)..100(default)

+++ Battery Status: BAT0
/sys/class/power_supply/BAT0/manufacturer                  = ASUSTeK
/sys/class/power_supply/BAT0/model_name                    = ASUS Battery
/sys/class/power_supply/BAT0/cycle_count                    =    96
/sys/class/power_supply/BAT0/energy_full_design            =  67292 [mWh]
/sys/class/power_supply/BAT0/energy_full                    =  61232 [mWh]
/sys/class/power_supply/BAT0/energy_now                    =  58761 [mWh]
/sys/class/power_supply/BAT0/power_now                      =  9583 [mW]
/sys/class/power_supply/BAT0/status                        = Charging

/sys/class/power_supply/BAT0/charge_control_end_threshold  =    100 [%]

Charge                                                      =  96.0 [%]
Capacity                                                    =  91.0 [%]

SkvShkr% sudo tlp setcharge
Setting temporary charge threshold for BAT0:
  stop =  60

2. Custom daemon?
On Arch i could setup a daemon that would set this fix for me, so I tried doing it here:

A) rc.local
Code: [Select]
#!/bin/sh

# /etc/rc.local -- rc.local for Artix Linux
#
# Enter your custom commands here.

#https://unix.stackexchange.com/questions/48534/how-to-adjust-charging-thresholds-of-laptop-battery
sudo echo 60 > sudo /sys/class/power_supply/BAT0/charge_stop_threshold

B) branding.start
Code: [Select]
#!/bin/sh

#neofetch --no_config --backend off --color_blocks off --underline off --disable memory gpu cpu icons theme resolution uptime
sudo tlp setcharge

This thing worked. Now when i run sudo tlp-stat -b at boot, my charge threshold is 60%, so my issue is solved

I have decided to share this post wis you either way and get some tips on linux/artix forum.




Re: Setting charge threshold (daemon?) on openrc [SOLVED?]

Reply #1
Now that I think about it, it may not be the best idea so I await your input

 

Re: Setting charge threshold (daemon?) on openrc [SOLVED?]

Reply #2
You don't need the sudo commands as those scripts run as root.

You could put both commands in /etc/rc.local
I'm not sure whether pacman would treat /etc/local.d/branding.start as a protected config file or not. But I suspect not ?
If not whenever package artix-branding-base get upgraded you would lose your changes as the file will be overwritten.

As an alternative to using /etc/rc.local you could make a file call WHATEVERYOULIKE.start in /etc/rc.local
make it executable
Code: [Select]
sudo chmod +x WHATEVERYOULIKE.start
and put the commands in there, but rc.local is fine too.

If you've only been using Linux a month you're doing rather well.

Welcome to Artix  :)