MQTT light: Send single state message with all data


reading MQTT.Light docs page, it is not very clear, but is there a way to have a single state topic, where end node notifies HA using JSON message about all information with single command?

Right now I have separate topics for each of the commands, like RGB state, brightness state, on/off state, rgbw state, temperature state, …

Something like:

Topic name: light/id/state, with data:

   "state": "on/off",
   "brightness": 123,
   "r": 123,
   "g": 11,
   "b": 12,
   "...": "..."

format of messages found in mqtt depends on how devices store those data in mqtt.

You can put as much information as u want in a single message. But what are you trying todo?
If you take the examples:

# Example configuration.yaml entry
  - light:
      name: "Office Light RGB"
      state_topic: "office/rgb1/light/status"
      command_topic: "office/rgb1/light/switch"
      brightness_state_topic: "office/rgb1/brightness/status"
      brightness_command_topic: "office/rgb1/brightness/set"
      rgb_state_topic: "office/rgb1/rgb/status"
      rgb_command_topic: "office/rgb1/rgb/set"
      state_value_template: "{{ value_json.state }}"
      brightness_value_template: "{{ value_json.brightness }}"
      rgb_value_template: "{{ value_json.rgb | join(',') }}"
      qos: 0
      payload_on: "ON"
      payload_off: "OFF"
      optimistic: false

Then you see you can have alot of info in 1 topic. In this case: office/rgb1
So the 1 light entity would have everything including RBG in this 1 message.

1 Like

I think I found the solution. In the discovery MQTT packet, I had to put schema: json type, and then I receive all commands on single topic and I can update the state with single MQTT message.

This one helped: MQTT RGB light with brightness / color temperature - how to get HA to actually send brightness/color_temp? - #5 by FloatingBoater