LIFX Circadian Rhythm (Time of day automation)

For some time now, I’ve been wanting to automatically have my lights change in both color temp (kelvin) and brightness based on the time of day. I’ve seen the Flux switch component as a solution in the forums, but to me Flux was designed to start at a cool daylight white in the morning and fade down throughout the day. I wanted a true circadian rhythm, start dim and warm in the morning and work its way up to cool and bright by noon, then back to dim, and warm come night time. in Update 0.48 the “light.lifx_set_state” was added which prompted me to finally attempt to write my code.

What I got was a highly customizable and scalable code!
Side Note: “input_boolean.scene_mode” allows me to pause the update process so I can run other scenes uninterrupted.

Huge shout out to CCOSTAN who has also been a great influence to me and my home automation. He had a similar code which ended up being the backbone to what you see below! Check out his GitHub for yourself!

alias: 'Light Adjustment'
trigger:
  - platform: time
# Matches every hour on the hour
    minutes: 00
    seconds: 15
    
  - platform: state
    entity_id: input_boolean.alert_mode
    to: "off"
    from: "on"

  - platform: state
    entity_id: input_boolean.scene_mode
    to: "off"
    from: "on"
    
  - platform: homeassistant
    event: start
  
condition:
  - condition: state
    entity_id: input_boolean.alert_mode
    state: 'off'
  - condition: state
    entity_id: input_boolean.scene_mode
    state: 'off'
      
action:
  - service: light.lifx_set_state
    data:
      entity_id: group.bathroom_lights, group.bedroom_lights
    data_template:
      color_temp: >
        {% set hour=states("sensor.time").split(':')[0] | int %}
        {%- if hour >= 0 and hour < 1  -%}
          365
        {%- elif hour >= 1 and hour < 2  -%}
          365
        {%- elif hour >= 2 and hour < 3  -%}
          365
        {%- elif hour >= 3 and hour < 4  -%}
          365
        {%- elif hour >= 4 and hour < 5  -%}
          360
        {%- elif hour >= 5 and hour < 6  -%}
          330
        {%- elif hour >= 6 and hour < 7  -%}
          310
        {%- elif hour >= 7 and hour < 8  -%}
          285
        {%- elif hour >= 8 and hour < 9  -%}
          250
        {%- elif hour >= 9 and hour < 10  -%}
          220
        {%- elif hour >= 10 and hour < 11  -%}
          180
        {%- elif hour >= 11 and hour < 12  -%}
          165
        {%- elif hour >= 12 and hour < 13  -%}
          155
        {%- elif hour >= 13 and hour < 14  -%}
          165
        {%- elif hour >= 14 and hour < 15  -%}
          180
        {%- elif hour >= 15 and hour < 16  -%}
          220
        {%- elif hour >= 16 and hour < 17  -%}
          250
        {%- elif hour >= 17 and hour < 18  -%}
          285
        {%- elif hour >= 18 and hour < 19  -%}
          310
        {%- elif hour >= 19 and hour < 20  -%}
          330
        {%- elif hour >= 20 and hour < 21  -%}
          360
        {%- elif hour >= 21 and hour < 22  -%}
          365
        {%- elif hour >= 22 and hour < 23  -%}
          365
        {%- elif hour >= 23 and hour < 24  -%}
          365  
        {%- endif %}             
      brightness: >
        {% set hour=states("sensor.time").split(':')[0] | int %}
        {%- if hour >= 0 and hour < 1  -%}
          5
        {%- elif hour >= 1 and hour < 2  -%}
          5
        {%- elif hour >= 2 and hour < 3  -%}
          5
        {%- elif hour >= 3 and hour < 4  -%}
          30
        {%- elif hour >= 4 and hour < 5  -%}
          55
        {%- elif hour >= 5 and hour < 6  -%}
          80
        {%- elif hour >= 6 and hour < 7  -%}
          105
        {%- elif hour >= 7 and hour < 8  -%}
          130
        {%- elif hour >= 8 and hour < 9  -%}
          155
        {%- elif hour >= 9 and hour < 10  -%}
          180
        {%- elif hour >= 10 and hour < 11  -%}
          205
        {%- elif hour >= 11 and hour < 12  -%}
          230
        {%- elif hour >= 12 and hour < 13  -%}
          255
        {%- elif hour >= 13 and hour < 14  -%}
          230
        {%- elif hour >= 14 and hour < 15  -%}
          205
        {%- elif hour >= 15 and hour < 16  -%}
          180
        {%- elif hour >= 16 and hour < 17  -%}
          155
        {%- elif hour >= 17 and hour < 18  -%}
          130
        {%- elif hour >= 18 and hour < 19  -%}
          105
        {%- elif hour >= 19 and hour < 20  -%}
          80
        {%- elif hour >= 20 and hour < 21  -%}
          55
        {%- elif hour >= 21 and hour < 22  -%}
          30
        {%- elif hour >= 22 and hour < 23  -%}
          5
        {%- elif hour >= 23 and hour < 24  -%}
          5
        {%- endif %}
      transition: 3

**This post was filled with more links, however since I’m a “new user” I’m not allowed to make my posts more informational…

The if elif statements are not 100% needed. You can set an array of your values and use that based on the integer provided by the hour.

alias: 'Light Adjustment'
trigger:
  - platform: time
    # Matches every hour on the hour
    minutes: 00
    seconds: 00
    
  - platform: state
    entity_id: input_boolean.alert_mode
    to: "off"
    from: "on"

  - platform: state
    entity_id: input_boolean.scene_mode
    to: "off"
    from: "on"
    
  - platform: homeassistant
    event: start
  
condition:
  - condition: state
    entity_id: input_boolean.alert_mode
    state: 'off'
  - condition: state
    entity_id: input_boolean.scene_mode
    state: 'off'
      
action:
  - service: light.lifx_set_state
    data:
      entity_id: group.bathroom_lights, group.bedroom_lights
    data_template:
      color_temp: >
        {% set hour = states("sensor.time").split(':')[0] | int %}
        {% set color_temp = [365, 365, 365, 365, 360, 330, 310, 285, 250, 220, 180, 165, 155, 165, 180, 220, 250, 285, 310, 330, 360, 365, 365, 365] %}
        {{ color_temp[hour] }}
      brightness: >
        {% set hour = states("sensor.time").split(':')[0] | int %}
        {% set brightness = [5, 5, 5, 30, 55, 80, 105, 130, 155, 180, 205, 230, 255, 230, 205, 180, 155, 130, 105, 80, 55, 30, 5, 5] %}
        {{ brightness[hour] }}
      transition: 3
4 Likes

Nice! Thanks for the info. Somewhat of a noobie at this.

There’s a custom component for this, it’s called circadian rhythm.

1 Like