Last active
September 17, 2025 07:32
-
-
Save Gnzlt/e3ba39017b2889ea54554383693d78e5 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint - Dynamic Light Brightness
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
| blueprint: | |
| name: "Dynamic Light Brightness (Lux Based)" | |
| description: > | |
| This blueprint dynamically adjusts a light's brightness to complement the ambient light levels detected by an illuminance (lux) sensor. | |
| It maps a defined range of lux values (from a minimum to a maximum) to a corresponding brightness range (e.g., 10 lux → 10% brightness, 500 lux → 100% brightness). The brightness is calculated using linear interpolation, ensuring smooth transitions as the ambient light changes. | |
| The automation is only active when the target light is already turned on. | |
| **Key Features:** | |
| - **Lux & Brightness Ranges:** Set minimum and maximum thresholds for both the lux sensor and the light's brightness percentage. | |
| - **Dynamic Threshold:** The maximum lux threshold can be set with a static value or linked to an `input_number` helper for dynamic adjustments via your dashboard. | |
| domain: automation | |
| input: | |
| target_light: | |
| name: "Light to Control *" | |
| description: "The light entity that will be controlled. The automation only runs if this light is ON." | |
| selector: | |
| entity: | |
| domain: light | |
| lux_sensor: | |
| name: "Illuminance (Lux) Sensor *" | |
| description: "The sensor that measures ambient light in lux." | |
| selector: | |
| entity: | |
| domain: sensor | |
| device_class: illuminance | |
| max_lux_static: | |
| name: "Maximum Lux Value (Static)" | |
| description: "Use this if NOT using an Input Number. When lux is at/above this value, the light is at max brightness." | |
| default: 500 | |
| selector: | |
| number: | |
| min: 10 | |
| max: 2000 | |
| step: 10 | |
| unit_of_measurement: lux | |
| max_lux_entity: | |
| name: "Maximum Lux Value (from Helper)" | |
| description: "(Optional) Use an Input Number helper to set the maximum lux value dynamically. This overrides the static value above." | |
| default: | |
| selector: | |
| entity: | |
| domain: input_number | |
| min_lux: | |
| name: "Minimum Lux Value" | |
| description: "When the lux level is AT or BELOW this value, the light will be at its minimum brightness." | |
| default: 50 | |
| selector: | |
| number: | |
| min: 0 | |
| max: 1000 | |
| step: 10 | |
| unit_of_measurement: lux | |
| max_brightness: | |
| name: "Maximum Brightness" | |
| description: "The brightness of the light when the lux level is at its maximum." | |
| default: 100 | |
| selector: | |
| number: | |
| min: 1 | |
| max: 100 | |
| mode: slider | |
| step: 1 | |
| unit_of_measurement: '%' | |
| min_brightness: | |
| name: "Minimum Brightness" | |
| description: "The brightness of the light when the lux level is at its minimum." | |
| default: 1 | |
| selector: | |
| number: | |
| min: 1 | |
| max: 100 | |
| mode: slider | |
| step: 1 | |
| unit_of_measurement: '%' | |
| mode: single | |
| max_exceeded: silent | |
| variables: | |
| lux_sensor: !input lux_sensor | |
| max_lux_static: !input max_lux_static | |
| max_lux_entity: !input max_lux_entity | |
| min_lux: !input min_lux | |
| max_brightness: !input max_brightness | |
| min_brightness: !input min_brightness | |
| max_lux: > | |
| {% if max_lux_entity is not none and max_lux_entity != '' %} | |
| {{ states(max_lux_entity) | float(500) }} | |
| {% else %} | |
| {{ max_lux_static }} | |
| {% endif %} | |
| target_brightness: > | |
| {% set lux = states(lux_sensor) | float(0) %} | |
| {# Calculate brightness using linear interpolation #} | |
| {% set brightness = min_brightness + (lux - min_lux) * (max_brightness - min_brightness) / (max_lux - min_lux) %} | |
| {# Clamp the result between min/max brightness and round it #} | |
| {{ [min_brightness, brightness, max_brightness] | sort | median | round(0) }} | |
| trigger: | |
| - platform: state | |
| entity_id: !input lux_sensor | |
| - platform: state | |
| entity_id: !input max_lux_entity | |
| - platform: state | |
| entity_id: !input target_light | |
| from: 'off' | |
| to: 'on' | |
| condition: | |
| - condition: state | |
| entity_id: !input target_light | |
| state: 'on' | |
| - condition: template | |
| value_template: "{{ states(lux_sensor) not in ['unknown', 'unavailable'] and states(lux_sensor) | is_number }}" | |
| - condition: template | |
| value_template: "{{ max_lux > min_lux }}" | |
| action: | |
| - service: light.turn_on | |
| target: | |
| entity_id: !input target_light | |
| data: | |
| brightness_pct: "{{ target_brightness }}" | |
| transition: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment