How to use value from a photocell to adjust brightness on a HA light entity?

Hi all, new to HA and ESPHome and getting started with automation but finding it a challenge for sure.

End goal here is to use a photocell to continually adjust the brightness setting of a light entity - in this case the backlight of an LCD display.

LDR is connected to a D1 mini and returns between 0 and 1 V or 0 and 100 is using a calibrate_linear filter. Not sure if the unit_of_measurement is an issue here as it defaults to V.

#esp-ldr.yaml
  - platform: adc
    pin: A0
    name: "Test Brightness"
    filters:
      - calibrate_linear:
          - 0.0 -> 0.0
          - 1.0 -> 100.0    
    update_interval: 2s

The LCD backlight is set via pmw pin on a separate D1 mini connected to the backlight pin on the pcf8574

#esp-lcd.yaml
output:
  - platform: esp8266_pwm
    pin: GPIO12
    id: backlight

light:
  - platform: monochromatic
    output: backlight
    name: "LCD Display Backlight"
    id: light_backlight
    restore_mode: ALWAYS_ON

I can control the backlight state and brightness via the GUI no probs. I cobbled the below together from other posts and here and have entered as a script.

#automation script
light_adjust_ldr:
alias: LCD Brightness
sequence:
  - service: light.turn_on
    data: 
      device_id: f533e67745a4556d7e5f32ed602abd53
      entity_id: light.lcd_display_backlight
      domain: light
    data_template:
      brightness_pct: "{{ states('sensor.test_brightness' }}"
mode: single

but it doesn’t work and throws an error in the trace: extra keys not allowed @ data[‘domain’]

brightness_pct: "{{ states('sensor.test_brightness' }}"

was oringally

brightness_pct: "{{ states('sensor.test_brightness' |float}}"

but this does return a value when tested in templates but does without the | float. I’m also unsure what the trigger would be for this automation how to run it on a regular schedule.

Grateful for any tips.

Have managed to find a working solution of sorts. I used the GUI to create an automation to set the entity brightness percentage to 100 every 60s and added a condition that the backlight state must be ‘on’.

I then edited the yaml and replaced the brightness percent with the state from the LDR.

alias: LCD Backlight
description: ""
trigger:
  - platform: time_pattern
    seconds: /60
condition:
  - condition: state
    entity_id: light.lcd_display_backlight
    state: "on"
action:
  - service: light.turn_on
    data:
      brightness_pct: "{{ states('sensor.test_brightness')}}"
    target:
      device_id: f533e67745a4556d7e5f32ed602abd53
      entity_id: light.lcd_display_backlight
mode: single