Manually calculating power consumption of lights

I just finished my code. It’s based off measurements of power by adjusting mired and brightness. I then fit a curve for each of the mired value sets, with brightness as the variable using a second order polynomial on this site Polynomial Regression Data Fit. The measured data at the bottom of this post is from a Philips Hue LTW001 bulb.

More than happy for feedback on the code.

- platform: template
  sensors:
    living_room_big_lamp_power:
      friendly_name: Living Room Big Lamp Power
      icon_template: mdi:lightning-bolt
      unit_of_measurement: "W"
      value_template: >
        {% if is_state('light.living_room_big_lamp','on') %}
          {% set mired = state_attr("light.living_room_big_lamp","color_temp") %}
          {% set brightness = ((state_attr("light.living_room_big_lamp","brightness") - 3) * (100 - 1)) / (254 - 3) + 1 %}
          {% set m153 = (0.000435254 * (brightness**2) + (0.002105929 * brightness) + 1.500175321) %}
          {% set m203 = (0.00057964 * (brightness**2) + 0.001134825 * brightness + 1.527090668) %}
          {% set m253 = (0.000785198 * (brightness**2) - 0.002785236 * brightness + 1.57216088) %}
          {% set m303 = (0.000733083 * (brightness**2) - 0.002574077 * brightness + 1.573079888) %}
          {% set m353 = (0.000668279 * (brightness**2) - 0.001853391 * brightness + 1.561981489) %}
          {% set m403 = (0.000570268 * (brightness**2) + 0.0000671178176666897 * brightness + 1.527920206) %}
          {% set m454 = (0.000487813 * (brightness**2) - 0.000161527 * brightness + 1.518884275) %}
          {% if mired >= 153 and mired < 203 %}
            {{ ((((mired - 153) * (m203 - m153)) / (203 - 153)) + m153)|round(2) }}
          {% elif mired >= 203 and mired < 253 %}
            {{ ((((mired - 203) * (m253 - m203)) / (253 - 203)) + m203)|round(2) }}
          {% elif mired >= 253 and mired < 303 %}
            {{ ((((mired - 253) * (m303 - m253)) / (303 - 253)) + m253)|round(2) }}
          {% elif mired >= 303 and mired < 353 %}
            {{ ((((mired - 303) * (m353 - m303)) / (353 - 303)) + m303)|round(2) }}
          {% elif mired >= 353 and mired < 403 %}
            {{ ((((mired - 353) * (m403 - m353)) / (403 - 353)) + m353)|round(2) }}
          {% elif mired >= 403 and mired < 454 %}
            {{ ((((mired - 403) * (m454 - 403)) / (454 - 403)) + m403)|round(2) }}
          {% elif mired == 454 %}
            {{ m454|round(2) }}
          {% endif %}
        {% else %}
          {{ 0.00 }}
        {% endif %}
Active Power (W)							
Kelvin	6535.947712	4926.108374	3952.56917	3300.330033	2832.86119	2481.389578	2202.643172
MIRED	153	203	253	303	353	403	454
BRIGHTNESS
1	1.52	1.53	1.55	1.54	1.54	1.53	1.52
10	1.56	1.59	1.59	1.61	1.6	1.58	1.57
20	1.7	1.78	1.85	1.83	1.8	1.75	1.72
30	1.94	2.08	2.23	2.18	2.13	2.04	1.96
40	2.28	2.51	2.76	2.69	2.59	2.46	2.23
50	2.71	3.05	3.44	3.32	3.18	2.98	2.76
60	3.2	3.69	4.23	4.05	3.84	3.59	3.28
70	3.78	4.42	5.16	4.92	4.66	4.3	3.89
80	4.45	5.32	6.29	5.99	5.64	5.16	4.63
90	5.23	6.32	7.67	7.26	6.8	6.16	5.48
100	6.05	7.45	9.22	8.72	8.11	7.25	6.36
1 Like