Light template: «color_temp» or «colortemp» to set color temperature?

Hi!

I´m trying to control color temperature of DALI lights in a scene. It is working fine when manually operating the light cards - but when attempting to create a scene state the lamps will not retain brightness settings.

To make the scene work I have to manually open the scenes.yaml file and edit «supported_color_modes» from this:

- id: "1704142140911"
  name: Alt lys på - 2700K
  entities:
    light.dali_stue_1_1_62_10_cct_2x8w_spot:
      min_color_temp_kelvin: 2702
      max_color_temp_kelvin: 6535
      min_mireds: 153
      max_mireds: 370
      supported_color_modes:
        - color_temp
      color_mode: color_temp
      brightness: 255
      color_temp_kelvin: 2702
      color_temp: 370
      hs_color:
        - 28.391
        - 65.659
      rgb_color:
        - 255
        - 166
        - 87
      xy_color:
        - 0.526
        - 0.387
      friendly_name: DALI Stue 1 1.62.10 CCT 2x8w Spot
      supported_features: 40
      state: "on"

To This:

- id: "1704142140911"
  name: Alt lys på - 2700K
  entities:
    light.dali_stue_1_1_62_10_cct_2x8w_spot:
      min_color_temp_kelvin: 2702
      max_color_temp_kelvin: 6535
      min_mireds: 153
      max_mireds: 370
      supported_color_modes:
        - colortemp
      color_mode: colortemp
      brightness: 255
      color_temp_kelvin: 2702
      color_temp: 370
      hs_color:
        - 28.391
        - 65.659
      rgb_color:
        - 255
        - 166
        - 87
      xy_color:
        - 0.526
        - 0.387
      friendly_name: DALI Stue 1 1.62.10 CCT 2x8w Spot
      supported_features: 40
      state: "on"

The only difference is removing the «_» between color_temp. Is there anything I can do to make HomeAssistant save the scene config using «colortemp» instead of «color_temp»? Or should I change the way the lamps are configured to make it work using «color_temp».

This is the light entity config:

# DALI light Stue 1 PNY CCT
- schema: template
  name: "DALI Stue 1 1.62.10 CCT 2x8w Spot"
  state_topic: "hdl/sc/1.62/10"
  command_topic: "hdl/sc/1.62/10/set"
  command_on_template: >
    {"state": "on"
    {%- if brightness is defined -%}
    , "level": {{ brightness }}
    {%- else -%}
    , "level": 255
    {%- endif -%}
    {%- if color_temp is defined -%}
    , "colortemp": {{ [[(1000000 / color_temp | float) | round(0), 2705] | max, 6535] | min }}
    {%- endif -%}
    }
  command_off_template: '{"state": "off", "level": 0}'
  state_template: "{% if value_json.level | int > 0 %}on{% else %}off{% endif %}"
  brightness_template: "{{ value_json.level }}"
  color_temp_template: "{{ (1000000 / value_json.colortemp | float) | round(0) }}"
  max_mireds: 370
  min_mireds: 153
  qos: 1

I also have some system log errors related to «invalid colortemp». As mentioned everything works fine except for creating scenes.

Log entríes:

Logger: homeassistant.components.mqtt.light.schema_template
Source: components/mqtt/light/schema_template.py:243 
Integration: MQTT (documentation, issues) 
First occurred: January 13, 2024 at 08:00:50 (66949 occurrences) 
Last logged: 00:29:20

Invalid color temperature value received

2024-01-13 02:25:40.600 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'colortemp' (value: {"level":0}, template: {{ (1000000 / value_json.colortemp | float) | round(0) }})
2024-01-13 02:25:40.600 WARNING (MainThread) [homeassistant.components.mqtt.light.schema_template] Invalid color temperature value received

All help is highly appreciated :slight_smile: Thanks!

Hi, what type of bridge/gateway do you use?

Hi @Maurits28,

I using an HDL BusPro gateway as a link between the lights and Home Assistant.

I’ve tried to pass the colortemp from MQTT using both variable “color_temp” and “colortemp”. When adapting the entities both variants work just fine when using the lighcard manually. The colortemp of the icon is aso updated, but for some reason it does not work when trying to save the state in a scene.

For the scene to work manual changing from “color_temp” to “colortemp” in scenes.yaml is required. If I later udate the scene from the UI the adjustmen in scenes.yaml is overwritten and I have to do it again - which is not ideal if making lots of adjustments to scenes.

The docs say

temperature_template:

not

color_temp_template:

EDIT:

And if it is mqtt light -

then the docs say:

color_temp_value_template:

I think you might need to look at your config for this example, because for instance:

schema string (optional, default: default)
The schema to use. Must be default or omitted to select the default schema.

and you have

 - schema: template

ok so looking further down the documentation I see the template section, now - it says the value of color_temp_template must be an integer representing mireds, are you certain that the JSON value is the kelvin temperature?

I think maybe you need to post an MQTT message from something like MQTT Explorer - showing the raw values that are received directly from the MQTT broker.

Thanks for your suggestions and sorry for very late reply. I have tried various adjustments, and I have found a pattern:

When I turn a light on the color temperature is not sent (no adjustment made - just a simple turn on command). The lamp turns on with the same color temperature as it was turned off with. An error is triggered in the system log:

Logger: homeassistant.components.mqtt.light.schema_template
Source: components/mqtt/light/schema_template.py:220
integration: MQTT (documentation, issues)
First occurred: 10:50:00 (818 occurrences)
Last logged: 12:14:07

Invalid color temperature value received

The MQTT raw data confirms that no color temp is sent:

The card is updated just fine:

Then I adjust the color temperature without changing the brighness. The card is updated, the light will correctly change temperature:

An error is now logged in Home Assistant. This time relating to brightness:

Logger: homeassistant.components.mqtt.light.schema_template
Source: components/mqtt/light/schema_template.py:209
integration: MQTT (documentation, issues)
First occurred: 10:52:11 (259 occurrences)
Last logged: 12:25:22

Invalid brightness value received from hdl/sc/1.62/10

The MQTT raw data indicates that level 255 is sent even if the brightness was not changed, but this time the colortemp is included in Kelvin. The lamp accepts kelvin temperatures and level 0-255 for brightness:

It seems the error might be related to not including brightness when changing colortemp and the other way around when changing colortemp?