Template entity to guess the outside colour temperature

Wouldn’t that be simply


… int),0]|max),255] …

instead of


… int),250]|max),454] …

?

Except the formula is for a curve that is based on colour temperature not brightness. You could give it a go and see if it gives the desired results - I doubt you would though, it will almost never spit out a number near 0.

Sure enough, it doesn’t.

Link? (10 char min)

Dynamic Lighting System for Workplaces at Northern Latitudes Tarmo Koppel, Tallinn University of Technology

Then I reverse engineered an equation to fit the graph.

1 Like

Any idea how I mite be able to accomplish the same effect for brightness?

{{state_attr('sun.sun', 'elevation') + 10}} would give you a number that varies between 10 at sunrise/sunset and 100. If you use that to set brightness percentage…

Or {{state_attr('sun.sun', 'elevation') /90*100}} would vary between 0-100.

But beware the seasons and your latitude would effect the brightness. The sun only reaches maximum elevation in the summer. Unless you live on the equator…

Otherwise to get 100% brightness at midday every day and 0 at sunrise you need a different formula.

This post has info on getting the percentage of the day remaining Sun elevation based on percentage of day which is tangentially related to what you want to achieve

nice idea! IMO you’re overusing () which makes it more confusing. Math in code follows order of operations, many of those () are implied in the syntax

{{ [ [ (1000000/(4791.67 - 3290.66/(1 + 0.222 * [ [ 0, state_attr('sun.sun', 'elevation') ] | max, 90 ] | min**0.81)))|int, 250 ] | max, 454 ] | min }}
1 Like

Maybe {{state_attr('sun.sun', 'elevation') /1*2}}, since the max elevation these days is around 49°?

So, the following seems to work, what do you think?

service: light.turn_on
target:
  entity_id: light.white_led
data_template:
  brightness_pct: >-
    {{ (state_attr('sun.sun', 'elevation')| multiply(2) / 1 ) | round(0) }}

the /1 is doing nothing

{{ state_attr('sun.sun', 'elevation')| multiply(2) | round(0) }}

:+1: Yep, realized just after posting, ended up with the following, which seems to be working well so far.

alias: Large Tank Light by Elevation
description: Increase / Decrease Brightness by Elevation
trigger:
  - platform: state
    entity_id: sun.sun
    attribute: elevation
condition:
  - condition: time
    after: '07:00:00'
    before: '19:00:00'
  - condition: numeric_state
    entity_id: sun.sun
    above: '0'
    attribute: elevation
action:
  - service: light.turn_on
    data_template:
      brightness_pct: '{{ (state_attr(''sun.sun'', ''elevation'')| multiply(2)) | round(0) }}'
    target:
      entity_id: light.white_led
mode: single

You’d probably want to normalize the values based on the min/max elevation possible for your region. So that the highest point is 100%.

FYI, this entire thread can be solved by using the custom integration: Circadian lighting, or adaptive lighting. Both have the same functionality.

I think I did, for the past week the max elevation been 49.2, not sure if this would be all year (probably not), but hope to come up with the ideal solution before then, I just need something working for the next week while I’m away.

I will definitely look into those.

I finally made a blueprint: Color temperature - match your lights to the sun

Do you know about a way to get this information? I have current elevation and I have the time for astronomical noon (which is when the sun will be at max elevation at the current day, however, how to know which elevation will be at noon?
Here at sweden the max elevation changes quite a lot over the year and I’d like to find it programmatically for one of my automations.

A hacky way would be to store the highest elevation from yesterday which will be a rough approximation of today’s maximum elevation.

In an automation use the moment the sun.sun.attribute.rising switches from true to false to update an a number helper with the current elevation.

As for the highest possible over a year, I would just look it up on the internet and then input it as a number helper.

1 Like

I liked the idea. Simple!

Thanks!

For colour temperature in Kelvin, you can try this (untested), adjust 2200 and 4000 to the supported range of your bulbs:
{{ [ [ (1000000/(4791.67 - 3290.66/(1 + 0.222 * [ [ 0, state_attr(‘sun.sun’, ‘elevation’) ] | max, 90 ] | min**0.81)))|int, 2200] | max, 4000] | min }}

This is still in Mireds. Probably you meant
{{ [ [ ((4791.67 - 3290.66/(1 + 0.222 * [ [ 0, state_attr('sun.sun', 'elevation') ] | max, 90 ] | min**0.81)))|int, 2200] | max, 4000] | min }}

The full sensor would be

  - sensor:
    - name: sun_kelvin
      state: "{{ [ [ ((4791.67 - 3290.66/(1 + 0.222 * [ [ 0, state_attr('sun.sun', 'elevation') ] | max, 90 ] | min**0.81)))|int, 2200] | max, 4000] | min }}"
      unique_id: "sun_kelvin"
      unit_of_measurement: 'Kelvin'
1 Like

I turned this into a blueprint:

1 Like