From 1d4dc29b73f0965ca52f865c2cad726e0dc26489 Mon Sep 17 00:00:00 2001 From: Pig Monkey Date: Tue, 14 Jan 2025 08:23:17 -0800 Subject: [PATCH] set battery idle on framework machines Apparently changes made via ectool only survive power off if the laptop remains plugged in, so in practice we have to set this on every boot. https://wiki.archlinux.org/title/Framework_Laptop_13#Battery_control Setting the lower and upper charge percentage to the same value causes the controller to idle the battery at that percentage. This seems like it would be better for the long term health of the battery than giving the battery a range to constantly dis/charge between. It also feels more like what I'm used to from all my years of Thinkpads and TLP. I have also set the max charge on my battery to 90% in the BIOS, as per: https://guides.frame.work/Guide/Enabling+Battery+Saver+Functionality+in+BIOS/392 --- roles/laptop/files/chargecontrol.service | 5 +++++ roles/laptop/handlers/main.yml | 5 +++++ roles/laptop/tasks/framework.yml | 27 ++++++++++++++++++++++++ roles/laptop/tasks/main.yml | 3 +++ 4 files changed, 40 insertions(+) create mode 100644 roles/laptop/files/chargecontrol.service create mode 100644 roles/laptop/tasks/framework.yml diff --git a/roles/laptop/files/chargecontrol.service b/roles/laptop/files/chargecontrol.service new file mode 100644 index 0000000..28ef755 --- /dev/null +++ b/roles/laptop/files/chargecontrol.service @@ -0,0 +1,5 @@ +[Service] +ExecStart=ectool chargecontrol normal 87 87 + +[Install] +WantedBy=default.target diff --git a/roles/laptop/handlers/main.yml b/roles/laptop/handlers/main.yml index 18d48bd..f7f8ba6 100644 --- a/roles/laptop/handlers/main.yml +++ b/roles/laptop/handlers/main.yml @@ -6,3 +6,8 @@ service: name: power_monitor.service state: restarted + +- name: restart charge control + service: + name: chargecontrol.service + state: restarted diff --git a/roles/laptop/tasks/framework.yml b/roles/laptop/tasks/framework.yml new file mode 100644 index 0000000..002745c --- /dev/null +++ b/roles/laptop/tasks/framework.yml @@ -0,0 +1,27 @@ +--- +- name: Install fw-ectool-git + kewlfft.aur.aur: + name: fw-ectool-git + become: yes + become_user: "{{ aur.user }}" + tags: + - aur + - framework + +- name: Copy charge control service + copy: + src: chargecontrol.service + dest: /etc/systemd/system/ + notify: + - reload systemd config + - restart charge control + tags: + - framework + +- name: Enable and start charge control service + service: + name: chargecontrol.service + enabled: yes + state: started + tags: + - framework diff --git a/roles/laptop/tasks/main.yml b/roles/laptop/tasks/main.yml index e12382f..2f4483c 100644 --- a/roles/laptop/tasks/main.yml +++ b/roles/laptop/tasks/main.yml @@ -5,6 +5,9 @@ - include_tasks: tuned.yml when: power_management is defined and power_management == "tuned" +- include_tasks: framework.yml + when: power_management is defined and power_management == "tuned" and ansible_system_vendor == "Framework" + - name: Install x86_energy_perf_policy pacman: name: x86_energy_perf_policy