Add battery charge limiter for laptop

This commit is contained in:
Przemek Grondek 2022-07-14 21:06:42 +02:00
parent 107f7aa27d
commit a36600126b
3 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,12 @@
[Unit]
Description=Set the battery charge threshold
After=multi-user.target
StartLimitBurst=0
[Service]
Type=oneshot
Restart=on-failure
ExecStart=/bin/bash -c 'echo 80 > /sys/class/power_supply/BAT0/charge_control_end_threshold'
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,18 @@
- name: Check if laptop has option to limit battery
stat:
path: /sys/class/power_supply/BAT0/charge_control_end_threshold
register: battery_limiter_available
- when: battery_limiter_available.stat.exists
block:
- name: Copy service to limit battery charge
become: yes
copy:
src: lib/systemd/system/battery-charge-threshold.service
dest: /lib/systemd/system/battery-charge-threshold.service
- name: Enable battery limit service
become: yes
systemd:
name: battery-charge-threshold
enabled: yes

View File

@ -0,0 +1 @@
- import_tasks: battery.yml