WTH: Easy way to limit the brightness and rescale brightness range of lights

Some smart bulbs do not play well with some light fixtures, leading to their premature deaths and a lot of frustration. There are two hacky ways around this:

  1. Create a template light which scales it’s brightness to a fraction of the the original light’s range and passes through it’s other attributes (a pain since this has to be done in YAML)
  2. Create automations that trigger when brightness is above a certain value and lower it to a maximum (and in turn you can never set your light’s brightness above a certain amount in the UI.

If there was a way to instead set a max/min brightness for a light entity in the UI (like some kind of helper), it would make managing these lights much easier.

I did a little bit more research and ended up implementing this using a template light , with temperature and color functionality. Still, this would be a really nice to have feature in the UI. Below kitchen_bar_light_0 is the light group created in the UI which has the brightness limiter automation on it for safety.

- platform: template
  lights:
    kitchen_bar:
      # Name
      friendly_name: Kitchen Bar

      # Icon
      icon_template: >-
        {% if is_state('light.kitchen_bar_0', 'on') %}
          mdi:ceiling-light-multiple
        {% else %}
          mdi:ceiling-light-multiple-outline
        {% endif %}

      # On/Off
      turn_on:
        service: light.turn_on
        entity_id: light.kitchen_bar_0
      turn_off:
        service: light.turn_off
        entity_id: light.kitchen_bar_0

      # Value
      value_template: "{{ states('light.kitchen_bar_0') }}"

      # Level
      level_template: >
        {% if is_state('light.kitchen_bar_0', 'on') %}
          {{ (state_attr('light.kitchen_bar_0', 'brightness')|float*2)|round|int }}
        {% else %}
          0
        {% endif %}
      set_level:
        service: light.turn_on
        entity_id: light.kitchen_bar_0
        data_template:
          brightness: "{{ (brightness|float*0.5)|round|int  }}"

      # Temperature
      temperature_template: "{{ state_attr('light.kitchen_bar_0', 'color_temp')|int }}"
      # There is a minor bug in the Meross LAN integration which causes the maximum and minimum light temperature values to be out of range of what the bulb can actually handle, and setting it to these causes the temperature to not change, hence the +-1. I should get around to logging a bug about it...
      max_mireds_template: "{{ state_attr('light.kitchen_bar_0', 'max_mireds') - 1 }}"
      min_mireds_template: "{{ state_attr('light.kitchen_bar_0', 'min_mireds') + 1 }}"
      set_temperature:
        service: light.turn_on
        entity_id: light.kitchen_bar_0
        data:
          color_temp: "{{ color_temp }}"

      # Color
      color_template: "{{ state_attr('light.kitchen_bar_0', 'hs_color') }}"
      set_color:
        service: light.turn_on
        entity_id: light.kitchen_bar_0
        data:
          hs_color:
            - " {{ hs[0] }}"
            - " {{ hs[1] }}"

The limiter automation:

alias: Limit Kitchen Bar Brightness
description: ""
trigger:
  - platform: numeric_state
    entity_id: light.kitchen_bar_0
    attribute: brightness
    above: "128"
condition: []
action:
  - service: light.turn_on
    data:
      brightness: 128
    target:
      entity_id: light.kitchen_bar_0
mode: single

2 Likes