Added Raspi 4 Conf
This commit is contained in:
50
hosts/rpi4/fan-controll.nix
Normal file
50
hosts/rpi4/fan-controll.nix
Normal file
@@ -0,0 +1,50 @@
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
environment.systemPackages = with pkgs; [
|
||||
(python3.withPackages (ps: [ ps.smbus2 ]))
|
||||
];
|
||||
|
||||
|
||||
# Fan control service
|
||||
systemd.services.argon-fan = {
|
||||
description = "Argon40 Fan Control via I2C";
|
||||
after = [ "multi-user.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
Restart = "always";
|
||||
ExecStart = pkgs.writeScript "argon-fan.py" ''
|
||||
#!${pkgs.python3.withPackages (ps: [ ps.smbus2 ])}/bin/python3
|
||||
import smbus2
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
bus = smbus2.SMBus(1)
|
||||
|
||||
while True:
|
||||
try:
|
||||
# Get temperature
|
||||
temp_output = subprocess.check_output(['${pkgs.libraspberrypi}/bin/vcgencmd', 'measure_temp']).decode()
|
||||
temp = float(temp_output.replace("temp=","").replace("'C\n",""))
|
||||
|
||||
# Set fan speed based on temperature (0-100)
|
||||
if temp < 55:
|
||||
speed = 0
|
||||
elif temp < 60:
|
||||
speed = 25
|
||||
elif temp < 65:
|
||||
speed = 50
|
||||
else:
|
||||
speed = 100
|
||||
|
||||
bus.write_byte(0x1a, speed)
|
||||
print(f"Temp: {temp}°C, Fan: {speed}%")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
time.sleep(30)
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user