Unable to configure color temperature via mqtt auto discovery

Hi there,

I’m pretty new to home assistant and have built a few MQTT lamps myself based on an esp32/8266 but controlled them differently. I hope that I meet you forum conventions, and big thanks in advance!

Now I want to switch to HASS and use the MQTT auto discovery feature of HASS to be able to integrate the devices.

Basically it works, but I just don’t manage to configure the ‘color temperature range’ and return the value in Kelvin of the device.

My UI also behaves a bit unexpectedly. When i move (and hold) the slider, the value is displayed in Kelvin, but on release it changes to percent.

This should be easily reproducible using “MQTT Explorer” and send the payload (raw).

The payload I send to <mymqtt::>homeassistant/light/deskLamp001/light/config

{
  "schema": "json",
  "brightness": true,
  "color_temp": true,
  "color_temp_kelvin": true,
  "min_color_temp_kelvin": 3000,
  "max_color_temp_kelvin": 6000,
  "rgb": false,
  "effect": false,
  "name": "deskLamp001 Desk Lamp",
  "unique_id": "deskLamp001",
  "command_topic": "homeassistant/jps-room/light/receive/deskLamp001",
  "state_topic": "homeassistant/jps-room/light/publish/deskLamp001",
  "device": {
    "identifiers": "deskLamp001",
    "manufacturer": "Own Manufacturer",
    "model": "Desk Lamp Model",
    "name": "deskLamp001",
    "sw_version": "Firmware Version",
    "connections": [
      [
        "mac",
        "08:B6:1F:2B:1F:F0"
      ]
    ]
  },
  "color_temp_values": {
    "min": 3000,
    "max": 6000
  }
}

This works fine and registers the device, but no matter what I try, I have not been able to modify the min_color_temp_kelvin=2000, max_color_temp_kelvin=6535 and return the kelvin value instead of the mireds. (All values with “color_temp” don’t seem to have any effect except "color_temp": true).

It is always the default mireds 153 - 500
This is the message I recive over mqtt:

{
  "state": "ON",
  "color_temp": 275
}

This is the log I get on discovery is:

2023-09-16 13:40:29.501 DEBUG (MainThread) [homeassistant.components.mqtt.mixins] Got update for entity with hash: ('light', 'deskLamp001 light') '{'schema': 'json', 'brightness': True, 'color_temp': True, 'color_temp_kelvin': True, 'min_color_temp_kelvin': 3000, 'max_color_temp_kelvin': 6000, 'rgb': False, 'effect': False, 'name': 'deskLamp001 Desk Lamp', 'unique_id': 'deskLamp001', 'command_topic': 'homeassistant/jps-room/light/receive/deskLamp001', 'state_topic': 'homeassistant/jps-room/light/publish/deskLamp001', 'device': {'identifiers': 'deskLamp001', 'manufacturer': 'Your Manufacturer', 'model': 'Desk Lamp Model', 'name': 'deskLamp001', 'sw_version': 'Your Firmware Version', 'connections': [['mac', '08:B6:1F:2B:1F:F0']]}, 'color_temp_values': {'min': 3000, 'max': 6000}, 'platform': 'mqtt'}'
2023-09-16 13:40:29.501 INFO (MainThread) [homeassistant.components.mqtt.mixins] Updating component: light.desklamp001_desk_lamp
2023-09-16 13:40:29.502 WARNING (MainThread) [homeassistant.components.mqtt.mixins] MQTT entity name starts with the device name in your config {'schema': 'json', 'brightness': True, 'color_temp': True, 'rgb': False, 'effect': False, 'name': 'deskLamp001 Desk Lamp', 'unique_id': 'deskLamp001', 'command_topic': 'homeassistant/jps-room/light/receive/deskLamp001', 'state_topic': 'homeassistant/jps-room/light/publish/deskLamp001', 'device': {'identifiers': ['deskLamp001'], 'manufacturer': 'Your Manufacturer', 'model': 'Desk Lamp Model', 'name': 'deskLamp001', 'sw_version': 'Your Firmware Version', 'connections': [['mac', '08:B6:1F:2B:1F:F0']]}, 'enabled_by_default': True, 'optimistic': False, 'payload_available': 'online', 'qos': 0, 'flash_time_long': 10, 'color_mode': False, 'hs': False, 'white_scale': 255, 'retain': False, 'availability_mode': 'latest', 'payload_not_available': 'offline', 'xy': False, 'encoding': 'utf-8', 'brightness_scale': 255, 'flash_time_short': 2}, this is not expected. Please correct your configuration. The device name prefix will be stripped off the entity name and becomes 'Desk Lamp'
2023-09-16 13:40:29.504 DEBUG (MainThread) [homeassistant.components.mqtt.discovery] Pending discovery for ('light', 'deskLamp001 light'): deque([])

