Philips Hue -> Fade colors over 1 hour

Hi!
I’m an absolute openhab newbie. I have added my philips hue as a “thing”. I want to realize a very slow fade from one color to another over a duration of about 1 hour. How to do this?

Thanks!!

youll need some item definitions in .items files. see http://docs.openhab.org/configuration/items.html
youll need a rule to control your items. see http://docs.openhab.org/configuration/rules-dsl.html
youll need a sitemap with a switch to start your hue fading. see http://docs.openhab.org/configuration/sitemaps.html

quick & dirty example of fading a color hue bulb:

// Items:
Color Your_Lamp "Lamp" <colorwheel> { channel="hue:0210:your_huehub:your_id:color" }
Switch Hue_Fading "Hue fade"
DateTime Hue_Fade_Next
// Rules
var Timer timer = null

// Start/stop fading
rule "Start Hue Colors fading"
 when 
  Item Hue_Fading changed
 then
  if (Hue_Fading.state == ON) {
    // set a timer to sligtly change the color again and again
    timer = createTimer(now, [|
      Hue_Fade_Next.sendCommand(now.toString)
      if (timer != null) {
        timer.reschedule(now.plusSeconds(1))
      }
    ])			
  }
  else {
    timer = null
  }
end

// Fade a bit. 
rule "Hue Fade Next"
  when 
    Item Hue_Fade_Next changed
  then
    if (Hue_Fading.state == ON) {
      // get your current color
      var hsb = Your_Lamp.state as HSBType
      // change it a little bit
      var DecimalType hue = new DecimalType(hsb.hue.intValue % 360 + 1) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)
      var PercentType sat = new PercentType(hsb.saturation.intValue) // 0-100
      var PercentType bright = new PercentType(hsb.brightness.intValue) // 0-100
      var HSBType newHsb = new HSBType(hue,sat,bright)

      // set the new color		
      Your_Lamp.send(newHsb)
    }			
end
// Sitemap
Switch item=Hue_Fading

change fading time playing with the reschedule parameter:

timer.reschedule(now.plusSeconds(1))

EDIT: completed when in “Start Hue Colors fading”

3 Likes