Created
January 14, 2024 00:31
-
-
Save jhillyerd/ef415a782d0ff8f70af85155d226b591 to your computer and use it in GitHub Desktop.
Home Assistant Auto Color Temperature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- id: '1704839258272' | |
alias: Auto Office Lights | |
description: '' | |
trigger: | |
- platform: state | |
entity_id: | |
- sensor.auto_kelvin | |
- platform: state | |
entity_id: | |
- binary_sensor.office_occupancy | |
action: | |
- if: | |
- condition: state | |
entity_id: binary_sensor.office_occupancy | |
state: 'on' | |
for: | |
hours: 0 | |
minutes: 0 | |
seconds: 0 | |
then: | |
- service: light.turn_on | |
target: | |
entity_id: light.office_lights | |
data: | |
brightness_pct: '{{ min(80, 30 + ( (states(''sensor.auto_brightness'') |float) | |
* 100) |int) }}' | |
kelvin: '{{ max(2800, states(''sensor.auto_kelvin'') |int) }}' | |
else: | |
- service: light.turn_off | |
target: | |
entity_id: light.office_lights | |
data: {} | |
mode: single |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template: | |
- sensor: | |
- name: Auto Brightness | |
state: > | |
{# Time the simulated sun rises and sets in my cave. #} | |
{% set sunrise = today_at("06:00") %} | |
{% set sunset = today_at("19:00") %} | |
{% set duration = sunset - sunrise %} | |
{% set elapsed = now() - sunrise %} | |
{% set deviation = ((max(0, min(1.0, elapsed / duration)) - 0.5) * 2) %} | |
{{ '%0.2f' % (1.0 - deviation |abs) }} | |
- name: Auto Kelvin | |
unit_of_measurement: "K" | |
state: > | |
{# Minimum and maximum Kelvin values to return. #} | |
{% set min_k = 1000 %} | |
{% set max_k = 6000 %} | |
{{ (min_k + (max_k - min_k) * (states('sensor.auto_brightness') |float)) |int }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment