Help: Last state scene for lights not working

I have configured a script that is being called by an automation which is triggered by pressing the main door ring bell button.
The main goal of the script would be:
Get the current initial light state at the moment of pressing the main door ring bell, then make the light blinking for 5 seconds and finally get back to the lights initial state at the moment of pressing the main door ring bell.
Somehow my code is not working, the light starts to blink but then won’t get back to its initial state. What am I missing?
Thanks in advance!


alias: ScriptLightNotifications
sequence:
  - service: scene.create
    data:
      scene_id: lights_previous_state
      snapshot_entities: light.z2mgrouplightsbasementtvroom01_01
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: mqtt.publish
    data:
      qos: 0
      retain: false
      topic: zigbee2mqtt/Z2MGroupLightsBasementTVRoom01_01/set
      payload: "{\"scene_recall\": 2, \"effect\": \"breathe\"}"
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - scene: scene.lights_previous_state
    enabled: true
mode: single

I haven’t performed tests to confirm it but your results suggest a snapshot scene doesn’t record the state of a light’s effects (just the basics like the light’s state, brightness, color).

After you created the snapshot scene, you applied an effect to the light (“breathe”). When you restored the scene, it had no record of what effect, if any, the light had previously so the light continues to “breathe”.

1 Like

I found out by myself. Somehow I have to turn off the light completely after blinking, then it works.
Here’s the code in case that might help someone else:

alias: ScriptPicabooLightNotifications
sequence:
  - service: scene.create
    data:
      scene_id: lights_previous_state
      snapshot_entities: light.z2mgrouplightsbasementtvroom01_01
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: mqtt.publish
    data:
      qos: 0
      retain: false
      topic: zigbee2mqtt/Z2MGroupLightsBasementTVRoom01_01/set
      payload: "{\"scene_recall\": 2, \"effect\": \"breathe\"}"
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: mqtt.publish
    data:
      qos: 0
      retain: false
      topic: zigbee2mqtt/Z2MGroupLightsBasementTVRoom01_01/set
      payload: "{\"scene_recall\": 0}"
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: scene.turn_on
    data: {}
    target:
      entity_id: scene.lights_previous_state
mode: single

Thanks anyway @123 !

EDIT: Oh, I forgot to mention, I also changed from the native scene call to call the scene.turn_on as a service on the very last step.

Shouldn’t make a difference which way you called the snapshot scene; both simply activate the scene.

The key is that you effectively disabled the effect by turning the light off with {"scene_recall": 0}".

1 Like