Skip to content

Change Proposal: Reorganizing MQTT Topics #207

@timothybrown

Description

@timothybrown

Okay, so I'm currently working on rewriting the HA Discovery code from the ground up. Part of this requires me to basically redo the MQTT topics. Right now it's kind of a mess and none of the topics are ideal for Home Assistant (or other home automation platforms).

The first step is to change the topic names and their payload. Here is what I've come up with:

  • Power Status Topic
    Device Topic/switch => on|off
  • Power Command Topic
    Device Topic/switch/set <= on|true|1|off|false|0
  • Color Status Topic
    Device Topic/color => R,G,B
  • Color Command Topic
    Device Topic/color/set <= #HEX|R,G,B
  • Brightness Status Topic
    Device Topic/brightness => 0-255
  • Brightness Command Topic
    Device Topic/brightness/set <= 0-255
  • Effect Status Topic
    Device Topic/fx => FX Number
  • Effect Command Topic
    Device Topic/fx/set <= FX Number|FX Name
  • API Response Topic
    Device Topic/api => XML API Response
  • API Command Topic
    Device Topic/api/set <= HTTP API Format
  • Availability Topic
    Device Topic/status => online|offline

This puts the topic names in-line with other projects (Espurna, ESPHome, etc.) and makes it easier to integrate into custom code and various home automation platforms without resorting to complex templating or XML decoding (however, because we've retained the API topic, this can still be done for advanced users).

Judging by a look through the issue list, it appears most people are using MQTT for HA Discovery support, which means this change will be transparent for those users (i.e., nothing will break for them and it will just work). This will only be a breaking change for those who manually configure HA, use other home automation platforms or use MQTT as a transport for custom software. I feel this is a very small percentage of use cases and this change will ultimately make it easier to use for them.

I'm interested to hear from anyone using the MQTT support in a non-HA setting (i.e., with custom code, other automation platforms and so forth). Would these topics be sufficient for your use? Is there anything else you'd like to see?

Comments from others (contributors, users and @Aircoookie alike) are welcomed as well!

I've currently got the basics of this implemented in my development fork (not yet published) and it's working well, but I wanted to get a discussion going before I go any further with it.

Edit: Renamed the power topic to switch and added availability to the list of topics. (When the device connects to the broker it will set the status topic to online then register what’s called a “last will”, which allows the broker to take care of setting the status topic to offline for us when the device disconnects.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions