Files
home-assistant-blueprints/blueprints/automation/apply_lighting_mode.yaml
John Ogle 96ab81f7ae Fix Adaptive mode not restoring lighting conditions
The blueprint was unconditionally overriding use_defaults to 'current',
preventing modes from specifying their own use_defaults value. This caused
Adaptive mode (which uses use_defaults: 'configuration') to keep the current
settings instead of resetting to configuration defaults.

Modified the data template to conditionally add use_defaults: 'current' only
when not already present in al_config, allowing modes like Adaptive to use
their specified value while maintaining backward compatibility.
2025-12-21 18:27:46 -08:00

96 lines
2.8 KiB
YAML

blueprint:
name: Apply Lighting Mode Settings
description: Data-driven mode application using convention-based entity lookup
domain: automation
input:
mode_input_select:
name: Mode Input Select
description: Dropdown helper tracking current lighting mode
selector:
entity:
domain: input_select
adaptive_lighting_switch:
name: Adaptive Lighting Switch
description: AL switch for this room
selector:
entity:
domain: switch
integration: adaptive_lighting
led_color_entity:
name: LED Color Entity (Optional)
description: Number entity for LED color (e.g., Inovelli switch)
default: {}
selector:
entity:
domain: number
mode: restart
max_exceeded: silent
trigger:
- platform: state
entity_id: !input mode_input_select
- platform: homeassistant
event: start
variables:
mode_select: !input mode_input_select
al_switch: !input adaptive_lighting_switch
led_entity: !input led_color_entity
mode: "{{ states(mode_select) }}"
settings_entity: "input_text.adaptive_lighting_settings_{{ mode | lower | replace(' ', '_') }}"
settings: "{{ states(settings_entity) | from_json }}"
behavior: "{{ settings.behavior | default('adaptive_lighting') }}"
manual_control: "{{ settings.manual_control | default(false) }}"
al_config: "{{ settings.al_config | default({}) }}"
led_color: "{{ settings.led_color | default(170) }}"
action:
# Always set manual_control state based on mode settings
- service: adaptive_lighting.set_manual_control
data:
entity_id: "{{ al_switch }}"
manual_control: "{{ manual_control }}"
# Execute behavior-specific actions
- choose:
# Behavior: adaptive_lighting
- conditions: "{{ behavior == 'adaptive_lighting' }}"
sequence:
- service: adaptive_lighting.change_switch_settings
target:
entity_id: "{{ al_switch }}"
data: >
{% if 'use_defaults' not in al_config %}
{{ al_config | combine({'use_defaults': 'current'}) }}
{% else %}
{{ al_config }}
{% endif %}
# Behavior: scene
- conditions: "{{ behavior == 'scene' }}"
sequence:
- service: scene.turn_on
target:
entity_id: "{{ settings.scene_entity }}"
# Behavior: script
- conditions: "{{ behavior == 'script' }}"
sequence:
- service: script.turn_on
target:
entity_id: "{{ settings.script_entity }}"
# Update LED color if entity provided
- if:
- condition: template
value_template: "{{ led_entity not in [none, {}, ''] }}"
then:
- service: number.set_value
target:
entity_id: "{{ led_entity }}"
data:
value: "{{ led_color }}"