Save color and brightness of a light whenever is changed. Apply last color and brightness after an automation changed them

I have a light in my living room which I might set at different colors and brightness values for normal use. I then use a script to setup “cinema mode” which turns it to blue and 5% brightness. When I then turn off the light and turn it back on without activating cinema mode it turns on with blue and 5pc brightness. I would like an automation which saves the color and brightness it was last on before cinema mode was activated and applies it to the light the next time I turn it on unless I am activating again cinema mode.

Can someone please point a newbie in the right direction? I have searched similar posts but the best I could find was not this specific use case as the lights were already on when a script changed them, which is not always my case.

As it is my first post, also happy to get the feedback on how I described the issue.

Thanks,
Nick

If the lights are off there is no brightness value to save.

Thanks Tom,

yes, correct, this is why i was looking for a solution that would allow me to save the state of color and brightness of the light whenever it was last on before the cinema mode script was invoked.

Hope this clarifies

Out of curiosity , do you have any disabled entities associated with the light you mentioned?

Nope, all entities enabled.

and power on behavior is set?

the light is controlled through smartthings integration, not sure where i would see the option to control the behavior, however in my use case there is no interruption of power.

Smart things is most likely not transferring the last state to HA. Although, I believe you can create a template sensor for that info. The log book keeps the info.

That is correct. However when the light is on i can see the color and value in the state of the entity in HA. So what i am trying to understand is:

  1. how do i capture it and store it when is on or changed
  2. how do i re-set it to those values the first time light is turned on after the cinema mode script was executed.

I would create a scene when the light is turned on or changed and apply the scene after your other script runs.

See this thread:

Issuing the same problem, i find a solution creating a sensor that change value only if the state of the Bulb is “on”.
Create a sensor named “bulb_last_color” and use this template:

{% if is_state('light.0x90fd9ffffe926c6f','on') %}
{{ state_attr('light.0x90fd9ffffe926c6f','rgb_color') }}
{% else %}
{{ states('sensor.bulb_last_color') }}
{% endif %}

The sensor will always keep color value and will never be null.