When sending a message:

2023-09-16 13:44:46.557 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=light, service=turn_on, service_data=entity_id=light.desklamp001_desk_lamp, color_temp_kelvin=3633>
2023-09-16 13:44:46.560 DEBUG (SyncWorker_1) [paho.mqtt.client] Sending PUBLISH (d0, q0, r0, m74), 'b'homeassistant/jps-room/light/receive/deskLamp001'', ... (31 bytes)
2023-09-16 13:44:46.561 DEBUG (MainThread) [homeassistant.components.mqtt.client] Transmitting message on homeassistant/jps-room/light/receive/deskLamp001: '{"state":"ON","color_temp":275}', mid: 74, qos: 0
2023-09-16 13:44:46.563 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [3827168936] JP from 192.168.178.99 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36): Sending {"id":87,"type":"result","success":true,"result":{"context":{"id":"01HAEWXFEXM8045GWSNH1218H6","parent_id":null,"user_id":"ba1800641e7341a795fd2817d4b4745c"}}}
2023-09-16 13:44:46.843 DEBUG (Thread-2 (_thread_main)) [paho.mqtt.client] Received PUBLISH (d0, q0, r0, m0), 'homeassistant/jps-room/light/publish/deskLamp001', ...  (31 bytes)
2023-09-16 13:44:46.844 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on homeassistant/jps-room/light/publish/deskLamp001 (qos=0): b'{"state":"ON","color_temp":275}'
2023-09-16 13:44:46.845 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=light.desklamp001_desk_lamp, old_state=<state light.desklamp001_desk_lamp=on; min_color_temp_kelvin=2000, max_color_temp_kelvin=6535, min_mireds=153, max_mireds=500, supported_color_modes=[<ColorMode.COLOR_TEMP: 'color_temp'>], color_mode=color_temp, brightness=245, color_temp_kelvin=3067, color_temp=326, hs_color=(27.718, 55.105), rgb_color=(255, 179, 114), xy_color=(0.49, 0.382), friendly_name=deskLamp001 Desk Lamp, supported_features=40 @ 2023-09-16T12:53:14.054319+02:00>, new_state=<state light.desklamp001_desk_lamp=on; min_color_temp_kelvin=2000, max_color_temp_kelvin=6535, min_mireds=153, max_mireds=500, supported_color_modes=[<ColorMode.COLOR_TEMP: 'color_temp'>], color_mode=color_temp, brightness=245, color_temp_kelvin=3636, color_temp=275, hs_color=(27.048, 41.896), rgb_color=(255, 196, 148), xy_color=(0.444, 0.371), friendly_name=deskLamp001 Desk Lamp, supported_features=40 @ 2023-09-16T12:53:14.054319+02:00>>

Hi there.
Sorry to bother, but did you finally get it working?
I can get my device discovered and removed ok. It has a “light” entity and some “sensor” -s.
The mqtt-broker gets my topics and payloads correctly. I can switch the light on and off, but whenever I touch the switch in the dashboard, it sets the brightness attribute to null…
I can get my ESP code to respond to my interaction with the dashboard (because I receive the value from the dial in the payload ), but the attribute in HA remains at null, so the dashboard does not show the brightness.

The example code on the HA website regarding mqtt discovery, is 6 years old.
Any ideas?