Circadian Lighting [Custom Component]

It would be nice if there are LED bulbs out there that come really close to incandescent/halogen light bulbs in terms of dimmability as I switched from LIFX to halogen with Insteon Hub 2242-222 and never looked back.

There hasn’t been any improvements to LED bulbs that dim really low to the point that the LED light is barely on. That way it would be cool to use a circadian component. The reason why I switched to halogen light bulbs is because I care less about the energy savings that LED bulbs offer.

Well if you have the Insteon Hub paired with Home Assistant you should be able to use Circadian Lighting to at least control the brightness, if that helps.

1 Like

OK, thanks! I get the idea - unfortunately, this only works for scenes that were activated by pressing the dimmer switch, but not for those activated in the Hue app. Hue dimmer switches have a sensor they use as “memory” to store the current position in the scene cycle, but this is not updated when a scene is chosen in the App…

My log looks like this (lines from other components removed):

2018-07-27 08:29:38 WARNING (MainThread) [homeassistant.loader] You are using a custom component for circadian_lighting which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2018-07-27 08:29:59 DEBUG (Thread-10) [custom_components.switch.circadian_lighting] light.tripod CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:29:59 DEBUG (Thread-21) [custom_components.switch.circadian_lighting] light.fado_homeserver CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:29:59 DEBUG (Thread-9) [custom_components.switch.circadian_lighting] light.linea CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:29:59 DEBUG (Thread-10) [custom_components.switch.circadian_lighting] light.tripod CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:29:59 DEBUG (Thread-10) [custom_components.switch.circadian_lighting] light.fado_homeserver CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:29:59 DEBUG (Thread-10) [custom_components.switch.circadian_lighting] light.linea CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:30:32 DEBUG (Thread-8) [custom_components.circadian_lighting] Circadian Lighting Component Updated
2018-07-27 08:30:32 DEBUG (Thread-12) [custom_components.switch.circadian_lighting] Wohnzimmer Switch Updated
2018-07-27 08:30:32 DEBUG (Thread-17) [custom_components.sensor.circadian_lighting] Circadian Lighting Sensor Updated
2018-07-27 08:30:32 DEBUG (Thread-12) [custom_components.switch.circadian_lighting] light.fado_homeserver CT Adjusted - color_temp: 241, brightness: 255.0, transition: 10.0
2018-07-27 08:30:32 DEBUG (Thread-12) [custom_components.switch.circadian_lighting] light.tripod CT Adjusted - color_temp: 241, brightness: 255.0, transition: 10.0
2018-07-27 08:30:32 DEBUG (Thread-12) [custom_components.switch.circadian_lighting] light.linea CT Adjusted - color_temp: 241, brightness: 255.0, transition: 10.0
2018-07-27 08:32:32 DEBUG (Thread-17) [custom_components.switch.circadian_lighting] light.linea CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:32:32 DEBUG (Thread-18) [custom_components.switch.circadian_lighting] light.fado_homeserver CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:32:32 DEBUG (Thread-9) [custom_components.switch.circadian_lighting] light.tripod CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:32:32 DEBUG (Thread-14) [custom_components.switch.circadian_lighting] light.fado_homeserver CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:32:32 DEBUG (Thread-15) [custom_components.switch.circadian_lighting] light.linea CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:32:32 DEBUG (Thread-20) [custom_components.switch.circadian_lighting] light.tripod CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:34:56 DEBUG (Thread-3) [custom_components.switch.circadian_lighting] light.tripod CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:34:56 DEBUG (Thread-21) [custom_components.switch.circadian_lighting] light.linea CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:34:56 DEBUG (Thread-11) [custom_components.switch.circadian_lighting] light.fado_homeserver CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:34:57 DEBUG (Thread-15) [custom_components.switch.circadian_lighting] light.tripod CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:34:57 DEBUG (Thread-9) [custom_components.switch.circadian_lighting] light.linea CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:34:57 DEBUG (Thread-15) [custom_components.switch.circadian_lighting] light.fado_homeserver CT Adjusted - color_temp: 241, brightness: 255.0, transition: 1
2018-07-27 08:40:52 DEBUG (Thread-7) [custom_components.circadian_lighting] Circadian Lighting Component Updated
2018-07-27 08:40:52 DEBUG (Thread-20) [custom_components.switch.circadian_lighting] Wohnzimmer Switch Updated
2018-07-27 08:40:52 DEBUG (Thread-10) [custom_components.sensor.circadian_lighting] Circadian Lighting Sensor Updated
2018-07-27 08:40:52 DEBUG (Thread-20) [custom_components.switch.circadian_lighting] light.fado_homeserver CT Adjusted - color_temp: 238, brightness: 255.0, transition: 10.0
2018-07-27 08:40:52 DEBUG (Thread-20) [custom_components.switch.circadian_lighting] light.tripod CT Adjusted - color_temp: 238, brightness: 255.0, transition: 10.0
2018-07-27 08:40:52 DEBUG (Thread-20) [custom_components.switch.circadian_lighting] light.linea CT Adjusted - color_temp: 238, brightness: 255.0, transition: 10.0
2018-07-27 08:40:52 DEBUG (Thread-6) [custom_components.switch.circadian_lighting] light.fado_homeserver CT Adjusted - color_temp: 238, brightness: 255.0, transition: 1
2018-07-27 08:40:52 DEBUG (Thread-4) [custom_components.switch.circadian_lighting] light.tripod CT Adjusted - color_temp: 238, brightness: 255.0, transition: 1
2018-07-27 08:40:52 DEBUG (Thread-8) [custom_components.switch.circadian_lighting] light.linea CT Adjusted - color_temp: 238, brightness: 255.0, transition: 1

