Auto dim lights above sensor threshold

Some background behind this
The family of the household like to go around flipping off lights by the physical switches. This causes issues with automations and lighting. There’s also the problem with some lights where if you turn them off and back on, they are set to turn on to 100% brightness. I set up multiple sensors for my lights to determine if the lights are too bright and built the automations one by one for each light and area. I know there are better ways to go about building this but it works for now.

Inside of sensors.yaml, you will need to add the sensor for the entity. I’m sure there’s a way to set this programatically and would love to see improvements or suggestions on how to achieve that.

      brightlight_testbulb:
        friendly_name: Light TestBulb is Over Limit
        value_template: >-
          {% if state_attr('light.test', 'brightness') | float > 155 %}
            true
          {% else %}
            false
          {% endif %}

The blueprint allows to set the transition time and target brightness. I’m going to add a few more options later. Since this is my first blueprint, I thought it would be best to keep things simple.

blueprint:
  name: Light is too bright
  description: The target entity or group of lights is over the predetermined brightness as set in sensors.yaml
  domain: automation
  input:
    sensor:
      name: Brightlight Sensor
      description: Custom sensor in sensors.yaml
      selector:
        entity:
          domain: sensor
    target_light:
      name: Lights
      description: The lights to reduce brightness
      selector:
        target:
          entity:
            domain: light
    transition_time:
      name: Transition time in seconds
      default: 30
      selector:
        number:
          min: 0
          max: 300
          unit_of_measurement: seconds
    brightness_percent:
      name: Brightness Percentage
      default: 10
      selector:
        number:
          min: 1
          max: 100
          unit_of_measurement: "%"
          mode: slider

trigger:
  - platform: state
    entity_id: !input sensor

action:
  - service: light.turn_on
    target: !input target_light
    data:
      transition: !input transition_time
      brightness_pct: !input brightness_percent