Night-friendly light with non-linear brightness mapping

What problem am I trying to solve?

I have dimmer-controlled lights in the sleeping room.
In the evening i mostly use the low brightness range (5-10%) and rarely use them full power.
It’s actually tricky to precisely steer the dial/slider to the desired brightness.

I have created a ‘synthetic’ light to control a dimmer in a non-linear way, giving more control to the lower brightness range. Demo:
ezgif-1-cbd69ebf56

The configuration

light:
  - platform: template
    lights:
      sleep1_synth1:
        friendly_name: sleeping room synth
        turn_on: 
          service: light.turn_on
          entity_id: light.sleep1_dimmer1
        turn_off: 
          service: light.turn_off
          entity_id: light.sleep1_dimmer1
        set_level:        
          service: light.turn_on
          data_template:
            brightness: "{{ ( (0.58 + brightness/255) **5 * 0.1017 *255) | int }}"             
            entity_id: light.sleep1_dimmer1
        value_template: >-
          {{ states.light.sleep1_dimmer1.state }}
        level_template: >-
          {% if state_attr("light.sleep1_dimmer1","brightness") != None %}
              {{  ( ((  (states.light.sleep1_dimmer1.attributes.brightness+0.5) /255/0.1017)**0.2 * 255 ) - 147.9 ) | int  }} 
          {% else %}
            0
          {% endif %}

How does it work?

The data_template function maps the brightness from the synthetic light to the real light.
The level_template function does the reverse, for when the light is dimmed locally.
Plots for both functions:
image

You can tweak the functions as you please: Graphing Calculator

Hope this helps and inspire you.

1 Like