Continuous Light by time of day (Gradient)

Set light by time of day continuously. The color temperature and brightness are in a gradient across the day. Trigger when switched on or every 15 seconds while on. The start of the day is always at full bright blue toned white (6400K). The color temperature is softened till a fixed value at noon. From noon till the end of day color temperature is softened and the brightness lessened ending in a nightlight (2200K) or your minimum brightness.

The triggering while the light is already on, can be disabled between set hours. The suspension switch must be set for this.

  • Every minute of the day has its own color and brightness
  • Select when your day starts and end
  • Disable withing selected time scale
  • Select minimum brightness

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Continuous Light by time of day (Gradient)
  description:
    Set light by time of day continuously. The color temperature and brightness are in a gradient across the day.
    Trigger when switched on or every 15 seconds while on. The start of the day is always at full
    bright blue toned white ( 6400 K). The color temperature is softened till a fixed value at noon.
    From noon till the end of day color temperature is softened and the brightness lessened ending in
    a nightlight ( 2200 K) or your minimum brightness.

    The triggering while the light is already on, can be disabled between set hours. The suspension switch
    must be set for this.
  domain: automation
  input:
    light_entity:
      name: Light entity
      description: The light to control. Color temperature range is auto-detected.
      selector:
        entity:
          domain: light
    night_disable:
      name: Suspend
      description: Suspend continuous trigger between selected times
      default: false
      selector:
        boolean:
    start_disable:
      name: Start disable time
      description: Start time to disable continuous trigger
      default: "17:00:00"
      selector:
        time:
    end_disable:
      name: End disable time
      description: End time to disable continuous trigger
      default: "01:00:00"
      selector:
        time:
    minimum_brightness:
      name: Minimum brightness
      description: The brightness minimum. Some lights ignore very low values
        and may turn on with full brightness instead!
      default: 1
      selector:
        number:
          min: 1.0
          max: 255.0
          step: 1.0
          mode: slider
    start_of_day:
      name: Start of day
      description: Moment in the morning the day starts (must be before noon)
      default: "07:30:00"
      selector:
        time:
    end_of_day:
      name: End of day
      description: Moment in the evening the day ends
      default: "23:00:00"
      selector:
        time:

variables:
  start_of_day: !input "start_of_day"
  end_of_day: !input "end_of_day"
  minimum_brightness: !input "minimum_brightness"
  night_disable: !input "night_disable"
  light_entity: !input "light_entity"
  start_disable: !input "start_disable"
  end_disable: !input "end_disable"
  minutes_before_noon: "{{[(as_timestamp(today_at('12:00')) - as_timestamp(today_at(start_of_day)))/60, 0]|max|int}}"
  minutes_after_noon: "{{[(as_timestamp(today_at(end_of_day)) - as_timestamp(today_at('12:00')))/60, 0]|max|int}}"
  minutes_elasped_since_start: "{{[(as_timestamp(now()) - as_timestamp(today_at(start_of_day)))/60, 0]|max|int}}"
  minutes_elasped_since_noon: "{{[(as_timestamp(now()) - as_timestamp(today_at('12:00')))/60, 0]|max|int}}"
  color_temp_calc: >
    {% if now() < today_at(start_of_day) %}
      454
    {% elif today_at(start_of_day) < now() <= today_at('12:00') %}
      {{156 + ((minutes_elasped_since_start / minutes_before_noon) * 119)|int}}
    {% elif today_at('12:00') < now() <= today_at(end_of_day) %}
      {{275 + ((minutes_elasped_since_noon / minutes_after_noon) * 179)|int}}
    {% else %}
      454
    {% endif %}
  brightness_calc: >
    {% if now() < today_at(start_of_day) %}
      {{[1, minimum_brightness]|max}}
    {% elif today_at(start_of_day) < now() <= today_at('12:00') %}
      255
    {% elif today_at('12:00') < now() <= today_at(end_of_day) %}
      {{[255 - ((minutes_elasped_since_noon / minutes_after_noon) * 254), minimum_brightness]|max|int}}
    {% else %}
      {{[1, minimum_brightness]|max}}
    {% endif %}

trigger:
  - platform: time_pattern
    seconds: "/15"
  - platform: state
    entity_id: !input "light_entity"
    from: "off"
    to: "on"

condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: !input "light_entity"
        state: "on"
      - condition: or
        conditions:
          - condition: not
            conditions:
              - condition: template
                value_template: "{{not night_disable}}"
              - condition: time
                after: !input "start_disable"
                before: !input "end_disable"
          - condition: template
            value_template: "{{not night_disable}}"

action:
  - service: light.turn_on
    data:
      brightness: "{{brightness_calc}}"
      color_temp: "{{color_temp_calc}}"
      transition: 5
    entity_id: !input "light_entity"
mode: restart
max_exceeded: silent

2 Likes

What are the advantages of this Blueprint compared to the Flux integration?

The flux switch platform will change the temperature of your lights similar to the way flux works on your computer, using circadian rhythm. They will be bright during the day, and gradually fade to a red/orange at night. The flux switch restores its last state after startup.

The integration will update your lights based on the time of day. It will only affect lights that are turned on and listed in the flux configuration.

Didn’t realize this existed, I suppose an advantage this offers is disabling the changing of light within a given timeslot. And I find blueprints with its UI is somewhat more user friendly.

OK.

BTW, if you’re interested, you can streamline a few templates by taking advantage of the fact you are already using datetime objects (so there’s no need to convert them to timestamps first before performing a subtraction).

  minutes_before_noon: "{{[(today_at('12:00') - today_at(start_of_day)).total_seconds()/60, 0]|max|int}}"
  minutes_after_noon: "{{[(today_at(end_of_day) - today_at('12:00')).total_seconds()/60, 0]|max|int}}"
  minutes_elasped_since_start: "{{[(now() - today_at(start_of_day)).total_seconds()/60, 0]|max|int}}"
  minutes_elasped_since_noon: "{{[(now() - today_at('12:00')).total_seconds()/60, 0]|max|int}}"
 

Thanks, I did consider this. Still learning about this, I tried making the blueprint somewhat stand alone, so without the need for such entities.

Not sure what you mean. What “entities” are you referring to?

A datetime one

datetime is a data type, not an entity.

For example, the result of now() is a datetime object and the result of today_at(start_of_day) is also a datetime object. In your original template you are using as_timestamp to convert datetime objects to float values (timestamps). What I pointed out is that you can subtract datetime objects directly (without first converting them).

1 Like

I get it now, thanks

I really like this blueprint, thanks, I also did not know about the flux integration. This blueprint looks to be a bit friendlier to initially configure. I can’t see an option to reload the fluxer config without rebooting HA.

Also, I like this blueprint gives an option to bring down to minimum brightness, but leave the light on, the flux integration appears to just lower brightness until off.

So I have it set up for multiple lights using a comma-separated list, but it seems to only trigger from the light that is first on the list.
Any chance of picking, and triggering from multiple light entities? Or do I just make one automation for each light.

I try using this however I cant turn my lights of at night, they turn on after a while?

So I have it set up for multiple lights using a comma-separated list, but it seems to only trigger from the light that is first on the list.
Any chance of picking, and triggering from multiple light entities? Or do I just make one automation for each light.

Glad you like it.
What I had in mind is making a separate one for each light (group), because is have different requirements for each group. I have not experience using automation with a CSV .

I try using this however I cant turn my lights of at night, they turn on after a while?

This kind of automation is sensitive to race conditions when using it with other control systems.

@MickW69 Having had some experience with my own blueprint that does something similar, the comma separated list cannot have any spaces between the commas.
For example, this will not work:

light.example1, light.example2

But this will work:

light.example1,light.example2

Here’s my take on this type of automation if you want to try it out:

I also made one that works with the XY color space for RGB bulbs:

1 Like

Would it be something that one you could do to take make the first blueprint that doesn’t change the color of the lights but just give the change in brightens? Because I would love to have that, I understand what the whole point of the changing of the color is set for but I and my fam kind like the color / light effects we have set but just wishes we could get to do like what this does but just leave the color / effects alone and just deal with only how bright the lights are. I and the rest of my fam would be most grateful to someone that could do that and make it as a blueprint, because I have tried my hand at this and will to say I end up yelling words at the tom my voice at hours that I shouldn’t is a understatement.