No announcement yet.

Mutiple Devices with the same MQTT Topic

  • Filter
  • Time
  • Show
Clear All
new posts

  • Mutiple Devices with the same MQTT Topic

    I asked this in the pinned topic but thought it might be more visible here.

    I just configured a RGB controller running Mclighting. I have it interfaced with HS using your plugin. My question is how do I create multiple devices with the same Subscribe and Publish topic?
    Mclighting publishes to KitchenCabinets/out
    McLighting Subscribes to KitchenCabinets/in

    Commands are formatted as such:
    KitchenCabinets/in =off (control of on/off)
    KitchenCabinets/in %50 (Dimmer)
    KitchenCabinets/in #HEXCODE (Color)
    KitchenCabinets/in /45 (animation mode)

    How can I create either different devices for each control or a parent device with children devices? Button style for Control and Animation, color picker for Hexcode and Number range for dimmer.
    Here is the MQTT documentation for McLighting if that helps:

  • #2
    I looked at the API link and it was pretty sparse and did not see the =/%/# etc syntax. What I did see under HomeAssistant integration was the more standard implementation of JSON for both in and out topics. If you are configured this way (#define ENABLE_HOMEASSISTANT) then you will get exactly the behavior that you desire. The /out topic will be shown in mcsMQTT/HS as KitchenCabinets/out:brightness, KitchenCabinets/out:color, etc. If you setup on General tab to have parent/child relationships then they will be grouped. Otherwise you can manually group them from the Edit tab using Grouping Parent Ref capability.

    What I do not see is is Dimmer in the JSON, but I suspect it is called "speed"

    Since you will have an unique HS device for each of the JSON items you will be able to define the expected /in Topic for each and set the Payload Template as necessary to achieve the desired payload.


    • #3
      On the MQTT page they reference that the MQTT API is formatted the same as the WEBSocket API.

      I have one way control setup with Virtual Devices and events generating MQTT Topics, but would love two way communication with your plugin.


      • #4
        The WebSocket API is essentially a one-way communication with only OK returned in status response. The only way I saw to get get some status was with polling using $ payload and it shows 4 parameters.
        { "mode":0, "delay_ms":50, "brightness":255, "color":[255, 20, 147] } You could setup an event to poll and get 2-way for these four. When mcsMQTT receives this topic it will setup four rows to associate the topic with the payload. Each row can then be accepted as a HS device. The publish topic and publish template on the Edit tab can then be set to provide the 2-way. Using WebSocket is closer aligned to restful protocol where the client (mcsMQTT) always initiates the transaction to pull data. MQTT normal architecture has the light publishing changes in status and often periodically refreshing status. I got the impression that when you configured it to ENABLE_HOMEASSISTANT then it would be behaving in a paradigm where a status response would follow every command. In this mode then you could set it up as 2-way as I described previously. When mcLighting does not publish its status then 2-way communication cannot be achieved. This is because mcsMQTT does not have any received topic to which it can listen to know the status of mcLighting.