Mqtt Homeassistant example

Hi,

Can anyone provide an example of how to configure a thing and channels in a “things” file for a mqtt homeassistant component? Paper UI can create a thing with autodiscovery, but how to do same from the things file?

Here is a Things file example with sonoff devices.

Bridge mqtt:broker:pibroker "pibroker" [ host="10.0.1.15", port=1883, secure=false, username="xxxxxxxx", password="xxxxxxx" ]
{
    // Sonoffs
    Thing topic sonoff11 "Living Room Light" @ "Living Room" {
    Channels:
        Type switch : power       "Power"         [ stateTopic="stat/sonoff11/POWER", commandTopic="cmnd/sonoff11/POWER" ]
        Type number : temperature "Temperature"   [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature" ]
        Type number : humidity    "Humidity"      [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Humidity" ]
    }

//    Thing topic sonoff2 "Couch Light" @ "Couch Light" {
//    Channels:
//        Type switch : power        "Power"         [ stateTopic="stat/sonoff2/POWER", commandTopic="cmnd/sonoff2/POWER" ]
//    }

//    Thing topic sonoff55 "Office Light" @ "Office" {
//    Channels:
//        Type switch : power        "Power"         [ stateTopic="stat/sonoff55/POWER", commandTopic="cmnd/sonoff55/POWER" ]
//    }

Ignore the // (comment out parts) as I no longer use files for things. BTW, it’s recommended to use PaperUI for the Thing and files for items, sitemap, rules, etc…

Thanks, however I am interested in https://www.openhab.org/addons/bindings/mqtt.homeassistant/ and can’t find a way to configure it from things file.

The purpose of the Homie and Home Assistant sub-bindings is to do automatic discovery. If you are not doing automatic discovery (i.e. hand coding them in .things files), use Generic MQTT Things (there are lots of examples on the forum in addition to the one H102 posted). You’ll have to figure out which topics you care about and what they mean on your own.

1 Like

As much as I am thankful for the response, this does not answer my question. For one reason or another, I want to have everything configured in the file (name me old-fashioned), and I am sure this should be possible with this binding as well. So either somebody knows this, or I will just switch to running this through generic mqtt.

What Rich is telling you is that if you do not want to use the self-discovery features of a Home Assistant device, and you want to configure it via files instead, then you must configure it in a file as a “generic” MQTT Thing. That’s it, that’s what you do.

2 Likes

In fact I did understand that. However, I wanted to use the auto-configuration ability (without specifying direct mqtt topics) of the home-assistant part of the mqtt binding without the auto-discovery part of it.

For you to better understand, it is the same thing if I would have a Sonoff/Shelly/Tasmota binding and when specifying a device in the things using IP configuration, it would ask you to enter MQTT topics. I would like to use auto-configuration part of it, however I do want to specify it not in the JSONDB but in my things file.

I have no idea what you are thinking. You understand that a remote MQTT device or service can have an infinitely flexible number and format of topics, and infinitely flexible and variable payload content?

it seems that we are not on the same page. to make the long story short, once device is found in auto-discovery I want to add it not through the JSONDB and paperui, but rather move it to things file. If this is not available, then we can stop this thread.

It’s not available, for any binding, for any discovery method

1 Like

You can’t get auto configuration without auto discovery. You either can do auto discovery or you have to define each and every Channel manually in the .things file. That’s how it works for all bindings. If you want to use .things files, you don’t get to take advantage of any automatic discovery or configuration.

Yes, this is exactly what I want. I want to setup a home-assistant (esphome) device manually in the things file and not use the paper-ui to add an auto-discovered one. How to do this? Each and every other binding supports adding item through things file even if the same device you want to add is auto-discovered one. I don’t see why the current home-assistant mqtt could not follow same logic.

It does. You would define your devices in a xxx.things file using the generic MQTT binding definitions here -


which does not care if your topics mention homeassistant/blah or not.
You could have done it by now.

Thank you for your help. I will make sure not to bother this forum with any more of my questions.

I understand your frustration, we share it too.

“I want to define my Things in a .things file.”
“Okay, here’s how you define Things in a .things file. Here’s an example, too.”
“No, I want to define my Things in a .things file.”

Clearly there’s some disconnect.

2 Likes