Setting pwm according CPU temperature

Hello forum,

How to set a output value for a shell command, with the CPU temperature as reference. I’d like to drive my fans according that value.
But maybe I can manage it outside from HA.


When I was using the raspberry as a HA server, I used the rasp cpu temperature to control an external fan.using a relay connected to one of the rasp pins. Using automation to trigger the relay when temp gets at certain threshold. I used a 12v fan but with two voltages connected to a relay to control the fan speed. 12v and 5V. 5V is ON all the time and when temp gets high relay switch over to 12v and back down to 5V.

I think I can use the GPIO with a PWM, then I may decide a set of preset to change the two fans speed.
I tested the fans and I can supply them with 24 V, whilst connect in series, but that might be a little to much. At the room temperature, I getting some pick of 75 °C, but average is about 60 degrees. So I just like to run the fans as much as necessary.

I have fans on my raspberry armour case controlled with pwm. This was possible with help of my mentor C V Rao.
Couple of lines in the config file.