Lux controlled brightness not working

Hi all!

Up to now I’ve been able to set up all my automations by searching this forum and scouring through the docs. I’m trying to automate my lights so the brightness is adjusted to the natural incoming light. The script below doesn’t give any errors, but the only thing it does is turn the light on. It’s not responding to any input from the lux sensor. Does anyone have a clue about what’s going wrong?

    - service: light.turn_on
        entity_id: light.hue_lightstrip_plus_1
        transition: 10
        brightness_pct: >
          {% set lux = states('sensor.downstairs_light_filtered') | float %}
          {% if lux <= 40 %}
          {% else %}
            {{ 56 * (160 - lux) / 160 + 0.09 }}
          {% endif %}

I used Dynamic brightness based on lux reading from a sensor and Help! Light brightness by lux level automation as inspiration.