[RELEASE] Day Lights - an iteration of Circadian Daylight

After installing @adamkempenich's Circadian Daylight I was interested in making a couple of tweaks and was drawn into the world of groovy development. While the underlying code has been re-worked, the spirt of the app along with the look and feel of the setup remains very similar. A few brave people in the forums have tried out the results and it seems that that app is stable enough for a general release.

The main changes to the original are:

  • At sunset the lights will remain at the minimum brightness
  • Color temperature will continue to change during the day even if dynamic brightness is disabled or overridden
  • If a custom brightness range is set, brightening can be accelerated in the morning or delayed until closer to midday

I've put the code on github that can be pasted to your Apps Code. You can create multiple instances of it to control different groups of bulbs.

7 Likes

Howdy, I’ve been enjoying this app - Thank you for improving it.

I do have some suggestions tho.

  • For colour bulbs, initialise them by sending pure white (0 hue / 0 saturation) and then send the desired colour temp.

I don’t know if it’s just LIFX, but I get weird results when I use the “colour bulb” function eg.

But if I change to using “colour temp bulb” and initialise it with pure white (0 hue / 0 saturation), then l initialise the app, I get good results.

  • When not using auto brightness, it would be great if the app detected brightness changes (external to the app) and then adjusted the colour/colour temp to match the time of day. Especially with LIFX colour bulbs, changing the brightness changes the colour temp.

Cheers Derek

1 Like

That color bulb thing is a bit odd, isn't it? It's an algorithm that I believe Adam brought over from the original ST app that will take a CT value and transform it into an HSV/RGB value. The Tuya bulbs that I have used for testing this also produced colors that don't seem to make sense, but I never really dove in to understand what's going on as my use case is for tuning the CT of white bulbs.

I will do some research on the color side of the circadian cycle and see what I can do. I'm still digesting your second suggestion - I think there was something on Adam's to-do list regarding an external lux sensor.

1 Like

Honestly, I’d treat them the same as the CT bulbs, just make sure they are set to hue and saturation = zero + colour temp each time and they should be good.

After observing Apple’s adaptive lighting settings for a few days, I’m pretty confident this is how they do it. Eg

Start with Red;

Send hue = 0, saturation = 0 and we get white at the specified colour temp:

I think I see where you're going with this. In my impression of the original code the idea was to use color-only bulbs to do a sort of "sunrise alarm" function - going from deep purple to blue to orange etc.

Which LIFX bulb are you using? I'll have a look but I believe with my RGBW bulbs if I assign a color temperature it will flip them into CT/white mode. And once a bulb is in CT/white mode, they might as well be in the Color Temperature Devices group.

1 Like

I've got a couple of different types, mainly LIFX Colour 1000lm and LIFX Mini C bulbs which exhibit the same behaviour.

Mine seem to do the same - Maybe we need an RGBW Bulb option, as using the CT Bulb option only works if the bulb has been set to White Mode (Hue / Saturation = 0).

Btw, looking at the code, the way to solve the "external dimming" issue I mentioned, would be to add a subscription to the device brightness in addition to power state. I meant to have a look through the Dev docs today, but haven't gotten around to it.

if (colorTemperatureDevices) {
        subscribe(colorTemperatureDevices, "switch.on", eventDeviceOn)
    }
    if (colorDevices) {
        subscribe(colorDevices, "switch.on", eventDeviceOn)
    }

So I can confirm that subscribing to the dim level (I’m not sure if I have this correct, but it works) does allow the app to ensure the right colour temp is applied when the brightness changes.

if (colorTemperatureDevices) {
        subscribe(colorTemperatureDevices, "switch.on", eventDeviceOn)
        subscribe(colorTemperatureDevices, "level", eventDeviceOn)
    }

I haven’t figured out how to send the hue and saturation values - I ran out of time today to investigate it.

I found an error in the OG code that calculates the HSV values and have updated the code on GitHub with the fix. Color devices should display much nicer now. Having said that I've been able to determine that my Tuya bulbs (using the community cloud driver) don't respond well to all the activity that this app generates for whatever reason. When I switched my test device to something that was directly paired with the hub the results were excellent.

While looking into this I took a bit of a dive into the world of HSV. I've got some ideas about implementing a Sunrise/Sunset scheme for color devices down the road.

I have also updated the settings page to clarify that "Color Temperature Devices" will work with CT values, and "Color Devices" will work with RGB/HSV values.

1 Like

Did you also add support for RGBW bulbs using my suggestions? I find it works really well.

So you're saying that the only way to get your bulbs into CT mode is to set hue and saturation to zero?

For every bulb that I have just setting a color temperature flips the bulb into CT mode. But if your answer is yes then I don't see why I couldn't add an option to set the hue and saturation to zero for all CT devices at initialization, device on, and start of day events. It would be up to the user to ensure that all the CT devices are RGBW as I would guess that sending that command to a tunable-white bulb would throw an error.

New version on GitHub with an option to attempt to force CT mode by setting the saturation to zero on a device in the Color Temperature group that is in RGB mode. This will happen any time a bulb is set to be updated, not just in the events I mentioned in my prior reply.

I found an old thread that discusses this very thing regarding LIFX bulbs. Based on that I went with the strategy to only set the saturation to zero. Let me know how it works for you.

And a special shoutout to @marktheknife for fixing a typo that I have been completely blinded to!

2 Likes

This is awesome!! Thank you for iterating on a classic.

@adamkempenich s work for circadian daylight is what started my smart home journey! I’m stoked to try what you’ve done

Have you considered getting your app into HPM so updates are easier?

2 Likes

Yep, seems to be a LIFX quirk.

Ah good, I’m glad I wasn’t imagining things.

Thank you, I’ll test it out today,

Btw, did you add the detection for brightness changes that I cobbled together?

I just tested this, and the level check line isn’t there. Can you please add this? Otherwise you get incorrect colour temps (at least on Lifx bulbs) until the next automated change takes place.

The other changes work great tho, thank you.

Ps I found a bug- if you go into the brightness options and don’t make a change, you can’t exit that section.

Got it, just updated github. It's a slightly different change than the one you came up with - I made it an option on the main page right below Dynamic Brightness, but the gist is the same. I put in a fix for the bug in brightness options as well.

It seems that I misunderstood both of your issues at the start of this, thanks for your patience!

1 Like

All good, I’m just happy you could make the changes I requested. This app allowed me to get rid of the homebridge app from my Hubitat hub.

:vulcan_salute:

Edit: lovely work, that works perfectly. :ok_hand:

1 Like

wondering if someone can help me - i've used the original for a while and found it to be exactly what i need - varies my lights to the right CT through the day - but i was 100% positive there was a mode override that meant it was disabled when my hub was in night mode. i recently added one of my bedroom lights to it (the one that comes on when i get up to go to the loo in the middle of the night to stop me tripping over and killing myself), but noticed as a result that it is running 24 hours a day.

has something changed, or have i mis-remembered how the original worked? also, does this new version allow for mode disablement?

thanks for all and any help

There a bunch of mode based overrides in here:

But for bedroom lamps, I turn off dynamic brightness.