I switched the sleep_entity and disable_entity on and off, but this does not reflect at all in the log.
Could you please share your config? What type of entity do you use for sleep/disable?

Interesting, I would expect that the app would still have to know when a scene has been activated.

I just pushed some changes to the switch component that adds additional logging and should fix the sleep_entity and disable_entity. I also added a state listener to the sleep_entity so that lights will be adjusted immediately when the entity is the the proper state.

I personally don’t use the disable_entity, I just have automations flip the switch off, but here’s an example of one of my configs with sleep_entity:

- platform: circadian_lighting
  lights_ct:
    - light.claytons_nightstand_lamp
    - light.corys_nightstand_lamp
  lights_brightness:
    - light.master_bedroom_light
  name: Master Bedroom Circadian Lighting
  sleep_entity: 'input_select.security_state'
  sleep_state: 'Stay'
  sleep_colortemp: 2000
  sleep_brightness: 1

Progress… :+1:

Sleep mode is now correctly switched on as soon as the sleep_entity enters the sleep_state, but only colortemp is updated instantly, not the brightness. Brightness is adjusted with the next update cycle (i. e. after the sensor updated after one interval).

Switching off the sleep mode does not update the lights instantly, I had to wait until the next update cycle or switch the lights manually off and on again. Perhaps you could update line 305 so that an update is also triggered when the sleep_entity LEAVES the sleep_state and not only when it ENTERS it?

Setting the disable_entity to diable_state correctly stops the lights from being updated. Setting the disable_entity to some other state (= re-enabling the circadian switch) does not update the lights instantly, I had to wait until the next update cycle. Perhaps you could also add a listener to trigger an update when the disable_entity leaves the disable_state?

It’s getting better and better, thank you for this phantastic component!

Cheers,
Tim.

I considered both of these scenarios and my thought was that a gradual change to the correct color temperature would be preferred for these situations, for example, when awakening from sleep any lights that are on suddenly adjusting could be jarring. Also, I felt the same could be the case with the disable entity. I could add options for transition for sleep/disable but I was concerned things would start getting too complicated. For your use case, would an instant adjustment in those situations be preferable? If you didn’t notice, there is a circadian_lighting.values_update service that will trigger an immediate update, but that uses the transition value. Perhaps it would be better to have that trigger an instant adjustment?

2 Likes

I can’t seem to get this going because of a missing dependency, any idea how to resolve this? I have restarted many times, not sure why it’s throwing an error.

