Return Light to previous state in automation

Hi,

I have an automation that changes the state of some light bulbs to red when my webcam is on. I’m having trouble figuring out how to get it to go back to it’s previous state. I’m hoping someone can look at my automation and tell me how to fix it.

alias: 'Notification: Conference Call ON'
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.edwardss_mac_mini_camera_in_use
    from: 'off'
    to: 'on'
  - platform: state
    entity_id: binary_sensor.edwardss_mac_mini_microphone_in_use
    from: 'off'
    to: 'on'
condition:
  - condition: time
    after: '08:00:00'
    before: '18:00:00'
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
action:
  - service: light.turn_on
    data:
      color_name: red
      brightness: 150
    entity_id: light.hue_living_rm_bulb_5
  - service: light.turn_on
    data:
      color_name: red
      brightness: 150
    entity_id: light.philips_gameroom_1
  - service: light.turn_on
    data:
      brightness: 75
    entity_id: light.lifx_mini_d_510f9d
  - service: script.pulse_madeas_light
    data: {}
mode: single

I would recommend using a scene snapshot to capture the entities as they were, then apply that scene on the inverse.

action:
  - service: scene.create
    data:
      scene_id: before
      snapshot_entities:
      - light.hue_living_rm_bulb_5
      - light.philips_gameroom_1
      - light.lifx_mini_d_510f9d
  - service: light.turn_on
    data:
      color_name: red
      brightness: 150
    entity_id: light.hue_living_rm_bulb_5
  - service: light.turn_on
    data:
      color_name: red
      brightness: 150
    entity_id: light.philips_gameroom_1
  - service: light.turn_on
    data:
      brightness: 75
    entity_id: light.lifx_mini_d_510f9d
  - service: script.pulse_madeas_light
    data: {}

- alias: "Return Lights via Scene Snapshot"
  trigger:
  - platform: state
    entity_id: binary_sensor.edwardss_mac_mini_camera_in_use
    from: 'on'
    to: 'off'
  - platform: state
    entity_id: binary_sensor.edwardss_mac_mini_microphone_in_use
    from: 'on'
    to: 'off'
  condition: []
  action:
  - service: scene.turn_on
    target:
      entity_id: scene.before

Thank you!! That worked! :grin: