Homey Community Forum

DIY circadian rhythm based lighting

I’m basically looking to recreate BrainLit’s circadian rhythm matching lighting, which they call BioCentric Lighting. I’ve been to their office here in Lund and essentially it adjusts color temperature and brightness to match the sun as if every day was April 16th in southern Sweden.

I would like to be able to use wall switches to turn on sets of lights in a room in different modes:

  1. Following the sun – as above – as long as they are left on.
  2. Fully bright and white
  3. Some scenes for specific cases.

I’m new to Homey, so I don’t know the best approach to develop this without reinventing the wheel. I’ve come as far as to create a HomeyScript that adjusts a color temperate and brightness variables in Better Logic, and have a Flow setting these properties on certain lights when they are turned on.
Left to do:

  1. Continuous updating of turned on lights in ‘circadian’ mode.
  2. Grouping of lights in each room for different modes.
  3. Handling of different modes in which updating is inactive.
  4. Handle bulbs, LED strips with different capabilities.

Is this the best way with HomeyScripts and Flows? Or should I instead build a custom app?

Does this help with your idea?

Thanks! I’ve gotten this far as to calculate both color temperature and brightness to a certain degree for a single light.
It’s the way forward, scaling it to every room of the apartment that I’m uncertain about. :slight_smile:

Can you share how you calculated the light temperature?

It’s much simplified and because I never want the lights to be completely dark, there is also a minimum, but it does serve its purpose well. :slight_smile:

:point_right: gist


Hi. How is this going? Can you share the calulations?

Yes, follow the finger :point_right: in my previous post. :slight_smile:

Just discovered your script and immediately packed in homeyscript!
But I still have some questions:
which flows have you made? Do you let homey do the
script every second?
Which flow did you create so that the temperature etc. are retrieved? Are they stored in a logic?
Definitely want to have this :slight_smile:
Maybe you could share your flows on this?
I would be mega grateful to you :wink:

Updating the brightness and color temperature values every minute seemed sufficient to make it transition smoothly throughout the day. They are stored in the Better Logic app.
Here’s the update flow, which also creates dimmed variants for certain lights.

Then I use the values with Hue lights. This flow is called repeatedly as long as the light is turned on.

Let me know if there’s anything else you’re wondering.

thank you for the answer, since yesterday I already did it though :slight_smile:

However, I noticed something and that is when I test the script, the shows me a different system time.
Now, for example, the script says:
At 15:55:05
Day progress: 66%
CircadianRhythm__temperature: 0.04
CircadianRhythm__brightness: 1

But for me it is 17:55 o’clock, where can I define this in the script? or add that it adds 2 hours?

and what is the second flow for? is it just to show the light a bit more dimmed (75% and 50%)?
And last question, the “dimming” from the second flow you do for both values right?

  1. Oh, yes. Completely forgot about the timezone issue in scripts since Homey v5. I’ve updated my gist with the hack to fix it. Now, this script should use the correct local time.

  2. In the first Flow I create different dimmed versions of the current brightness because sometimes it is too bright, while I still want it to change during the day.

  3. In the second Flow I repeatedly set temperature to the CircadianRhythm_temperature and dim to the CircadianRhythm_brightness with the Dining room lights.

Great work @iotnerd.

Because I am not familiar with JSON and HomeyScript, I have one more question.
How can I write the values of “CircadianRhythm__temperature” and “CircadianRhythm__brightness” of the script in a variable?
So I don’t understand your first flow because there are question marks in the flows:

des ist ganz einfach, leg in der better logic App eine Variable mit Nummer an.
Wichtig ist das du die auch genauso benennst wie im Script also:


und dann starte mal das Script, dann trägt der automatisch die Werte ein.

1 Like

I have one last question, who I want to do exactly the opposite with the calculation. So let’s say on the weekend the light is too yellow for me and I want to achieve that it is 25% stronger than currently. Iwas I would then have to apply a formula? I come with these formulas topics not quite so to cope.

btw thanks for the customization of the script, the time is now displayed correctly :slight_smile:
Especially during the week the light is so really nice

When I wish to have something other than circadian lighting, I just disable flows and set whatever custom values I want. You can have a physical or virtual switch that turns on (1) circadian mode and another that turns on (2) custom mode.

  1. Sets lights to circadian, and enables a flow that repeatedly sets the values again every x minutes.
  2. Sets lights to some other preferred values, and disables the repeated update Flow.

Something like this?

Great script and thanks for sharing it!
In the meantime, I got it working with the help of @clipse_M.

The marked lines in the screenshot are probably intended to limit the dimming level to the upper and lower range, right?

Is this also possible with the temperature?

Because I have absolutely no programming knowledge, I would be happy if someone could change the script.