Hello! I created one script with two fields: light and mode. I use these to apply effects to some lights.
Before any effect though, I created an scene to save the previous state:
service: scene.create
data:
scene_id: "{{ slugify(light) }}_snapshot_{{ slugify(mode) }}"
snapshot_entities: "{{ light }}"
alias: Save original state
Immediately after the scene, I’m sending a variety of effects based on mode.
And then I’ll call the previously created scene like this:
service: scene.turn_on
target:
entity_id: scene.{{slugify(light)}}_snapshot_{{ slugify(mode) }}
alias: Restore original state
But I’m facing one problem with two lights: Sometimes the effect starts up before the scene is created and that means the original state is lost.
Instead of adding 1~3 seconds delay after scene.create, I wanted to use a wait template, like this:
Create a script variable containing a unique name for the scene entity. I suggest using the current time, as a timestamp, because it’s an easy way to get a unique value.
That’s due to a typo I made in the second script variable’s definition.
Replace this:
e_id: 'scene.{{ oid }}'
with this:
e_id: 'scene.{{ s_id }}'
To make as_timestamp more robust, it should be supplied with a default value. If it can’t convert the supplied value to a timestamp it will report the default value (as opposed to failing with an error).