How to implement a custom MQTT device (Home Theater Receiver)

Hi,
I know this question has already been asked but it doesn’t answer to my case. I’m pretty new to HA and I don’t understand everything yet.
A long time ago I builded an adapter that makes Sony Control AII protocol available in an MQTT broker, to remotly send commands and control / automate my old Receiver. It works like a charm but now I want to integrate it to HA, but, I don’t understand how. With my actual setup I can control input channel, volume, power, and many other. I saw that in HA I can add a custom MQTT bynary sensor, switch… but not as a single device, and I want all state and commands to be in the same device, not just have on off… Can someone explain me where I’m wrong please ? I don’t know if my question is really clear but, thanks by advance for your advices.

1 Like

Devices in home assistant are comprised of entities. An entity in home assistant is a single state. Entities can have numerous attributes associated with that single state.

You can create all 3 from MQTT discovery. Home assistant relies on a configuration for a device or entity. If that configuration doesn’t exist, it doesn’t know what topics are associated with that device or entity.

You can keep your current setup to automate your receiver, all you need to do is establish a configuration for home assistant to know how to handle your device.

Through YAML, you can only create entities. Through MQTT automatic discovery, you can create whatever you want (including devices).

1 Like

Thanks for your answer.
If I understand well, I’m better to rewrite my MQTT implementation to match HA MQTT Discovery specification, and then, if well setup, my Receiver will show up with a device that has many entities, that’s right ?
Thanks for your link

your topics and data shouldn’t change. You need to ADD discovery information as a topic that follows the discovery protocol. Follow the link I provided from top down and hopefully you’ll understand what you need to add.

But you basically need 2 things:

  1. A configuration via a topic
  2. A topic(s) that contain(s) your sensors data that’s continuously updated.

Home assistant then configures it self using #1. That configuration pulled from #1 tells home assistant what the data is for #2. Home assistant then creates the sensor for #2 and uses #2 to update said sensor.

1 Like

Ooooh, yeah I understand now ! I’m going to try it. Many thanks, Have a nice day !


Thanks a lot !! Thanks to you I achieved what I tried for more than a week, now, it finally works !

3 Likes

hey there! would you be able to link to some documentation that you used to help build out your discovery packet? or would you be able to share your packets that you crafted? I’m struggling to find documentation on this but this is similar to what I want to do, too!

2 Likes

Hey @Seb7o,
Can you post you configuration please?
Thanks.

3 Likes

Hey/Salut
It would have been very keen to you to share your work, like the configuration used to create that Device.

Best, cordialement.
David.

Hello,
As a beginner, I created the following solution:

  1. I added a mqtt include line to the configuration.yaml file
mqtt: !include /config/myconfig/integrations/mqtt/mqtt.yaml
  1. I created an mqtt.yaml file in which I listed the entities/sensors
#mqtt:
  binary_sensor:
  ##### Adel device binary_sensors
    - name: "Battery Voltage Alarm"
      unique_id: "adel_battery_voltage_alarm"
      icon: mdi:alert-outline
      state_topic: "N510/N510_public"
      value_template: >
        {% set status = value_json['Adel']['battery'].battvoltagealarm | int %}
        {% if status == 0 %} OFF
        {% else %} ON
        {% endif %}
      device_class: problem
      entity_category: diagnostic
      availability:
        - topic: "N510/Adel"
          payload_available: "online"
          payload_not_available: "offline"
      device:
        identifiers: "adel_cbi2420a"
        name: "Adelsystem CBI2420a"
        manufacturer: "ADELSYSTEM"
        model: "CBI2420a"
        sw_version: "v.0.111"
        via_device: "USR-IOT N510"                   # ModbusToMqtt gateway
        configuration_url: "http://192.168.1.50"    # ModbusToMqtt gateway

---etc

  sensor:
  ##### Adel device sensors
    - name: "AC Input Voltage"
      unique_id: "adel_ac_input_voltage"
      state_topic: "N510/N510_public"
      value_template: "{{ value_json['Adel']['main'].voltage }}"
      device_class: "voltage"
      unit_of_measurement: "V"
      state_class: "measurement"
      availability:
        - topic: "N510/Adel"
          payload_available: "online"
          payload_not_available: "offline"
      device:
        identifiers: "adel_cbi2420a"
        name: "Adelsystem CBI2420a"
        manufacturer: "ADELSYSTEM"
        model: "CBI2420a"
        sw_version: "v.0.111"
        via_device: "USR-IOT N510"                       # ModbusToMqtt gateway
        configuration_url: "http://192.168.1.50"        # ModbusToMqtt gateway

---etc

With this solution, the entities are listed under one device.

I had a couple of problems too. I am reading modbus devices with a ModbusRtuToMqtt gateway. Unfortunately, the gateway can only publish the data in one topic. Currently, writing registers via mqtt is still causing problems, but the system works.