Can I make an MQTT device with multiple topics and payloads?

Hi all, I’m new to Home Assistant. Hopefully I’m not being ignorant of something, but I’ve been all over all the docs I can find, and I’m unable to answer a question -

I’m working on integrating Home Assistant and a custom lighting controller I’ve built. The controller should ideally subscribe to a few MQTT topics to get configuration from HA. I’ve seen the light device here, and it is very close to what I’d like to achieve, but it’s not a perfect match. The controller I’m working on has a lot of custom effects with parameters I want to control via sliders.

My question is this: is it possible to make a composite device from various MQTT entities I’ve defined in configuration.yaml? I have successfully been able to control the device as a switch, but I would like to expose more configuration all under one logical device. My hope is that clicking this device in HA can show a bunch of fields like when I click an RGB light in HA.

For clarity, I’m hoping to do this entirely via configuration.yaml or other configuration files. I’m sure this can be achieved by creating an HA add-on, but I’m guessing that’s a lot of work, and I’m not very keen on getting a development environment set up to make on device that is hardly more than an RGB light.

Did you code the firmware of your light controller yourself? Then it would be very easy: just publish the correct auto discovery messages as retained mqtt messages on device power up. Like this ha will create a device grouping a switches and sensors you define in your discovery message. Here is all you need to know about that: https://www.home-assistant.io/docs/mqtt/discovery/

In addition, in your discovery message the ‘device’ part must be the same for each sensor created.

This is an example for a humidity and temperature sensor :

temperature :

topic :

homeassistant/sensor/xiron_3201/temperature/config

discovery message :

{"unit_of_measurement":"°C","device_class":"temperature","value_template":"{{ value_json.TEMP }}","state_topic":"rflink/Xiron-3201","name":"eetkamer_temperature","unique_id":"eetkamer_temperature","device":{"identifiers":["xiron_3201"],"name":"xiron_3201","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}

humidity :

topic :

homeassistant/sensor/xiron_3201/humidity/config

message :

{"unit_of_measurement":"%","device_class":"humidity","value_template":"{{ value_json.HUM }}","state_topic":"rflink/Xiron-3201","name":"eetkamer_humidity","unique_id":"eetkamer_humidity","device":{"identifiers":["xiron_3201"],"name":"xiron_3201","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}

Notice the ‘device’ blocks are identical.

I have a similar use case, realized with MQTT discovery for my ESP8266 thermostats.
It let’s HA discover a climate entity plus some sensors and switches.

The code is written in c++, if you’re interested I can share it.

Thanks everyone, this seems to be exactly what I needed! I did code the firmware, and I happened to be using an ESP8266 just like eXtatic.

I don’t think I need code samples just yet, but I wouldn’t object either. :slight_smile:

This question can be considered answered/closed. The help is very appreciated!

@eXtatic, I’m trying to set up the auto-discovery feature for multiple entities, I believe same way as you have done in your example here, so it would be a great help if you could share your code?

Sure, here you go:

Thanks you so much, that will get me started!

Hello everyone, I’m new to Home Assistant too. I have programmed my own LED controller that accesses various topics. It has animations where i want to adjust the speed via a slider. I’ve read a lot about Home Assistant, but haven’t found a tutorial anywhere on how to properly integrate MQTT. Could someone help me with that?

excuse my english, i’m from germany

Wasn’t here for quite some time, still struggeling with MQTT?
You can also PM me if it’s easier for you to talk german.