I have a light that doesn’t support transition
parameter. I want it to gradually increase in brightness. I already have a working python script, with the while loop:
while True:
if (brightness == brightness_end):
break
else:
*check time-step and do stuff*
What I don’t like, is that when the script runs it uses 100% of the CPU, as it runs while loop hundreds of times per second, even if there is no need for it.
I tried adding time.sleep(1)
, but it didn’t change anything, as if HA runner simply ignores it. Apparently threading
is not imported, so can’t use that either.
What can I do to slow the script down?
Edit: using logging, I figured out that sleep works fine, however the value of 1 second for some reason uses much more cpu (90%), than 2 (35%) or 3 seconds (5%). No, it doesn’t jump to 90% for 1 second and drops down to 5% for the rest 2 seconds (in 3 second example), it is flatlined the whole time. Looks like some HA bug, tbh.