Funny how things work... Everyone in my house is constantly tweaking the AC settings. One says, "I am cold." Another says, "I am MELTING."
I am getting tired of 'correcting' the settings, never mind being the AC police. So, figured I would let NR own it... and what do I see, the above thread.
Now I can create a flow that can (slowly, silently) return the AC settings to the 'correct' settings, such that evil AC trolls will not realize immediately that NR is returning the AC settings to their 'correct' settings.
The node would be passed the setpoint and measured temperature and will output a number between 0 and 1 which you can scale to the pwm range you want for the fan. Then the node (once correctly tuned) will control the fan to give the required setpoint.
Going back to your function, it is not clear to me what it is trying to do. It sets pwm to msg.payload then either decrements or increments it by 1. At least I think that is what the rather unusual lines like
pwm = pwm -=1
do. I think that is the same as pwm = pwm -1
or pwm -= 1
But that seems a bit strange since msg.payload coming in appears to be either the setpoint or the current temperature. So the pwm sent out is going to be either temperature +- 1 or setpoint +-1, which I imagine is not what you want.