Hi, when I activate my button
( input_boolean.tema_romantico ) I would like automation to start taking a snapshot of the following lights: light.yeelight_colorc_0x1b0ffc9a light.yeelight_colorc_0x18906fb6 light.yeelight_colorc_0x189042ff light.faretti_camera_da_bed light.suprema_smart_controller_rgbww_4
to then start a script already created that changes the brightness and color of the lights in question. When the input_boolean.tema_romantico is turned off I would like it to load the snapshot made previously.
I tried to search the internet for how to do it, but I only found this piece of code that could help me but I don’t know how to complete it:
alias: Camera da letto snapshot
description: ''
trigger:
- entity_id: input_boolean.tema_romantico
from: 'off'
platform: state
to: 'on'
condition: []
action:
- data:
snapshot_entities: light.yeelight_colorc_0x1b0ffc9a light.yeelight_colorc_0x18906fb6
light.yeelight_colorc_0x189042ff light.faretti_camera_da_letto light.suprema_smart_controller_rgbww_4
service: scene.create
- service: script.1643407098523
- delay: 00:00:04
When the input_boolean is turned on, the automation creates a snapshot scene of the five lights, named scene.lights_before, and then executes your script.
When the input_boolean is turned off, the automation turns on scene.lights_before thereby restoring the previous state of the five lights.
That’s due a small but significant error I made in the original example. Replace the template’s outer single-quotes with double-quotes (I have already corrected the example posted above).
Change this:
'{{ trigger.to_state.state == 'on' }}'
to this:
"{{ trigger.to_state.state == 'on' }}"
The rule is that the template’s outer quotes must not be identical to its inner quotes.
If you notice the automation is slightly different because when I opened it in the graphical interface it always appeared to me “Save”, clicking on it added this line of code: