MQTT Light and ( + ESP32)

Hi everyone,

I have made a simple dimmable LED lamp and want to controle it with homekit.
Im almost there. Turning light ON by setting brightness works great.

Ony issue that i have is when i want to turn the light OFF (by setting the brightness to 0%) the slider in Lovelace UI only go back to 1%. and so never give the MQTT command “OFF”.

When listening to this mqtt topic and setting the slider to 1% i see on the seriel monitor (esp32) massage arriving with brightness set to 2? and command_topic - “ON”

If it is possible i want to be able to set the slider to 0% and so the command_topic to “OFF”

Hope someone can help me. Im on it now for hours and can’t figure it out.

This is the .yaml piece:

light:
  - platform: mqtt
    name: "Warm licht"
    state_topic: "slaapkamer/licht/state"
    command_topic: "slaapkamer/licht"
    brightness_state_topic: 'slaapkamer/warmlicht/brightness'
    brightness_command_topic: 'slaapkamer/warmlicht/brightness'
    #qos: 0
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: true
    #retain: false