Turning the lights on according to the light level outside

Create a template sensor that maps your light level to wanted brightness. Then use this sensor to specify the brightness whenever you call the light turn on service.

Using the two points you supplied, and 100% brightness at 0 lux, gives this equation:

bri_pct = -0.3 * lux +98.33

Which you can use in a template sensor like this:

- name: 'Calculated Light Brightness'
  unit_of_measurement: "%"
  icon: "mdi:brightness-auto"
  state: >
    {{ ( [0, (-0.3 * states('sensor.your_lux_here')|float(0) + 98.33 )|round(0)|int(0), 100]|sort )[1] }}

This maps 328 lx → 0 % through to 0 lx → 98% brightness. Note that the points you supplied do not quite cover the full 0 to 100% range, but you would not notice 2% difference between 98% and 100%, so close enough.

Output values are limited to 0% to 100% brightness by the [0, x, 100]|sort[1] function. It sorts the list in order of increasing value and picks the middle one. So if you had a brightness value of -7:

[0, -7, 100] it would sort to [-7, 0, 100] and pick the middle value, 0. Thus clamping -7 to 0.

How to use the sensor in an action:

action:
  - service: light.turn_on
    target:
      entity_id: light.your_light
    data:
      brightness_pct: "{{ states('sensor.calculated_light_brightness') }}"

You can use a spreadsheet to experiment with different points and see what the equation produces:

6 Likes