Aeon Multisensor luminance feedback loop for lighting control

Hello,

I have been able to get my lights to go on and off with the motion sensors and luminance sensors in my mains powered Aeon Multisensors and now I am trying to figure out how to control the brightness of my dimmers as a function of the luminance sensors once the lights are on. I would like to maintain constant brightness settings in rooms on a 60 second update interval. I can take data once the lights are on every 10 seconds but I need a way to average 6 readings because the sensors are not very stable/accurate and averaging the data should produce a more stable signal to make adjustments off of. Can anyone make some suggestions on how to complete this task?

Thank you in advance!

Try the link below.

Set a number of samples and use the average created for your value.

Thank you silvrr, that will help me take the average luminance measurement values that I need but now I need a solution for a feedback loop. I essentially need a PID feedback loop.

I started putting together a package to control the light with the luminance but I am having some trouble. Right now my package will turn the lights off instead of changing the level. Can someone please take a look and tell me what I am doing wrong?

sensor:
  - platform: statistics
    entity_id: sensor.multisensor_living_room_luminance
    name: Luminance Living Room
    sampling_size: 6

input_slider:
  luminance_living_room_setpoint:
    name: Luminance Living Room Setpoint
    icon: mdi:brightness-auto
    initial: 20
    min: 0
    max: 200
    step: 10
  living_room_level:
    name: Current Living Room Light Level
    icon: mdi:brightness-6
    initial: 255
    min: 0
    max: 255
    step: 1

automation:

  - alias: "auto_luminance_living_room_control"
    trigger:
      #- platform: state
      #  entity_id: light.living_room_level
      #  to: 'on'
      - platform: time
        minutes: '/1'
        seconds: 00
      #- platform: template
      #  value_template: '{{ states.input_slider.luminance_setpoint_living_room | int < states.sensor.luminance_living_room_mean | float | round }}'
    action:
      - condition: and
        conditions:
          - condition: template
            value_template: '{{ (states.sensor.luminance_living_room_mean |int ) > (states.input_slider.luminance_setpoint_living_room |int) }}'
      - service: input_slider.select_value
        entity_id: input_slider.living_room_level
        data_template:
          value: '{{ (states.input_slider.living_room_level | int) - 1 }}'

      - condition: and
        conditions:
          - condition: template
            value_template: '{{ (states.sensor.luminance_living_room_mean |int) < (states.input_slider.luminance_setpoint_living_room |int) }}'
      - service: input_slider.select_value
        entity_id: input_slider.living_room_level
        data_template:
          value: '{{ (states.input_slider.living_room_level | int) + 1 }}'

  - alias: "Set living room light level"
    trigger:
      - platform: time
        minutes: '/1'
        seconds: 00
      #- platform: state
      #  entity_id: light.living_room_level
      #  to: 'on'
      #- platform: template
      #  value_template:  '{{ state.input_slider.luminance_setpoint_living_room | int != state.sensor.luminance_living_room_mean | float | round }}'
    action:
      - service: light.turn_on
        entity_id:
          - group.living_room_lights
        data_template:
          brightness: '{{ states.input_slider.living_room_level | int }}'

group:
  Living Room Lights:
    name: Living Room Lights
    entities:
      - light.living_room_level

  Automatic Luminance Settings:
    name: Automatic Luminance Settings
    control: hidden
    entities:
    - light.living_room_level
    - sensor.luminance_living_room_mean
    - input_slider.luminance_living_room_setpoint
    - input_slider.living_room_level

I figured out all of my errors and got it working. It is really slow but it works!

Here is the package:

sensor:
  - platform: statistics
    entity_id: sensor.multisensor_living_room_luminance
    name: Luminance Living Room
    sampling_size: 6

input_slider:
  luminance_living_room_setpoint:
    name: Luminance Living Room Setpoint
    icon: mdi:brightness-auto
    initial: 20
    min: 0
    max: 200
    step: 10
  living_room_level:
    name: Current Living Room Light Level
    icon: mdi:brightness-6
    initial: 150
    min: 0
    max: 255
    step: 1

automation:

  - alias: "auto_luminance_living_room_control"
    trigger:
      - platform: time
        minutes: '/1'
        seconds: 00
      - platform: template
        value_template: '{{ (states.sensor.luminance_living_room_mean |int ) > (states.input_slider.luminance_living_room_setpoint.state |int) }}'
    action:
      - service: input_slider.select_value
        entity_id: input_slider.living_room_level
        data_template:
          value: '{{ (states.input_slider.living_room_level.state | int) - 5 }}'

  - alias: "auto_luminance_living_room_control"
    trigger:
      - platform: time
        minutes: '/1'
        seconds: 00
      - platform: template
        value_template: '{{ (states.sensor.luminance_living_room_mean |int ) < (states.input_slider.luminance_living_room_setpoint.state |int) }}'
    action:
      - service: input_slider.select_value
        entity_id: input_slider.living_room_level
        data_template:
          value: '{{ (states.input_slider.living_room_level.state | int) + 5 }}'

  - alias: "Set living room light level"
    trigger:
      - platform: time
        minutes: '/1'
        seconds: 00
      - platform: template
        value_template:  '{{ (states.sensor.luminance_living_room_mean |int ) != (states.input_slider.luminance_living_room_setpoint.state |int) }}'
    action:
      - service: light.turn_on
        entity_id:
          - group.living_room_lights
        data_template:
          brightness: '{{ states.input_slider.living_room_level.state | int }}'

group:
  Living Room Lights:
    name: Living Room Lights
    entities:
      - light.living_room_level

  Automatic Luminance Settings:
    name: Automatic Luminance Settings
    control: hidden
    entities:
    - automation.auto_luminance_living_room_control
    - light.living_room_level
    - sensor.luminance_living_room_mean
    - input_slider.luminance_living_room_setpoint
    - input_slider.living_room_level