Your revision 5 works! Thank you so very much! I have dimming lights again! Well, except for one minor thing…
The previous version of the script in the OpenHAB 2.5 days, I actually had the timerTickEveryMs set to 750, because too low of a value seemed to cause issues with my Kasa switches almost locking up or lagging behind almost as if the commands were too frequent and caused some issues. 750 was a good sweet spot, although I’ve just played with 500, and 1000 for the setting as well.
Now for long dimming times (30+ seconds) It appears all good, although anything shorter I’m seeing, that when I initiate a universaldimmer.sendCommand(“Light_UL_OfficeCeilingBrightness,50,10000”)
It actually ends randomly between 45 and 48% rather than 50. No huge deal, a few percent isn’t critical, although when I dim them off…
universaldimmer.sendCommand(“Light_UL_OfficeCeilingBrightness,0,10000”)
It only seems to dim down to 1 or 2%, and never right down to 0 unless I dim over a longer time period, It’s like the script overshoots but because of how my Kasa dimmers lag behind, they don’t get that final update to go right down to 0.
I did find a quick and easy workaround to fix it, and that was duplicating the
item.sendCommand(targetValue)
line, directly above the final logInfo, just after the if(!isAtTarget) so it looks like this:
timerPool.remove(itemName)
if (!isAtTarget)
{
item.sendCommand(targetValue)
}
item.sendCommand(targetValue)
logInfo("UniversalDimmer", String::format("Finished dimming %s from %d => %d", itemName, startingBrightness, targetValue))
Which appears to do the trick as it sends that final value once more after the script thinks it’s at the target, which pushes it down below the 1-2%, as well as up past that 47-48%.
On a side note, I’ve also just ordered several H801 LED Dimming modules off AliExpress, so I’m sure I’ll be back with questions once I get them and flash them with Tasmota, and hope that your script plays nicely with those too, as my current cheap LED Controllers that came with my LED strips don’t use PWM, so they flicker incredibly badly at anything below 100%, the H801’s seem to have programmable PWM frequencies so I should have less headaches (literally) and a better looking dimmed light on several light strips I have installed.