Custom Color Temperature Ranges for Zigbee Dimmers Example Config

A few weeks ago I got myself some milight zigbee cct dimmers.
http://www.futlight.com/light/xqy/fut035z.html
Nice stuff since they have 8000hz pwm rate just like the old non-zigbee models.
I’m using zigbee2mqtt and these dimmers have a hardware range they advertise in their zigbee clusters from 153 to 500 mired, but since you can connect any kind of strips to this dimmer, e.g 2700k (370 mired) on the warm white side, the range will then be off
For example when you set 500 mired on the homeassistant side then you’ll get the 370mired on the dimmer side which is ofc an issue when using something like adaptive lighting.
Here is some example code to make a template entity for color conversion, maybe it is helpful for someone.
A more in-depth explanation of the color conversion is here:

Also i think you have to set the option to send seperate commands to the bulb in adaptive lighting.
There seems to be some limitation with the template entity.

light:
  - platform: template
    lights:
      azdimmer_dummy:
        friendly_name: "AzDimmerTemplate"
        level_template: "{{ state_attr('light.dimmerazroom', 'brightness') | int }}"
        value_template: "{{ states('light.dimmerazroom') }}"
        temperature_template: >-
         {% set color_temperature = state_attr('light.dimmerazroom', 'color_temp') | int %}
         {{ (color_temperature - 153)*(500-153)/(370-153) + 153 }}
        max_mireds_template: 370 
        min_mireds_template: 153
        turn_on:
          - service: light.turn_on
            entity_id: light.dimmerazroom
        turn_off:
          - service: light.turn_off
            entity_id: light.dimmerazroom
        set_level:
          - service: light.turn_on
            data_template:
              entity_id: light.dimmerazroom
              brightness: "{{ brightness }}"
        set_temperature:
          - service: light.turn_on
            data_template:
              entity_id: light.dimmerazroom
              color_temp: "{{ (color_temp - 153)*(500-153)/(370-153) + 153 }}"