Issue of the topic: I have been looking into how I can smoothly dim the leds acording to the brightness level outside. I have succeed in setting the right brightness level, however the light can change quickly sometimes and the dimming of the leds looks really bad. I’m looking to make something similar. This is what I have tried, however the Dimmer bugs out and just goes back and forward at value like 30,60. Not sure why, It might have something to do with the delay, however I need this to happen relatively quickly.
rule "RGB_W1 Adaptive"
when
Item lightLevel received update or
Item adaptiveLedsW1 changed
then
var Number set = 0
var Number current = RGB_W1D.state as DecimalType
var Number lux = lightLevel.state as DecimalType
if (adaptiveLedsW1.state == ON && lightLevel.state <= 1000) {
set = (1000-lux)/10
}
else if (adaptiveLedsW1.state == ON && lightLevel.state >= 1001) {
set = 0
}
while((current=current+1) <= set) {
RGB_W1D.sendCommand(current)
Thread::Sleep(50)
}
end
rule "RGB_W1 Adaptive"
when
Item lightLevel received update or
Item adaptiveLedsW1 changed
then
if (adaptiveLedsW1.state == ON && lightLevel.state <= 1000) {
var Number lux = lightLevel.state as DecimalType
RGB_W1D.sendCommand((1000-lux)/10)
}
else if (adaptiveLedsW1.state == ON && lightLevel.state >= 1001) {
RGB_W1D.sendCommand(0)
}
end
In other word what I want to accomplish is
• when light instensity has changed
• calculate the right led brightness (for eg. if the light instensity is 100lx my led brightness should be 90%(i can accomplish that doing (1000-lux)/10))
• every 100ms add 1+ to the current led brightness until it reaches the right led brightness
2019-02-07 17:13:37.364 [vent.ItemStateChangedEvent] - RGB_W1D changed from 29.0 to 30
2019-02-07 17:13:37.421 [vent.ItemStateChangedEvent] - RGB_W1D changed from 30 to 30.000000000000004
2019-02-07 17:13:37.460 [ome.event.ItemCommandEvent] - Item 'RGB_W1D' received command 31
2019-02-07 17:13:37.484 [vent.ItemStateChangedEvent] - RGB_W1D changed from 30.000000000000004 to 31
Turn off autoupdate for your Item. Every time you send a command, autoupdate guesses what the result might be and updates the Item. It’s doing that in its own timeframe, and won’t be synchronised with your dimming steps.
For some unknown reason, you’ve deleted your MQTT input so the Item no longer gets state from the real dimmer. If you do mean to run it blind, you’ll need autoupdate back.
I’m suprised the rule isn’t throwing errors in your logs anyway, the local/global variables status looks all wrong.
(function(i) {
if(i==1023 || i==1023.0) {
var state = "ON";
} else if (i==0 || i==0.0){
var state = "OFF";
} else {
var state = "UNDEF";
}
return state;
})(input)
I suspect things might go wrong if you have more than start of the dimming rule - each will create it’s own private, independent timer. But if light levels drift slowly, that’s not likely to happen I suppose.
Yes that’s better.
50 milliseconds is a bit short for openHAB depending on what platform your run
I would recommend that you make that even longer and increase the iteration.
You will not notice the difference visually and it will run much smother:
val int timeoutMills = 500
....
dimLevel = dimLevel + 5
I’m currently trying to run two dimmers simultaneously ,however if they are in the same rules file one of them doesn’t work, I have created separate timers.
val int timeoutMills = 150
rule "Progressive Dimmer LED_W0D"
when
Item lightLevel changed or
Item LED_W0A changed
then
if(LED_W0A.state == ON) {
var Timer LED_W0T = null
var int dimLevel = (LED_W0D.state as DecimalType).intValue
var int setLevel = 0
if(lightLevel.state <= 1000)
setLevel = ((1000-(lightLevel.state as DecimalType))/10).intValue
else
setLevel = 0
if(LED_W0T === null) {
LED_W0T = createTimer(now.plusSeconds(0), [ |
if (dimLevel == setLevel) {
LED_W0T = null
} else if (LED_W0T !== null) {
if(dimLevel < setLevel)
dimLevel = dimLevel + 1
else if(dimLevel > setLevel)
dimLevel = dimLevel - 1
LED_W0D.sendCommand(dimLevel)
LED_W0T.reschedule(now.toInstant().plusMillis(timeoutMills).atZone(now.zone))
}
])
}
}
end
I’m upgrading my installation to openHab 3.0, I thought I would share this rule, with you guys, for anyone that will be searching regarding this topic.