Restoring light to previous state

I want my light to shortly glow up and after some time return to whatever brightness it had before.
The scripts reads current brightness from one lightbulb and stores its value into a helper. That part works but when trying to restore it back to its original state, I get a weird number.
Any ideas what I am doing wrong?

Receiving error: expected int for dictionary value @data(brightness)

boostlight:
  alias: Boostlight
  mode: single
  sequence:
  - data_template:
      entity_id: input_number.old_brightness
      value: "{{ states.light.kitchen1.attributes.brightness | int }}"
    service: input_number.set_value
  - scene: scene.scene_dim_kitchen_lights
  - delay: 00:00:05
  - data:
      brightness: "{{ states.input_number.old_brightness.state | int }}"
    entity_id: light.kitchen_lights
    service: light.turn_on

I would do this in NodeRED. I would store the value of the previous state as a global variable, then put a timer on the flow, then use the global variable as the brightness setting when calling the light service again.

Sorry - not using NodeRed - but thats exactly what I’m trying to do in a script. Using a HELPER as a global variable

It is possible to do this. Return light to previous state after automation

This is the example in that post:

- 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
3 Likes

But then I would have to use snapshots of a scene i guess. I want to directly control ie. two lightbulbs in a group and revert to previous state. Why am I receiving an INT error?

Change data to data_template (thanks god this will be changed in 0.115) in the part where you set the brightness for the bulb.

Also @poudenes suggested solution doesn’t need to have a scene, it creates a scene on the fly, which can afterwarda be restored, I think it’s exactly what you are looking for.

Thanks - I will give it a try
But still when using data_template I receive the error message

data_template:
  brightness: '{{ states(''input_number.old_brightness'') | int(0) }}'
entity_id: light.kitchen_lights
service: light.turn_on

Your double quotes are actually two single quotes side by side.

You have ‘’ <- Two singles
Should have " <- Double

Even on
brightness: “128” i receive the error

What do you get when you enter this in template editor?

{{ states('input_number.old_brightness') | int }}

I even get the error when enterinng
brightness: 255 (or any other number) I get
Receiving error: expected int for dictionary value @data(brightness)

Can you please show your full code again please.

boostlight:
  alias: Boostlight
  mode: single
  sequence:
  - data_template:
      entity_id: input_number.old_brightness
      value: '{{ states.light.kitchen1.attributes.brightness | int(0) }}'
    service: input_number.set_value
  - scene: scene.scene_dim_kitchen_lights
  - delay: 00:00:05
  - data_template:
      brightness: {{ states('input_number.old_brightness') | int }}
      entity_id: light.kitchen1
    service: light.turn_on

Error loading /config/configuration.yaml: invalid key: “OrderedDict([(“states(‘input_number.old_brightness’) | int”, None)])”
in “/config/scripts.yaml”

You are missing double quotes around the template.

OK - so I gave it a try with scenes on-the fly and finally managed to get the brightness to revert but the color temperature (all HUE lights) is not restored. Any clues?

  trigger:
  - entity_id: binary_sensor.wyzesense_77a64cec
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - service: scene.create
    data:
      scene_id: kitchen_spot_revert
      snapshot_entities: 
        - light.kokken
  - service: scene.bright_kitchenspots
  - delay: 00:00:05
  - service: scene.turn_on
    data:
      entity_id: scene.kitchen_spot_revert

Entity: light.kokken is
min_mireds: 153
max_mireds: 500
brightness: 1
color_temp: 351
is_hue_group: true
friendly_name: Køkken
supported_features: 43

Anyone an idea?

Hi Jon,
Still active with NodeRed?
Can you proivide me with some screenprints of NodeRed doing this?
I would like to restore values of a Hue-light and are looking or a while now without success. (I blame it on myself)

Thanks Guy