@nickraffy wrote:
I have an automation that changes the color of a light depending on the amount of time I have before I have to leave for work. Currently I use an automation that activates 1 minute prior to the indicator automation to take a snapshot of the lights current state and then another script that activates 1 minute after the indicator automation to restore the lights initial state. The indicator automation is set to run between a specific time period. I am wondering if there is a way to condense this into a single automation that runs the indicator action for a set amount of time? I tried looking into using a for loop with a 1 minute delay per loop but I don’t know that I can place an entire action within a for loop.
The time_to_leave sensor gives a value in minutes before I am supposed to leave and goes negative once the time has passed (resets every day at midnight). I currently update that sensor manually within the automation since it uses the now() function.
Indicator automation action:
data_template: brightness_pct: 30 color_name: >- {% set leave = states('sensor.time_to_leave')| int %} {% if leave > 2 %} green {% elif 0 < leave <= 2 %} yellow {% else %} red {% endif %} entity_id: light.living_room service: light.turn_on
The actions to take a snapshot and restore light state:
data: scene_id: leave_time_revert snapshot_entities: light.living_room service: scene.create
data: {} entity_id: scene.leave_time_revert service: scene.turn_on
Posts: 1
Participants: 1