Save and Restore Entity States

Hi,

i’m trying to automate a setting for watching TV. i already created a scene with all my lights properly set. The setting of the lights works, but now i try to restore the state of the lights before activating the scene. I stumbled across the documentation Scenes and this is my solution, which unfortunately does not work.

# in scripts.yaml
tv_mode_on:
  alias: "TV Modus aktivieren"
  sequence:
    - service: scene.create
      data:
        scene_id: before_tv
        snapshot_entities:
          - switch.wandlampe
          - switch.d1
          - light.stehlampe_zigbee
          - switch.d2
          - light.kugellampe
    - service: scene.turn_on
      target:
        entity_id: scene.fernsehen

tv_mode_off:
  alias: "TV Modus deaktivieren"
  sequence:
    - service: scene.turn_on
      target:
        entity_id: scene.before_tv

i also created a switch to toggle the mode:

tv_mode:
        friendly_name: tv_mode
        turn_on:
          service: script.turn_on
          entity_id: script.tv_mode_on
        turn_off:
          service: script.turn_off
          entity_id: script.tv_mode_off

Can anybody tell me what i am doing wrong?
Thanx!

Any chance you restarted HA or reloaded scenes in between when you ran tv_mode_on and tv_mode_off? Note that modifying any scene in the UI editor causes all scenes to be reloaded, even if you don’t explicitly press the “Reload scenes” button.

Scenes created via scene.create don’t survive restarts of HA or reloads of the scene integration.

no, i waited for about 10 seconds or so before toggling the switch. If i run the script tv_mode_on and tv_mode_off from the developer settings, everything works fine.

Edit:

OMG, i am so stupid…

turn_off:
          service: script.turn_OFF # it has to be script.turn_on 
          entity_id: script.tv_mode_off

thank you for your help