Storing an attribute of an entity for later use

Hi guys,

Complete novice here so apologies for whats probably a very basic question. I have tried researching this but have been unsuccessful.

I have several lights but I would like the light in the hall (if its on, which is half hour before sunset until 11pm, but it dims lower at 8pm) to turn its brightness up if our ring doorbell rings, then revert back to its previous brightness level after a set time (something like 2 mins).

I can make the automation (if ring doorbell activates and time is between xx then call script etc but the problem I have is storing the brightness level and then setting brighness back to that level.

Entity: Wiz Hall

min_color_temp_kelvin: 2202
max_color_temp_kelvin: 6535
min_mireds: 153
max_mireds: 454
effect_list:

  • Ocean
  • Romance
  • Sunset
  • Party
  • Fireplace
  • Cozy
  • Forest
  • Pastel Colors
  • Wake up
  • Bedtime
  • Warm White
  • Daylight
  • Cool white
  • Night light
  • Focus
  • Relax
  • True colors
  • TV time
  • Plantgrowth
  • Spring
  • Summer
  • Fall
  • Deepdive
  • Jungle
  • Mojito
  • Club
  • Christmas
  • Halloween
  • Candlelight
  • Golden white
  • Pulse
  • Steampunk
  • Rhythm
    supported_color_modes:
  • color_temp
  • rgbw
    friendly_name: Wiz Hall
    supported_features: 4
    color_mode: color_temp
    brightness: 69
    color_temp_kelvin: 2645
    color_temp: 378
    hs_color:
  • 28.518
  • 67.51
    rgb_color:
  • 255
  • 164
  • 82
    xy_color:
  • 0.532
  • 0.388

Thanks guys

Hi Carl, you can do all that in 1 automation.

Have a look at this solution with the template in the action: [solved] Automation with motion sensor & light: sometimes in the dark. Why? - #2 by 123
In the brightness_pct step, you will have to add your state when the bell rings.

I have come up with this, its a bit messy but it works. I have made 3 scripts (1 to get current brightness, 1 to set the brightness high and another to set brightness back to what it was.

service: input_number.set_value
data:
value: |
{{ state_attr(‘light.wiz_hall’,‘brightness’)|int }}
target:
entity_id: input_number.hall_level

service: light.turn_on
data_template:
brightness: 150
entity_id: light.wiz_hall

Delay of 2 mins

service: light.turn_on
data_template:
brightness: “{{ states(‘input_number.hall_level’)|float(0) }}”
entity_id: light.wiz_hall

How would this be coded to all be in 1 script that can be called from an automation?

Reference: Creating scenes on the fly

script:
  your_script_name:
    sequence:
      - service: scene.create
        data:
          scene_id: before
          snapshot_entities:
            - light.wiz_hall
      - service: light.turn_on
        target:
          entity_id: light.wiz_hall
        data:
          brightness: 150
      - delay:
          minutes: 2
      - service: scene.turn_on
        target:
          entity_id: scene.before
1 Like

Excellent Thank you!

1 Like