Circadian Lighting [Custom Component]

Yeah but my guess here is that because the lights are fading between brightness the set color temp function might interrupt somehow. The lights are fading to the chosen brightness and then back where it came from. But its random.

Yeah i could solve it with an automation!

Easy to setup and works perfectly! Thank you for sharing this project! :slight_smile:

I want to try this project but one thing is not clear to me:
As i already have automations about my lights turn on at sunset, must i disable them to use your project or not?
Can you be more precise about it as i am newbie here…

Circadian Lighting should never turn lights on or off, all it’s designed to do is adjust the color temperature and/or brightness of lights configured in Circadian Lighting when they are on.

Ok, and what if in the automations i already set brightness and rgb values? They will be overwritten by the sensor or not?

Exactly. If you don’t want brightness / color to be overwritten then you would just have the automation turn off the Circadian Lighting switch before turning the light(s) on, and then when you want the Circadian Lighting values to be set you could use an automation to turn the Circadian Lighting switch back on.

Ok, by default the switch will turn on when the lights will be on ?

By default the CL switch is on always, but only adjusts lights when they’re on.

Hmmm so why, just after installing it the switch is OFF? I just turned on manually now…

You’re right, I’m sorry. What I should have said is that when the switch is first created the state is None (which is off), however once it’s turned on/off it should remember the state through reboots (although in my experience this doesn’t always work due to a failure in the state recorder, especially when there’s multiple reboots close together - this is a platform issue and not specific to CL)

The sun is down at the moment, the lights are turned on here but i don’t see any significant difference between no sensor and sensor configured and active… the switch is on. Maybe i still do not understand how it works…
Here it is the screenshot of the sensor values…

Can you explain me what i must expect from this component?

So when the sun is down it will keep the lights at the min colortemp - in the real world when the sun is down there’s no light so no colortemp, so keeping it at the min is the best solution.

Circadian Lighting will adjust color temperature from sunrise to sunset, and will adjust brightness from sunset to sunrise (if you choose to use that option). Brightness is set at a per-CL switch basis, so you’ll see brightness calculation if you click on the CL switch for more information.

This is my configuration:

- platform: circadian_lighting
  name: Luci Circadiane
  lights_rgb:
    - light.yeelight_1
    - light.yeelight_2

Is this correct? What to add more to have the switch working completely?
What you mean “Brightness is set at a per-CL switch basis”?
Sorry my english is not so good to understand all.

This is what i get on clicking the switch.

Is this config correct to add more switches for different lights?

- platform: circadian_lighting
  name: Luci Circadiane RGB
  lights_rgb:
    - light.yeelight_1
    - light.yeelight_2
    - light.yeelight_3
    - light.yeelight_4
    - light.bedside_wifi
- platform: circadian_lighting
  name: Luci Circadiane Brightness
  lights_brightness:
    - light.philips_salotto
    - light.philips_studio
    - light.philips_3
    - light.philips_4
    - light.philips_5

Yes, that’s all you need.

As you said the sun is down, the only thing it should be doing right now is setting the brightness of light.yeelight_1 and light.yeelight_2 to 81.12208251953125 (this number should update every 15 minutes). When the sun rises, the brightness will stay at 100, but the color will begin to change until the sun sets again.

You may want some lights to adjust brightness and others not to. Just like other platforms you can define multiple CL switches, each containing a set of lights. That is why color temperature is shown on the CL sensor (so that all lights always stay in sync) while brightness is shown on the switch.

Yes, assuming that’s under the switch: section of the configuration.yaml

Ok, i’ll try to understand how it works in time…
Thanks…

Please may I congratulate you on a fantastic custom component. I use it in my home office to syncronise all the different lights together. Can I also point out that lights using the limitless LED component (a.k.a. mi-lights), do not support a 15 minutes transition. took me a while to figure out why i was getting strange behaviour. might be an idea to make your default under 60 seconds, for maximum compatibility.

One other strange behaviour is that the ‘circadian values’ sensor is showing up as a device tracker. I’m assuming this is something strange with my system that needs debugging.

