I currently use two main patterns for adjusting light levels:
Adjusting lights that are currently ON based on time of day (Astro is not a good idea in Norway as we have few non-sunny hours in the summer and few sunny hours during the winter).
For some motion triggered lights (for example in the bathroom) I have special rules which, when motion is detected, turns some lights on or not based on time of day and adjusts the light to different levels than those in #1.
What I am missing now is some way of dimming lights which are turned on and are not in the #2-umbrella to (for example) the PresetDimLevel.
Something like:
rule "Some light switched to ON. Set the changed light to correct dimlevel"
when gLight changed
//Figure out which light it was that changed to ON
//Set this light to the correct dimlevel
end
Is there a common pattern for this which I can re-use?
My “patterns” Pattern 1: Adjusting dimlevels for lights that are already on
Items:
Group gDimmer
Number Dimmer1 (gDimmer) {....}
Number Dimmer2 gDimmer) {....}
Number PresetDimLevel
Switch UpdateLightLevels
Rules:
rule "6:30, weekday - night is over, adjust to early morning light"
when
Time cron "0 30 6 ? * * *"
then
PresetDimLevel.postUpdate(20)
Thread::sleep(500)
UpdateLightLevels.sendCommand(ON)
end
rule "React on UpdateLightLevels switch, send target percentage"
when
Item UpdateLightLevels changed to ON
then
UpdateLightLevels.postUpdate(OFF)
gDimmer.members.forEach[ item |
if (item.state > 0) {
logInfo("lightingschedule.rules", "Item state: " + item.state)
item.sendCommand(FF_AllLights_PresetPercNormal.state as Number)
}
}
Pattern 2: Turning on lights by motion detection
Items:
Contact Bathroom_Motion
Switch Bathroom_Dimmable_Light {....,expire=....}
Bathroom_Small_Lights {...}
Bathroom_Strong_Light {...}
rule "Bathroom_Motion received update"
when
Item Bathroom_Motion received update
then
if (Bathroom_Dimmable_Light.state==ON){
Bathroom_Dimmable_Light.postUpdate(ON) //Delay expire
}
else{
val CurrentHour = now.getHourOfDay
if (CurrentHour > 6 && CurrentHour < 11){
Bathroom_Dimmable_Light.sendCommand(70)
Bathroom_Small_Lights.sendCommand(ON)
}
else if (CurentHour....)..
end
Edit: The Solved-post gave the right answer and another post show my actual implementation which includes this solution.
rule "Some light switched to ON. Set the changed light to correct dimlevel"
when
Member of gLight changed
then
triggeringItem.sendCommand(dimlevel)
end
In order to make this as general as possible (and in order to be able to turn off lights - which I don’t think will be possible with the rule above), one would need to check for something like:
when
Member of gLight changed from 0
then
…
end
But documentation has it that this should work just fine!
Hmmm, it seems like it should have worked and I get the following logged:
“2018-10-25 19:35:26.595 [ome.event.ItemCommandEvent] - Item ‘FF_Sov2_Light_Dimmer’ received command 20”
So the rule correctly sends the command and I get the “received command”-event, but not the two “predicted to become”- and “changed to”-events which I get if I use the openhab-console to send the command for example. And the light is not dimmed to 20 as hoped.
rule "Some dimmable light switched to ON. Set the changed light to correct dimlevel"
when
Member of gDimmer changed from 0
then
logInfo("Lightningschedule.rules", "The dimmable item " + triggeringItem.name + " turned on. Dim to correct level.")
Thread::sleep(500)
triggeringItem.sendCommand(FF_AllLights_PresetPercNormal.state)
end
Adding asDecimalType (deprecated) and then transforming into and int is adding to the execution time and adding a lot of time at parsing time.
Try not to use primitives (int, floats…) unless really necessary
I’m using the Astro binding for sun-rise/set with location set to Oslo without any issues for over a year now.
What was you problem?
Are you even further north perhaps?
I live in Oslo as well, but using astro sounds like a very bad idea to me. The sunrise July 1st is at like 4AM, too early for all lights to be way bright imo, and now it’s at 8.15 or something which is too late.
If my kids wake up at 5AM to go pee, I want them to feel it’s night and go back to bed, preferably without waking us up, both in the winter and the summer.
So, for regular work days, all lights are dimmed way down until 6 or 6.30 and are way bright from 7 when the day has started. And all lights start dimming slowly down from 7PM onward.
My outdoor lights are astro-timed though and that works well.