wake-alarm/wake_alarm/wake-alarm-fans.sh
Krzysztof kuhy Rudnicki 3109d6053c wake_alarm: Tapo P110 plug control, fan ramp via sudo, loud warnings
- Add python-kasa-based smart-plug control (_smart_plug.py) with
  turn_on_plug / turn_off_plug called around the alarm window.
  Reads ~/.config/wake_alarm/tapo.json (host/email/password).
- Hard timeout (TAPO_TIMEOUT_SECONDS) so plug never blocks the alarm.
- Install fan-control script + sudoers entry (install.sh step 6);
  _max_fans / _restore_fans now invoke it via /usr/bin/sudo -n so
  pwm1_enable writes succeed.
- Remove ntfy.sh push notifications entirely (silent no-op was useless).
- Replace every silent skip with _logger.warning() so failures are
  loud: missing xset / xrandr / speaker-test, unreadable hwmon files,
  fan script errors, missing Tapo config, kasa import failure, etc.
- wake-alarm.service: Restart=on-failure with 10s backoff.
- Tests: 100% line+branch coverage on python_pkg/wake_alarm.
2026-05-23 19:51:26 +02:00

53 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# Control CPU/case fan speed for the wake alarm.
#
# Usage:
# wake-alarm-fans.sh max — ramp all NCT fans to 100%
# wake-alarm-fans.sh restore <enable> <pwm> — restore saved values
#
# Must be run as root (installed in /etc/sudoers.d/wake-alarm via install.sh).
# Safe: fans are designed to run at max speed indefinitely.
set -euo pipefail
# Locate the hwmon directory for any NCT Super I/O fan controller.
HWMON=""
for name_file in /sys/class/hwmon/hwmon*/name; do
[[ -f "$name_file" ]] || continue
chip=$(cat "$name_file")
case "$chip" in
nct6775|nct6779|nct6791|nct6792|nct6793|nct6795|nct6796|nct6797|nct6798|nct6799)
HWMON=$(dirname "$name_file")
break
;;
esac
done
if [[ -z "$HWMON" ]]; then
# Not an error — hardware without this chip just skips fan control.
exit 0
fi
PWM_PATH="$HWMON/pwm1"
ENABLE_PATH="$HWMON/pwm1_enable"
case "${1:-}" in
max)
echo 1 > "$ENABLE_PATH" # Switch to manual mode
echo 255 > "$PWM_PATH" # 255/255 = 100% speed
;;
restore)
if [[ $# -ne 3 ]]; then
echo "Usage: $0 restore <old_enable> <old_pwm>" >&2
exit 1
fi
# Restore pwm value first, then restore the control mode.
echo "${3}" > "$PWM_PATH"
echo "${2}" > "$ENABLE_PATH"
;;
*)
echo "Usage: $0 max | $0 restore <old_enable> <old_pwm>" >&2
exit 1
;;
esac