I script that I’m planning to use to control my fan in my argon case.
The setspeed for the fan has still to be added. For now, I’m only sending a notify message (for testing)…
#Fan Control (Argon case)
temp1=40.0
temp2=45.0
temp3=50.0
sh=60
@time_trigger
@state_trigger(f"float(sensor.cpu_temp)<{temp1} and (sensor.cpu_temp.old==None or float(sensor.cpu_temp.old)>={temp1} )" ,state_check_now=True,state_hold=sh)
@state_trigger(f"float(sensor.cpu_temp)>={temp1} and (sensor.cpu_temp.old==None or float(sensor.cpu_temp.old)<{temp1})", state_check_now=True, state_hold=sh)
@state_trigger(f"float(sensor.cpu_temp)>={temp2} and (sensor.cpu_temp.old==None or float(sensor.cpu_temp.old)<{temp2})", state_check_now=True, state_hold=sh)
@state_trigger(f"float(sensor.cpu_temp)>={temp3} and (sensor.cpu_temp.old==None or float(sensor.cpu_temp.old)<{temp3})",state_check_now=True, state_hold=sh)
def argon_one_check_fan(trigger_type=None, var_name=None, value=None,old_value=None):
if trigger_type=="time":
#script is saved or HA is (re)started. Get current temperature.
cputemp=float(sensor.cpu_temp)
notify.persistent_notification(message=f"trigger is time, cputemp={cputemp}" , title="CPUTEMP")
elif trigger_type=="state" and var_name=="sensor.cpu_temp":
cputemp=float(value) #"sensor.cpu_temp" in stead of "value" is also possible. I took value, as this is the "real" value that caused the trigger to go off
notify.persistent_notification(message=f"kwargs trigger_type={trigger_type}, var_name={var_name},value={value}, old_value={old_value}" , title="CPUTEMP")
else:
notify.persistent_notification(message="SHOULD NEVER HAPPEN" , title="CPUTEMP")
return
if cputemp > temp3:
notify.persistent_notification(message=f"CPUTEMP {cputemp} > {temp3}. Set fan to speed X for this temp" , title="CPUTEMP")
elif cputemp > temp2:
notify.persistent_notification(message=f"CPUTEMP {cputemp} > {temp2}. Set fan to speed Y for this temp" , title="CPUTEMP")
elif cputemp > temp1:
notify.persistent_notification(message=f"CPUTEMP {cputemp} > {temp1}. Set fan to speed Z for this temp" , title="CPUTEMP")
else:
notify.persistent_notification(message=f"CPUTEMP {cputemp} <= {temp1}. Set fan to speed 0 for this temp" , title="CPUTEMP")