Hey everyone, I wanted to share a fantastic project I recently completed with my smart lighting setup. After some research and experimentation, I managed to create a seamless color cycle automation for my living room lights using openHAB. Here’s how it went!
The Goal
I’ve always been fascinated by dynamic lighting, especially the way colors can transform a space. My aim was to have all the bulbs in my living room cycle through a spectrum of colors smoothly, with the ability to adjust the speed. This would not only add a festive touch but also enhance the ambiance during gatherings.
The Setup
I use Philips Hue bulbs connected via deCONZ, which integrates perfectly with openHAB. The bulbs are spread across three rooms, creating a cohesive lighting system. I decided to implement this using openHAB rules, as it offers the flexibility I needed for customization.
The Challenges
Initially, I faced a few hurdles. The most significant was ensuring thread safety, as I wanted multiple bulbs to update without causing conflicts. I also needed to figure out how to reset the timer if no motion was detected for a certain period, which I achieved using an automation rule tied to a PIR sensor.
The Solution
I stumbled upon a helpful script on the openHAB community forums. It involved creating a rule that increments the hue value of each bulb, cycling through the color spectrum. By adjusting the sleep interval, I could control the speed of the cycle. Here’s a snippet of the rule I used:
java
import org.eclipse.xtext.xbase.lib.Functions
val Functions$Function3 <SwitchItem, ColorItem, NumberItem, Boolean> cycleColors = [ light, lightColor, mode |
var hue = 0
val sat = new PercentType(75)
val bright = new PercentType(100)
var direction = 1
val long pause = 200
logInfo("color", "Starting color loop for " + light.name)
// Ensure the light is ON
if(light.state != ON) light.sendCommand(ON)
while(mode.state == 12 && light.state == ON) {
Thread::sleep(pause)
hue = hue + (5 * direction)
if(hue >= 360) {
direction = direction * -1
} else if (hue < 0) {
hue = 0
direction = direction * -1
}
lightColor.sendCommand(new HSBType(new DecimalType(hue), sat, bright).toString)
}
true
]
rule “Living Room Color Cycle”
when Item LivingRoom_ColorCycle_Mode changed
then
if(LivingRoom_ColorCycle_Mode.state == 12 ) {
cycleColors.apply(Light_LivingRoom_Main, Light_LivingRoom_Color, LivingRoom_ColorCycle_Mode)
}
end
The Outcome
After some tweaking, the system worked flawlessly! The lights now cycle through colors smoothly, and I can adjust the speed using a simple slider in my sitemap. It’s been a joy to watch the room transform with each color change. The addition of the PIR sensor integration means the lights automatically reset the cycle when motion is detected, adding an extra layer of convenience.
Lessons Learned
This project taught me the power of openHAB rules and the importance of community resources. It also highlighted the need for thorough testing and iteration. I’m now confident in tackling more complex automation projects.
I’d love to hear about your smart lighting projects or any tips you might have for enhancing this setup! ![]()