Hi, trying to work out an automation that needs to capture and store the state and brightness of lights prior to running and then restore them to their previous state when finished.
I’ve defined the variables in the action block so the automation can be run manually if needed.
HA does not like the variables in the If/Then portion. Getting an “Automation Unavailable, expected float for dictionary value @ data[brightness_pct]”
Understand variables are sequence specific; could it be loosing the variable when it gets to the end? I can’t redeclare because the automation is turning on those lights in order to function, so - their value would not be their initial state at that point.
action:
- variables:
hallway_lights_state: "{{states('light.upstairs_hallway_can_lights')}}"
hallway_lights_brightness: "{{((state_attr('light.upstairs_hallway_can_lights','brightness') | int / 255 * 100)) | round(0)}}"
project_room_lights_state: "{{states('light.project_room')}}"
project_room_lights_brightness: "{{((state_attr('light.project_room','brightness') | int / 255 * 100)) | round(0)}}"
... does stuff here ...
- if:
condition: template
value_template: "{{ hallway_lights_state == 'off' }}"
then:
- type: turn_off
device_id: 8caefdd28db37208d31e4ad01d500e90
entity_id: light.upstairs_hallway_can_lights
domain: light
else:
- type: turn_on
device_id: 8caefdd28db37208d31e4ad01d500e90
entity_id: light.upstairs_hallway_can_lights
domain: light
brightness_pct: "{{ hallway_lights_brightness }}"