Updating Brightness when turned off

When a light turns on, it turns on to whatever it was last time it was on. For my use case, I want to have it turn on to a set brightness, which is changed by different events. These events could be anything - time, who is home, tv state, kids in bed, etc).

The way I am currently doing this seems wrong. I’ve defined a new helper and use this in any automation that turns on the lights. That’s great but, not only does it feel mad, I can’t use the lovelace light controls.

There’s got to be a better way. Is it the Template Light?

Thanks for your help.

A template light could do this.

Anytime a light or group of lights is turned on or off, the template light can activate a script which can do pretty much whatever you want.

Also, there are various fields to control the attributes of the light(s), from colours to brightness etc. These can be set based on templates (for instance, when the TV is on, set the brightness of a light to 50%)

However… having many of these conditions could make the template light messy.
For example, take this part of the configuration:

        level_template: "{{ state_attr('sensor.theater_brightness', 'lux')|int }}"
        value_template: "{{ state_attr('sensor.theater_brightness', 'lux')|int > 0 }}"
        temperature_template: "{{states('input_number.temperature_input') | int}}"
        color_template: "({{states('input_number.h_input') | int}}, {{states('input_number.s_input') | int}})"
        effect_list_template: "{{ state_attr('light.led_strip', 'effect_list') }}"

Imagine adding large chunks of jinja in there…

Perfect. Thank you.

I’ve started playing with it now, seems to work reasonably well.

      template_livingroom:
        friendly_name: "Living Room"
        unique_id: light.template_livingroom__1111
        value_template: "{{ states('light.livingroom_lights') }}"
        level_template: "{{ states('input_number.light_living_room_brightness') }}"
        supports_transition_template: "{{ true }}"

        turn_on: 
          service: light.turn_on
          target:
            entity_id: light.livingroom_lights
          data:
            brightness: "{{ states('input_number.light_living_room_brightness') }}"
        turn_off: 
          service: light.turn_off
          target:
            entity_id: light.livingroom_lights
        set_level:
          - service: input_number.set_value
            data:
              value: "{{ brightness }}"
              entity_id: input_number.light_living_room_brightness
          - service: light.turn_on
            target:
              entity_id: light.livingroom_lights
            data:
              brightness: "{{ states('input_number.light_living_room_brightness') }}"

This way I can keep the light itself pretty clean, then have automations to update the input_number that controls the brightness.

Thanks for the help.