"Scenes on the fly" doesnt set default color if light is off in first

I created automation. If its trigged, light is setting yellow and blue for some seconds. This is working well but i want to set light’s color and its state what it is before automation. Thats why i use scenes on the fly.

If light is on first, everything is working and color is setting its default, but light is closed in beginnig, its closed after automation but its color stayed in blue.

What will I do to make color back to first color before automation started when first state of light is closed.

action:
  - service: scene.create
    data:
      scene_id: before
      snapshot_entities: light.calisma_ana_isik
  - repeat:
      count: 2
      sequence:
        - service: light.turn_on
          data:
            color_name: yellow
          target:
            entity_id: light.calisma_ana_isik
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
        - service: light.turn_on
          data:
            color_name: navyblue
          target:
            entity_id: light.calisma_ana_isik
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
  - service: scene.turn_on
    target:
      entity_id: scene.before
    data: {}

Yes, this is how it works. Your scene before hand is capturing the light as off. If you want to only capture the on state, first turn the light on, then capture the scene, then run your repeat, then recall the before scene.

You can use choose to conditionally turn the light on if the light is off.

1 Like

Related question to Petro:
How can we see the content of the snapshot “scene_id: before” from HA, is there a way?

I want it to work when it’s off too and it works fine, but when light off and automation works then it doesn’t return to its original color. Although the light is not navyblue in the initial state, it remains navyblue if i turn light back on.

I think that Petro’s point is that you last set the light to be blue before turning it off…

        - service: light.turn_on
          data:
            color_name: navyblue
          target:
            entity_id: light.calisma_ana_isik
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0

So to fix this I think you should add in final change back to yellow, like this:

        - service: light.turn_on
          data:
            color_name: navyblue
          target:
            entity_id: light.calisma_ana_isik
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
        - service: light.turn_on
          data:
            color_name: yellow
          target:
            entity_id: light.calisma_ana_isik
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0

Then when you next run “scene.create” it will see a yellow setting on the lamp. That’s what I think you need to do.

I don’t believe there is a way.

Right, because it doesn’t have a color to restore to. If you want to capture the color, the light needs to be on. There’s no way around that.

Ok, a pity because sometimes it acts like it’s haunted and it would be nice to have access to it to troubleshoot. Thanks for responding anyway. :+1:

Any oddness is usually caused by what you’re hardware reports and how often it reports.

1 Like

Yes, You are right the off light has no color variant so it was just changing the state.

I add if condition “if light is closed ,i open it and snapshot its value. After automation then recall them and close the lamp.
Thanks

On the fly scenes are not destroyed at the end of the automation.
But it will be if you restart HA or if you call the service scene.reload
And it will not be what you expect if in the meantime the automation (or another) has started (again) and recreated a scene with the same name.

You can also read my question

1 Like

You can also create 2 scenes
before_on
<light.turn_on>
after_on

then scene.turn on in the opposite order.
after_on
before_on

What is the interrest? Well, if it was off, it will get its color back and off. If it was on before the light.turn_on, it will not off.
Therefore you’ll get the exact situation prior to your automation, same color, same on/off status.

I turn it on if light is off and then create scene.

  alias: FB Gol Atarsa Işık Yanıp Sönsün OFF
description: Fenerbahçe gol attığında lambayı flash yap
trigger:
  - platform: state
    entity_id:
      - sensor.team_tracker
    attribute: team_score
condition:
  - condition: template
    value_template: >-
      {{ trigger.to_state.attributes.team_score | int >
      (trigger.from_state.attributes.team_score | int ) }}
  - condition: state
    entity_id: light.oturma_kapi_isik
    state: "off"
action:
  - service: light.turn_on
    data: {}
    target:
      entity_id: light.oturma_kapi_isik
  - service: scene.create
    data:
      scene_id: before
      snapshot_entities: light.oturma_kapi_isik
  - repeat:
      count: 2
      sequence:
        - service: light.turn_on
          data:
            color_name: yellow
          target:
            entity_id: light.oturma_kapi_isik
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
        - service: light.turn_on
          data:
            color_name: navyblue
          target:
            entity_id: light.oturma_kapi_isik
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
  - service: scene.turn_on
    target:
      entity_id: scene.before
    data: {}
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.oturma_kapi_isik
  - service: scene.reload
    data: {}
mode: single


1 Like

Very interesting. I think that this explains some of my (haunted) problems.

I have a porch light which is automated to come on a sunset and turn off at 22:30. It’s brightness is set by a light-sensor so that the brightness increases over time, as needed.
I also have a porch door sensor which when triggered will turn the porch light at max brightness for a duration of 2 mins and then afterwards restore the “scene: before” but was acting oddly as the light was getting stuck in a max brightness state.

I now understand that if somebody opens the porch door twice during that two minute period, scene.create will be run twice, with the second run gathering the state of the light at max brightness preventing the light from returning back to the original state which was set by the light-sensor.
I think that the solution proposed to you by CentralCommandMike will also fix my problem, but I worry that I’ll end up with a scene snapshot for each door-open command unless I somehow perform a scene: reload to clear out the history… but I’ll give it a try!

It is what I need now. Can you please explain it again? What is the order of doing it? Currently, I just create a snapshot named scene.before_on and load it at the end and have the problem like the OP that the colors have changed. So I can let this be like it is as I understand you. Then I turn the lights on shortly and create another snapshot.

Then I would do what I want like flashing all the lights in different colors. Then activate the after_on scene to get the colors back and activate the before_on scene to get them off again.

Not sure to follow what you want to achieve.
To solve the OP, you would have to do the following:

  • create a scene to capture current state of light(s) (on/off)
  • on the light(s) without any data, only target
  • create another scene to capture the color of the light(s) before operation(s)
  • do whatever you like with the light(s)
  • restore the “color” scene: so when on again it will be the color you like
  • restore the “state” scene: what was on (resp. off) is back on (resp. off),

It is not perfect as it will not on to the right color, what the OP wanted, but it is one way to do it.

1 Like