Return light to previous state after automation

I have a workaround… I believe the problem is when the light is off, the color, brightness, and temperature state isn’t being captured by scene.create. If you turn on the light and wait a short amount of time (250ms) you can get the previous state. That requires saving two scenes instead of one though, the first to capture the power state, and the second to capture the color, brightness, and temperature. Here is an example of a red/blue siren that correctly sets the previous power, color, brightness, and temperature after the scripts runs:

alias: Front Light Siren
sequence:
  - service: scene.create
    data:
      scene_id: front_light_before_siren_script
      snapshot_entities: light.tasmota
  - type: turn_on
    device_id: 9e5f76d63dfa4149a5a9bce4e2bd390e
    entity_id: light.tasmota
    domain: light
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 250
  - service: scene.create
    data:
      scene_id: front_light_after_on_before_siren_script
      snapshot_entities: light.tasmota
  - repeat:
      count: '10'
      sequence:
        - scene: scene.cloudfree_light_red
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 500
        - scene: scene.cloudfree_light_blue
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 500
  - service: scene.turn_on
    target:
      entity_id: scene.front_light_after_on_before_siren_script
  - service: scene.turn_on
    target:
      entity_id: scene.front_light_before_siren_script
mode: single
icon: mdi:alarm-light-outline
5 Likes