2018-08-08 05:51:59 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.switch.circadian_lighting. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/loader.py", line 94, in get_component
    module = importlib.import_module(path)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/switch/circadian_lighting.py", line 9, in <module>
    from custom_components.circadian_lighting import DOMAIN, CIRCADIAN_LIGHTING_UPDATE_TOPIC, DATA_CIRCADIAN_LIGHTING
  File "/config/custom_components/circadian_lighting.py", line 50, in <module>
    from timezonefinder import TimezoneFinder
ModuleNotFoundError: No module named 'timezonefinder'

Hello!

It seems that I have the same problem.

Error loading custom_components.switch.circadian_lighting. Make sure all dependencies are installed
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/loader.py”, line 94, in get_component
module = importlib.import_module(path)
File “/usr/local/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 678, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/config/custom_components/switch/circadian_lighting.py”, line 9, in
from custom_components.circadian_lighting import DOMAIN, CIRCADIAN_LIGHTING_UPDATE_TOPIC, DATA_CIRCADIAN_LIGHTING
File “/config/custom_components/circadian_lighting.py”, line 50, in
from timezonefinder import TimezoneFinder
ModuleNotFoundError: No module named ‘timezonefinder’

Can you write down the steps how you installed timezonefinder?

Thank you!

I just tried to install timezonefinder. I used SSH & Web Terminal addon, tried with pip, but it fails, only starts installation with pip3 but it fails at the end with error code 1…

Any idea?

Regards,
TT

I’m running in Docker if that matters. Shouldn’t it download the dependency on it’s own though?

Home Assistant should install required packages on it’s own. In my testing, the first time I loaded the component it did not install but after rebooting Home Assistant it did. I’ve reached out in the devs chat on Discord but haven’t gotten a response yet. I’ll keep looking into it though.

Do either of you have other custom components that have required packages?

Do you see any errors from homeassistant.util.package? You should see something like:

2018-08-14 00:33:43 ERROR (SyncWorker_7) [homeassistant.util.package] Unable to install package limitlessled==6.6.6: Could not find a version that satisfies the requirement limitlessled==6.6.6

I don’t have any errors like that. And it’s strange because yeah I do have other custom components that are loading their dependencies just fine.

Strange…you looked in the whole home-assistant.log file? Maybe try removing the custom component files, rebooting, then adding the custom component files and rebooting again - then check the log.

Hi Clayton,

great custom component. I have not tried it yet, but I certainly will.

In my setup I have several LED stritps, that have cold and warm white as colors. It is connected to 2 channels of a fibaro RGB(W) dimmer switch. Thus it basically ‘is’ a rgb light, but the rgb is not fully used and there is no correct mapping of led-color and color-channel.

Currently I am transitioning from FHEM (another OpenSource HA-system) to Home Assistant. In FHEM I already had my own version of circadian lighting. Here I had a script setting blue in the morning, white during the day and in the evening dimming the lights and fading to warm white.
I dealt with the warm white/cold white (WW/CW) situation by handling it as two seperate lights, dimming CW down in the evening and dimming WW up a bit less.
The Hue bulbs I am using were handled similarly: warming & dimming down was done by lowering the brightness and increasing the temperature.

So now to my question:
What do you think is the best way to join my setup and your circadian lighting? Is there any way to implement a “light_CW”, where you can define entities for the cold and warm channel?
Or is it best for me to write a custom component, which takes colortemperature and brightness to CW and WW and translate it to brightness of the CW/WW channels?

About the scenes: I found it ideal to have the system use the setting of a scene as a new starting point. So setting a scene overrides the “normal” calculated values and the system dims/warms from the settings of the scene, but not going lower than a certain minimum.
Usually the eyes adapt to the change quickly enough, creating an illusion of “constant” lighting, although the light warms and dims down. At least this is what I generally learned from guests who did not know about that feature. Either they did not notice or they did not complain :wink:

The way that Home Assistant, SmartThings, and every other platform I’ve come across, is built there’s a layer of abstraction between the hardware and the way components interact with that hardware. For example, the commands that need to be sent to a Hue bulb to change its color and those that need to be sent to a Z-Wave bulb are completely different, but in the UI, automations, etc. the service that is called is identical. This way you don’t need to keep track of how different hardware works - that’s done when it’s integrated and from then on you don’t worry about it.

