Nice solution, something lke thisshould part of the standard featureset!
If I understand this correctly it requires all light.turn_xxx actions to be replace by staterestore, where you store (cache) the attributes so they can be reapplied when needed.
For some situations it would be nice not to rely on a cached value but to get/retrieve the atributes from the actual light and store it in your component. That will make automations foulproof; like
Store light attributes entity_id: light.light01
do something with light.light01(eg flash or set brightness)
restore light attributes entity_id: light.light01
The solution does that. It copies the current attributes of the device and stores it. When you call restore, the cache values are enacted. So the flow is like this:
Capture current state
store it
push state from script invocation
....
Call Restore
if the state hasn't changed then apply cached values from initial contact
if it has changed, do nothing.