These Emacs Lisp functions help me to control fan speed on Lenovo Thinkpad laptops. With some adaptations they may work on other laptops as well.
(defun sudo (arguments)
"Executes list ARGUMENTS with system command `sudo'."
(let* ((command (format "sudo su -c -- root -c \"%s\"" (string-join (list arguments))))
(return (shell-command-to-string command)))
return))
(defvar my-fan-proc-file "/proc/acpi/ibm/fan")
(defun fan-speed (arg)
"Controls fan speed provided user has superuser rights and system
command `sudo' works without password. Function will mostly work
on Lenovo Thinkpad notebooks. Prefix argument ARG shall be
numbers from 1 to 9. Numbers from 1 to 7 determine the fan speed
level, number 8 represents auto fan speed level and number 9
represents full fan speed. Activate with `C-u NUMBER M-x
fan-speed'. If invoked without arguments it will show the
contents of the fan control file."
(interactive "P")
(when (and (file-exists-p my-fan-proc-file)
(rcd-which "sudo"))
(if arg
(cond ((= arg 7) (sudo (format "echo level %s >> %s" arg my-fan-proc-file)))
((= arg 8) (sudo (format "echo level auto >> %s" my-fan-proc-file)))
((= arg 9) (sudo (format "echo level full-speed >> %s" my-fan-proc-file)))
((and (< arg 7) (> arg 0)) (if (y-or-n-p (format "Really set fan speed to %s?" arg))
(sudo (format "echo level %s >> %s" 7 my-fan-proc-file))))
(t (message "Supply better numeric argument to this function from 1 to 9.")))
(message (file-to-string my-fan-proc-file)))))
Copyright © 2021-03-29 22:43:35.917913+02 Jean Louis
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.