Scene snapshot is not restored

Hello dear community,

I am trying to setup a simple automation that when something happens the state of the of a Shelly RGBW should be snapshot into a scene, than a scene to let the LED flash is loaded and afterwards the saved scene should be restored.
I searched for similar examples before asking and found out that adding a delay after creating the snapshot helped other people, but it does not seem to be my case.
I ran the automation directly to debug it and I see that a new scene is created, the LEDs are flashed but after the delay of 5 seconds they are turned off without restoring the saved state. I even tried turning the LEDs on before running the automation, but nonetheless they are turned off at the end of the automation and if I check the configuration of the Shelly in the web UI I still see the red light state. To me it seems that the state of the Shelly is not saved correctly. I also tried increasing the first delay to 5 seconds, but nothing changed.

Here is the yaml of my automation:

alias: Alarm
description: Flash LEDs
triggers:
  - type: opened
    device_id: c1962cbbbbd5e4aa4a530136cb096edd
    entity_id: 4d0af1183f046e0cb5d6d4a33a727dd6
    domain: binary_sensor
    trigger: device
conditions:
  - alias: Somebody is in the room
    condition: or
    conditions:
      - condition: device
        device_id: 097ea2f0b420cdd14e856d7968dddfa5
        domain: media_player
        entity_id: 199c8e3c48e9f2b4997255c2e4740c82
        type: is_on
      - condition: device
        type: is_on
        device_id: 1714887379bbd9bfcc4adf624c0bfb82
        entity_id: a899e0a8a7a712f30b88d6fd3c924a84
        domain: light
      - condition: device
        type: is_on
        device_id: dbe6e311d5c99017ca398e221b8af0e3
        entity_id: a04b1dac0d47d36fb47579e124babc5e
        domain: light
actions:
  - sequence:
      - alias: Save the state
        action: scene.create
        metadata: {}
        data:
          scene_id: saved_led_status
          snapshot_entities:
            - light.shelly_rgb
      - delay: 2
      - alias: Active red light scene
        action: scene.turn_on
        target:
          entity_id: scene.red_light
        data: {}
      - delay: 5
      - alias: Restore the previous state
        action: scene.turn_on
        target:
          entity_id: scene.saved_led_status
        data: {}
mode: single

Do you spot an error?
Thanks for your support.

Hello Carlo,

I thought I had heard there was an issue opoen for scenes saving color. Not certain. I would search the HA issues and maybe there is an answer there.

¯\(ツ)
Reporting issues - Home Assistant.
GitHub · Where software is built.

Thank you @Sir_Goodenough, with your pointer I found this issue Running scene.create and then restoring it doesn't work properly on lights that are turned off · Issue #125807 · home-assistant/core · GitHub and it seems that it could be an explanation for my problem.

I will double check it, because I believe I also tried saving a snapshot with the light on.
I also do not understand why that should be a problem, because both the web interface of the Shelly and the live editing of a scene with Home Assistant show the proper status of the light even if it’s turned off.

During my research I also find a possible workaround WTH can't scene restore the state of off entities - #6 by septillion which is better than nothing, even if not perfect.
I’ll recheck my automation to see if the snapshot scene is created correctly when the light is on and in that case I will simply have to extend my automation with an if and the workaround for the off-branch.

I’ll post an update once I know more.