HACS integration: PYSCRIPT
Entity: cpu_temp (get the temperature of CPY from my RPI)
purpose: adjust fanspeed (argon one)
…
temp1=43.0
temp2=44.0
temp3=45.0
sh=30
shf=20
@state_trigger(f"float(sensor.cpu_temp)<{temp1}" ,state_check_now=True,state_hold=sh,state_hold_false=shf)
@state_trigger(f"float(sensor.cpu_temp)>={temp1} and float(sensor.cpu_temp)<{temp2}",state_check_now=True,state_hold=sh,state_hold_false=shf)
@state_trigger(f"float(sensor.cpu_temp)>={temp2} and float(sensor.cpu_temp)<{temp3}",state_check_now=True,state_hold=sh,state_hold_false=shf)
@state_trigger(f"float(sensor.cpu_temp)>={temp3}",state_check_now=True,state_hold=sh,state_hold_false=shf)
def argon_one_check50(**kwargs):
cputemp=float(sensor.cpu_temp)
if cputemp<temp1:
log.info(f"=====>temperatuur onder {temp1}")
elif cputemp>=temp1 and cputemp<temp2:
log.info(f"=====>temperatuur >={temp1} en < {temp2}")
elif cputemp>=temp2 and cputemp<temp3:
log.info(f"=====>temperatuur >={temp2} en < {temp3}")
else:
log.info(f"=====>temperatuur >{temp3} ")
log.info(f"got arguments50 {kwargs}")
Explanation: In stead of the “log.info”, I will call the service to set the fan speed.
I’ve been looking at the documentation, and I came up with this.
the temp1,temp2,temp3 values are meant for testing. I real life, I guest it will be like 40,50 and 55 ?
I guess I can put those values in “helper fields” (maybe with the need of a pyscript.reload… (but that’s for later).
Who else is using PYSCRIPT? What do you think of my code? Can it be done better? How?
Are there advantages/disadvantages?
Please let me know?
thanks!