Ideally, you would write a custom integration for your fibaro dimmer that would provide that layer of abstraction, allowing it to take in regular commands through the standard light service calls. Admittedly, that would be a fair amount of coding on your end to do. An easier solution for Circadian Lighting might be to just add the component but don’t include your fibaro lights in any CL switches, then build your own automation/python script/node-red/etc that adjusts the fibaro lights based on the CL sensor (which provides everything you need to determine brightness and color temperature).

One thing I’d like to point out is that Circadian Lighting starts with lights at the minimum color temperature at sunrise, goes to maximum CT at mid-day, and goes back to minimum CT at sunset. This mimics natural daylight, but is slightly different than the behavior you described (“blue in the morning, white during the day and in the evening dimming the lights and fading to warm white.”)

You are correct, ideally there should be a layer in between my odd light configuration and a usual CT+BRI system.
Not having written a custom component yet I assume that it wont be too much effort in this special case. CT + BRI in, some calculation and two powersettings out.
As you seem to have done some research about color temperature: have you run across an equation to calculate/estimate color temperature from two known color temperatures?
Or is it roughly linear? Eg. for one LED at 3k and one at 7k, will a 50-50 mix be around 5k?
I am aware of that the spectra of the two LEDs will add up and probably not reproduce the ‘true’ light at 5k (or whatever it will be), but does it come close? Or is it highly nonlinear?

The thinking behind my way of lighting (blue - white - yellow) was that blue light enhances waking in the morning, a mix of both to come closer to 5-5.5k (daylight) and then reducing the blues in the evening to promote melatonin production. Are there any arguments to prefer the way it is implemented in your component (except it being more ‘natural’)?

If I read your code correctly, then the offset of the sunrise and sunset will change the length of the cycle. So there is no way of “hacking” your circadian rythm in to mine by shifting the sunset to way ahead of my wakeup time so that it is already blue by then, right? I’d loose the somewhat quick dimming in the evening.

My research only goes so far as what color temperatures occur naturally, when, and how they affect the human body. I haven’t done any research into the physics of color and how they would blend, etc. My hunch would be that it isn’t linear but probably logarithmic, but I have no basis for that. The best solution would obviously be to buy a meter and calibrate your lights off that, but that would run you probably $500-$2,000. A cheaper solution might be to buy a cheap bulb that’s known to be relatively accurate and just play with your lights until they look like they match - that should be good enough I would think.

I find waking up to very blue of white light jarring - personally if I wake up with a slightly more yellow light I feel much more rested , and when it gradually transitions to a whiter/bluer light it helps me feel more alert and energetic.

My code will always generate a parabolic color temperature curve sunrise-sunset and a parabolic brightness curve sunset-sunrise. (See screenshots in post 2) You could use the sunrise offset or sunrise time to shift those curves so that the peak, or wherever you want, will occur when you wake up. It would then shift to your min color temp at a decreasing rate.

I’m getting the following error but not quite sure what is going wrong;

Traceback (most recent call last):,
    brightness = (self._attributes['brightness'] / 100) * 255,
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run,
    result = self.fn(*self.args, **self.kwargs),
  File "/config/custom_components/switch/circadian_lighting.py", line 302, in light_state_changed,
    self.adjust_lights([entity_id], 1),
  File "/config/custom_components/switch/circadian_lighting.py", line 259, in adjust_lights,
2018-08-19 20:26:13 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved,
TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'

I have the disable brightness adjust set to true and a min/max colortemp, everything else is default (i’m using lights_ct).

I’d first like to say I think this component is excellent! I was able to get the conventional color temperature changes/parabola working, and I want to use the sleep state but I don’t know how to set up the correct entity. Could you post some instructions as to how to set this up?

Also, with the brightness transitions, it seems that with my Hue lights, they get dimmer at night/brighter in the morning faster in proportion to the color temperature. Is there a way to slow down the brightness transitions but keep the color temp transitions the same?

Also, those graphs you posted very early on, how did you generate the ones for color temp and brightness? The sensor only generates a graph for the CL values.

Thanks so much!

@oakbrad @taanczos.tamaas what folders do you have in /config/deps/lib/python3.6/site-packages?