With HA 0.80 some API elements have been removed, which this component was using. The following patch should help to bring it back to work:

λ diff -u switch/circadian_lighting.py.orig switch/circadian_lighting.py
--- circadian_lighting.py.orig  2018-10-13 21:29:26.139165300 +0200
+++ circadian_lighting.py       2018-10-13 21:20:02.978286000 +0200
@@ -14,11 +14,10 @@
from homeassistant.helpers.dispatcher import dispatcher_connect
from homeassistant.helpers.event import track_state_change
from homeassistant.helpers.restore_state import async_get_last_state
-from homeassistant.components.light import (
-    is_on, turn_on)
+from homeassistant.components.light import (is_on, DOMAIN as LIGHT_DOMAIN)
from homeassistant.components.switch import SwitchDevice
from homeassistant.const import (
-    CONF_NAME, CONF_PLATFORM, STATE_ON)
+    CONF_NAME, CONF_PLATFORM, STATE_ON, SERVICE_TURN_ON)
from homeassistant.util import slugify
from homeassistant.util.color import (
    color_RGB_to_xy, color_temperature_kelvin_to_mired, color_temperature_to_rgb)
@@ -263,39 +262,41 @@
                if self._attributes['lights_ct'] is not None and light in self._attributes['lights_ct']:
                    mired = int(self.calc_ct())
                    if is_on(self.hass, light):
-                        turn_on(self.hass, light,
+                        self.hass.services.call(LIGHT_DOMAIN, SERVICE_TURN_ON, dict(
                                color_temp=mired,
                                brightness=brightness,
-                                transition=transition)
+                                transition=transition,
+                                entity_id=light))
                        _LOGGER.debug(light + " CT Adjusted - color_temp: " + str(mired) + ", brightness: " + str(brightness) + ", transition: " + str(transition))

                """Set color of array of rgb light."""
                if self._attributes['lights_rgb'] is not None and light in self._attributes['lights_rgb']:
                    rgb = self.calc_rgb()
                    if is_on(self.hass, light):
-                        turn_on(self.hass, light,
+                        self.hass.services.call(LIGHT_DOMAIN, SERVICE_TURN_ON, dict(
                                rgb_color=rgb,
                                brightness=brightness,
-                                transition=transition)
+                                transition=transition,
+                                entity_id=light))
                        _LOGGER.debug(light + " RGB Adjusted - rgb_color: " + str(rgb) + ", brightness: " + str(brightness) + ", transition: " + str(transition))

                """Set color of array of xy light."""
                if self._attributes['lights_xy'] is not None and light in self._attributes['lights_xy']:
                    x_val, y_val = self.calc_xy()
                    if is_on(self.hass, light):
-                        turn_on(self.hass, light,
+                        self.hass.services.call(LIGHT_DOMAIN, SERVICE_TURN_ON, dict(
                                xy_color=[x_val, y_val],
                                brightness=brightness,
                                transition=transition,
-                                white_value=brightness)
+                                white_value=brightness))
                        _LOGGER.debug(light + " XY Adjusted - xy_color: [" + str(x_val) + ", " + srt(y_val) + "], brightness: " + str(brightness) + ", transition: " + str(transition) + ", white_value: " + str(white_value))

                """Set color of array of brightness light."""
                if self._attributes['lights_brightness'] is not None and light in self._attributes['lights_brightness']:
                    if is_on(self.hass, light):
-                        turn_on(self.hass, light,
+                        self.hass.services.call(LIGHT_DOMAIN, SERVICE_TURN_ON, dict(
                                brightness=brightness,
-                                transition=transition)
+                                transition=transition))
                        _LOGGER.debug(light + " Brightness Adjusted - brightness: " + str(brightness) + ", transition: " + str(transition))

    def light_state_changed(self, entity_id, from_state, to_state):
1 Like

How to apply the patch?

Just pushed an update to config/custom_components/switch/circadian_lighting.py , to get Circadian Lighting working with Home Assistant 0.80

1 Like