Join multiple MQTT topics to one device

Hi

First time user here to play with HA, coming from another home automation system.
I’m trying to add my old Automower to HA from MQTT.
It sends the various values as sub topics, not a json, like this:
image

How do I combine this to one single “device”?
I have added it as a sensor, just to start with:

sensor:
  - platform: mqtt
    name: Automower
    icon: mdi:robot-mower-outline
    state_topic: "Automower/AM_G2/State/Status"

thanks

btw: is it correct that i need to restart HA every time i’ve modified configuration.yaml?

The word “device” has special meaning in Home Assistant. It typically refers to a physical device that is represented by one or more entities. For example, the Philips Hue bridge is a device and each Hue light is represented as a separate light entity. Here’s another example, my laser printer is a device and all of its characteristics (toner level, page count, etc) are represented as separate entities:

Another way to model something is to represent it as a single entity with multiple attributes. For example, here’s sun.sun. Its state (above_horizon) is the current state of the sun and all other characteristics (elevation, next_dawn, etc) are reported as attributes.

Yet other way is not to use a device or attributes but to simply represent each characteristic as a separate entity.

So which one of these three options do you want to use to model your Automower?

Thanks for explanation. Are there any drawback in using device or entities, when using them later on in automation etc? based on your explanation I would go for one entity with multiple attributes. I also want to map the status numbers to decriptive text.

There are no drawbacks in using devices or entities (unless you consider it a drawback to seeing each one of Autommower’s sub-topics exposed as a separate entity in Configuration > Entities). One advantage to this arrangement (as I’ve explained above) is that it reveals information about the physical device. The other advantage is that each sub-topic is a separate entity so that’s useful if you plan to create automations that need to trigger on any of those sub-topics.

The advantage of modeling it as entity with attributes is compactness (it’s a single entity). It’s still possible to create automations that trigger when an entity’s attribute changes but it’s not as neat as with separate entities.

You should know that it will be challenging to create an entity with attributes based on multiple MQTT topics. An MQTT Sensor offers json_attributes_topic to subscribe to a single topic and json_attributes_template to convert the JSON payload into one or more attributes. Your Automower’s multiple topics can’t be used with this arrangement. You might have to use an external program to subscribe to all the topics and re-package all the data into a single topic with a JSON payload (i.e. into something that Home Assistant knows how to easily process).

All this to say that Automower’s multiple topics may oblige you to model it as a device with many entities

If i can preprocess the data into a json object, how should It then look, based on screenshot?

I’m not going to re-type all the sub-topics but this abbreviated version should give you an idea of what it can look like:

{"IRight": 10, "ILeft": 10, "Mode": 1, "Stats": {"First": "something", "Second": 52}, "Minuterie": 0}

Has any of the information I have provided helped to answer your original question?

Thanks for explanation. Yes absolutely! I’ll play around wheter it should be a device or an entity

1 Like