Hi
I’m storing the brightness (dim level) of my lights in a scene that is created on the fly when turning off the light. And then restore the same brightness when turning on the light again by turning on that scene.
My code works, but I have to create two automations (one to store, one to restore the brightness) for each light. Therefore, I was trying to create two more generic automations that would take a list of all my lights and then to the rest dynamically. The generic brightness store automation would create a scene with a scene_id based on the light entity_id that had triggered. However, I can’t get it to work.
Here the code that works for one light (and which I would have to copy and adapt for each light):
- alias: Light DaliBroadcast Save
trigger:
- platform: state
entity_id: light.dalibroadcast
attribute: brightness
condition:
- condition: numeric_state
entity_id: light.dalibroadcast
attribute: brightness
above: '0'
action:
- service: scene.create
data:
scene_id: pb_dalibroadcast
snapshot_entities:
- light.dalibroadcast
mode: single
- alias: Light DaliBroadcast Restore
trigger:
- platform: state
entity_id: light.dalibroadcast
from: 'off'
to: 'on'
condition: []
action:
- service: scene.turn_on
data: {}
entity_id: scene.pb_dalibroadcast
mode: single
Now I’d would like to have something like this:
- alias: Light Generic Save
trigger:
- platform: state
entity_id: light.light1, light.light2, light.light3 #here I would like to have a list of all my lights
attribute: brightness
condition:
- condition: numeric_state
entity_id: light.light1, light.light2, light.light3 #here I would like to have a list of all my lights
attribute: brightness
above: '0'
action:
- service: scene.create
data:
scene_id: scene_light1 # This scene_id would be created dynamically based on the light that triggered above, allways with the same syntax, e.g. "scene_LIGHT-ENTITY-ID"
snapshot_entities:
- light.light1 # This entity_id would be created dynamically based on the light that triggered above
mode: single
- alias: Light Generic Restore
trigger:
- platform: state
entity_id: #here I would like to have a list of all my lights
from: 'off'
to: 'on'
condition: []
action:
- service: scene.turn_on
data: {}
entity_id: scene_light1 # This scene_id would be calculated based on the light that triggered above, and with the syntax from the first automation.
mode: single