MQTT status reponse from a python script

I’ve set an mqtt light strip with is controlled by a Python script on a Pi Zero (using paho-mqtt and rpi-ws281x).
Everything is working fine (on/off, brightness, transitions, etc.) but the Lovelace card doesn’t seem to register the status change. When i change something (colour, brightness, status), it quickly changes back to the default status.

I found a few resources online saying that i need to send a response after having applied the changes, yet I can’t find anything on how and what to respond.
For the moment, I’ve changed to yaml config to optimistic and everything is working just fine, but this shouldn’t be the permanent solution

My config (based on https://www.home-assistant.io/integrations/light.mqtt/):

light:
  - platform: mqtt
    schema: json
    name: "Test RGBW Strip"
    state_topic: "ido/test_rgbw_strip"
    command_topic: "ido/test_rgbw_strip/set"
    brightness: true
    rgb: true
    white_value: true
    optimistic: true
    qos: 1

The python side is based on the examples from


where I’ve implemented on_message() to handle the light strip

Many thanks for the help

When you receive a command on

ido/test_rgbw_strip/set

You need to send a confirmation on

ido/test_rgbw_strip

You mean a PUBACK message? I’ve tried that, it’s also automatically sent by the python lib

A puback message is used with qos1 and qos2 to inform that the message is received. That is not what I’m talking about. You need to send back a message with the new state.

Brilliant, many thanks :slight_smile:
For future people with a similar question, i’ve written this small function to notify the broker of the current state

def _confirm_state(self):
    """
    Inform the broker of the current state
    """
    self.publish(
        'ido/test_rgbw_strip',
        payload=json.dumps({
            'state': self._last_state,  # ON/OFF
            'brightness': self._last_brightness,    # int
            'color': {'r': self._last_rgbw[0], 'g': self._last_rgbw[1], 'b': self._last_rgbw[2]},
            'white_value': self._last_rgbw[3]   # int
        }),
        qos=1,
        retain=False
    )