Skip to content

Make your lights turn on, off, change their brightness and color temperature automatically.

License

Notifications You must be signed in to change notification settings

FLchs/smartlight-ha-blueprint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Home Assistant smart light blueprint

GitHub License GitHub Actions Workflow Status GitHub Release

blueprint logo

Make your lights turn on, off, change their brightness and color temperature automatically.

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

Why ?

There are many blueprints that already do the same thing, partly or with other (often unnecessary) features.

Blackshome's blueprint is awesome, but some features are unnecessary for the simplest use cases, and if something goes wrong it is hard to debug due to the many branches and edge cases. My blueprint is definitely not as smart, it only does one thing but tries to do it as well as possible.

So what does this blueprint do ?

It turns lights on or off and changes their brightness according to a motion and light sensor, and changes their color temperature according to the sun’s position. That’s all.

What doesn't it do ?

It doesn’t handle any edge cases. If you need a reversed light sensor, a manual conditional switch, RGB party lights, or anything fancy: use another blueprint. I recommend Blackshome's blueprint, it is well tested and documented.

How to use it ?

Add the blueprint to Home Assistant: Using automation blueprints (really read it if you never used a blueprint).

Then the automation configuration is (or at least should be) self-explanatory.

How does it work ?

This blueprint tries to follow the KISS principle, anyone with basic knowledge of Home Assistant automation should be able to understand and troubleshoot it.

Logic

Here is how values are computed:

Brightness

  • Brighter when ambient light is low
  • Dimmer when ambient light is high
  • Adjusts brightness smoothly between defined limits
max_b - (lux - low) * (max_b - min_b) / (high - low)

This formula linearly decreases brightness from max_b to min_b as the measured light (lux) increases between the low and high thresholds. If the light level is below low, brightness is set at max_b; if it’s above high, it’s clamped to min_b.

Example:

  • lux = 45
  • low = 15
  • high = 200
  • min_b = 20
  • max_b = 100%
100−(45−15)×(100−20)/(200−15)
=100−30×80/185
=100−12.97 
=87%

→ The lights are set to 87% brightness since the room is quite dark (depend on sensors).

Color Temperature

  • Warm when the sun is low (sunrise/sunset)
  • Cooler as the sun rises higher
  • Follows a smooth nonlinear curve based on solar elevation

min_ct + (max_ct - min_ct) * ( (elevation - e_min) / (90 - e_min) ) ** gamma

This equation maps the sun’s elevation to a color temperature between min_ct (warmest) and max_ct (coolest).
The elevation is first clamped between e_min (civil twilight) and 90° (sun at zenith), then normalized to a 0–1 scale.
The gamma value controls how quickly the color temperature transitions: lower gamma keeps the temperature warmer for longer; higher gamma shifts more quickly toward cooler tones.

Examples:

  1. Sun is low in the sky:
  • elevation = 12°
  • e_min = -6°
  • min_ct = 2000 K
  • max_ct = 4000 K
  • gamma = 0.8

norm = (12 - (-6)) / (90 - (-6)) = 18 / 96 = 0.1875
ct = 2000 + (4000 - 2000) (0.1875 ** 0.8)
= 2000 + 2000
0.261
≈ 2000 + 522
≈ 2522 K

→ The lights are set to ~2520 K, very warm because the sun is still low.

  1. Sun is near zenith:
  • elevation = 75°
  • e_min = -6°
  • min_ct = 2000 K
  • max_ct = 4000 K
  • gamma = 0.8

norm = (75 - (-6)) / (90 - (-6)) = 81 / 96 = 0.84375
ct = 2000 + (4000 - 2000) (0.84375 ** 0.8)
= 2000 + 2000
0.873
≈ 2000 + 1746
≈ 3746 K

→ The lights are set to ~3750 K, cooler as the sun is high.

Flowchart

Flow chart describing the blueprint process

Roadmap

  • Release a working blueprint
  • Improve logic for color temperature
  • Decide if adding an override sensor is fancy or not

Contributing

Issues and pull requests welcome.

About

Make your lights turn on, off, change their brightness and color temperature automatically.

Topics

Resources

License

Stars

Watchers

Forks