I´m trying to write a few automations (might have been better to do this as a script in retrospect) and i think I have the logistics of it down but it does not seem to like the value in the first automation for some reason, probably missing something apparent that I have been staring myself blind on past hour.
Someone that has a good idea on the code below?
# Automation to save the current brightness of all lights in the Living Room area
- id: save_brightness
alias: Save Brightness
trigger:
- platform: time
at: '22:00:00'
action:
- service: variable.set_variable
data_template:
variable: saved_brightness
value:
{% for state in states.light %}
{% if state.attributes.area in ["Living Room", "Bedroom"] %}
- light: '{{ state.entity_id }}'
brightness: '{{ state.attributes.brightness }}'
{% endif %}
{% endfor %}
# Automation to adjust the brightness of all lights in the Living Room area during the time range
- id: adjust_brightness
alias: Adjust Brightness
trigger:
- platform: time
at: '22:00:05'
action:
- service: light.turn_on
data_template:
entity_id: '{{ item.light }}'
brightness_pct: '{{ (item.brightness * 0.5)|int }}'
loop: '{{ saved_brightness }}'
# Automation to return the brightness of all lights in the Living Room area to their saved state
- id: restore_brightness
alias: Restore Brightness
trigger:
- platform: time
at: '06:00:00'
action:
- service: light.turn_on
data_template:
entity_id: '{{ item.light }}'
brightness: '{{ item.brightness }}'
loop: '{{ saved_brightness }}'