Return light to previous state after automation

Hello everyone, what is the best way to remember current light (state, colour, brightness) and return it later in automation or script if required? I thought I would hold global variables as MQTT sensors, so in automation I’m able to save state but I’m unable to apply settings to the light when needed.

2 Likes

thank you, super easy :slight_smile:

For those still wanting to accomplish this without jumping through too many hoops.
You can make use of scenes to save the state beforehand and then reapply it when you want to revert back to the previous state. Better than creating many inputs in the config. Can save the state of many entities in one go.

- id: 'doorbell_pressed'
  alias: 'Doorbell Pressed'
  description: 'Flash lights light blue when someone presses the doorbell'
  trigger:
  - entity_id: binary_sensor.doorbell_button 
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      scene_id: doorbell_notification_revert
      snapshot_entities: 'light.living_room,light.kitchen'
    service: scene.create
  - data:
      effect: Facebook
      entity_id: light.living_room
    service: light.turn_on
  - data:
      effect: Facebook
      entity_id: light.kitchen
    service: light.turn_on
  - delay: 00:00:04
  - data:
      entity_id: scene.doorbell_notification_revert
    service: scene.turn_on
10 Likes

How did you get this to work?

I have one automation that does this:

and then another one that does this.

But it doesnt revert?