Skip to content

Instantly share code, notes, and snippets.

@elden1337
Created June 7, 2021 11:45
Show Gist options
  • Save elden1337/ba391b49f263dd0b0adee4156be8ac72 to your computer and use it in GitHub Desktop.
Save elden1337/ba391b49f263dd0b0adee4156be8ac72 to your computer and use it in GitHub Desktop.
Circadian lighting calculator fit for Scandianvian countries.
- id: '12345'
alias: Light - Circadian lights
description: ''
trigger:
- platform: time_pattern
minutes: /10
condition:
- condition: template
value_template: '{{ states.light|selectattr(''state'',''eq'',''on'')|list|count
> 0 }}
'
action:
- service: light.turn_on
data_template:
color_temp: '{{ states.sensor.colortemp.state }}'
entity_id: '{{ states.light|selectattr(''state'',''=='',''on'')|rejectattr(''entity_id'',
''=='', ''light.GROUPS_OR_LIGHTS_YOU_WANT_TO_EXCLUDE_EVEN_IF_THEY_ARE_ON'')|map(attribute=''entity_id'')|join('','')
}}
'
mode: queued
max: 25
- platform: template
sensors:
colortemp:
friendly_name: 'circadian light - color temperature'
unit_of_measurement: 'mired'
value_template: >
{%if states.sun.sun.attributes.elevation > 0%}
{%set nightlenPow = ((as_timestamp(states.sun.sun.attributes.next_rising) - as_timestamp(states.sun.sun.attributes.next_setting)) / 3600 / 24)**1.6 %}
{%set altitudefactor = states.sun.sun.attributes.elevation * nightlenPow%}
{{ (450 - (altitudefactor * 44))|int}}
{%else%}
{{450}}
{%endif%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment