Scene.create bug?

I am using scene.create in the same way as in the last example from this page:

My automation looks like this:

  - alias: porch light change when door locked
    trigger:
      - platform: state
        entity_id: lock.conexis_l1
        to: "locked"
    action:
      - service: scene.create
        data:
          scene_id: before
          snapshot_entities:
          - light.porch_light
      - delay: 00:00:01
      - service: light.turn_on
        entity_id: light.porch_light
        data:
          xy_color: [0.701, 0.299] # red
          brightness: 255
      - delay: 00:00:05
      - service: scene.turn_on
        target:
          entity_id: scene.before

The problem is that the ‘before’ scene, despite what it says in the docs, is not overwritten the next time this automation runs.

I end up with new ‘before’ scenes constantly being created, and they persist until I restart.

So after a few days, when I right-click the Mac HA app (which shows scenes in the contextual menu) I get this abomination:

Everyone in my family also get the same huge list of ‘before’ scenes in the iOS HA app’s complication on their apple watches.

My ‘scenes’ page looks like this, none of these scenes can be deleted from the UI:

Does anyone know what’s wrong here? Why doesn’t scene.before get overwritten?

Alternatively, can I prevent any scenes from appearing inthe Mac App contextual menu, or in the Apple watch complication?

Thanks!

I can’t replicate the problem you described using 2023.11.2.

Here’s how I tested it. In Developer Tools > Services, I executed the following service call three times.

Only one instance of scene.before appeared In Developer Tools> States and in Settings > Automations and Scenes > Scenes. The scene entity cannot be deleted but this is expected because it’s meant to exist until Home Assistant is restarted. I restarted and the one instance of scene.before was eliminated.

I don’t know why you’re seeing multiple instances of the scene.

Unless someone else knows the cause (give it at least a day or three), you may need to report this as an Issue in Home Assistant’s GitHub repository. However I don’t know if this should be reported in Frontend or Core repository; it may be either a UI bug (Frontend) or a Scene integration bug (Core). I suggest you start by posting the Issue in Core and wait for advice from a member of the development team.

Thanks for investigating :grinning:

I’ve been fiddling around with it and I think it’s because I have 4 automations, all of which are based on that same example, and they all use ‘before’ as the temporary scene. I’ve changed them to use different scene names, and now instead of hundreds of ‘before’ scenes, I just have a list of the 4 temporary scenes.

I’ve then removed these 4 unwanted scene names by adding a scene.reload to the end of each automation. This reloads my scenes (I dont have any), and wipes out the temporary scene after each run.

  - alias: porch light change when door locked
    trigger:
      - platform: state
        entity_id: lock.conexis_l1
        to: "locked"
    action:
      - service: scene.create
        data:
          scene_id: porch_light_status_locked
          snapshot_entities:
          - light.porch_light
      - delay: 00:00:01
      - service: light.turn_on
        entity_id: light.porch_light
        data:
          xy_color: [0.701, 0.299] # red
          brightness: 255
      - delay: 00:00:05
      - service: scene.turn_on
        target:
          entity_id: scene.porch_light_status_locked
      - service: scene.reload