MQTT / OpenHab Confused

  • Platform information:
    • Hardware: Raspberry Pi 4
    • Raspian Buster
    • openHab 2.5 (install using openhabian)

I am new to MQTT and OpenHab and I just cannot seem to find the information I need to get started with adding MQTT Things.

I am trying to add and be able to view the Power, Voltage, Temperature and related paramaters from an emonPi device that looks like this in MQTT Explorer.

image

So far I have configured the MQTT Broker settings to access the emonPi’s MQTT broker, but after a couple of days looking for the information to get started - I am just totally lost and confused as to how I go about adding a MQTT Thing in in the latest OpenHab 2.5 to view these values.

Hello mate,

This might help.

I have open-energy-monitor running on a different RPI than openhab

This is my things file

Bridge mqtt:broker:emonmosquitto "emonmosquitto" @ "MQTT" [ host="xxxxxxx", port=1883, secure=false, retain=false, username="emonpi", password="emonpimqtt2016", qos=0, keep_alive_time=30000, reconnect_time=60000 ]
{
    // Emonpi
    Thing topic emonpi "House Power" @ "MQTT" {
    Channels:
        Type number : emonpi_ct1 "House Power"          [stateTopic="emon/emonpi/power1pluspower2"]
    }
}

this is my items file

Number  emonpi_ct1      "House Power [%d W]"  {mqtt="<[mosquitto:emon/emonpi/power1:state:default]"}													

Have you installed mosquitto on openhabian?

sudo openhabian-config
then choose option 20, mosquitto is option 23

you also need to download the mqtt binding via paperui, first of all you need to enable legacy 1x bindings, thats under - configuration>system> you will see a switch to include legacy 1x bindings. Once you have done that download the mqtt x1 binding in addons>bindings

on my things file you need to change the host xxxxxxx to the ip of the rpi that is running emonpi

1 Like

i would also download mqttfx for your pc then subscribe to your emonpi with this emon/emonpi/# when you add # at the end it will look for all of your mqtt items that use emon/emonpi

this is a great way to find out if your emonpi is actually ‘publishing’ any data via mqtt, once you know that it is then you can ‘subscribe’ to it via mosquitto on openhab.

If you want to continue to use the UI to define Things:

  1. Go to the inbox, click the + icon, select MQTT
  2. Click “Add Manually”
  3. This should all be familiar to you since you’ve created the Broker Thing (and it shows as ONLINE?). Click on “Generic MQTT Thing”.
  4. Give it a meaningful name and ID.
  5. At the bottom right there should be something like “Open newly created Thing”. If you miss that, search for or browse to the new Thing in the list. Open it for editing by clicking on the pencil icon to the right.
  6. For each topic you want to subscribe to: click “Add Channel”, select the appropriate type, it looks like number is the correct one for all of these topic. Enter the topic with the value you want to subscribe to for the State topic. For example, to get the first temperature reading (?) at emonpi.local/emonpi/t1 for the State topic. As with the Thing, use meaningful names and IDs.

That’s it. There are no transformations or anything tricky needed here it appears. Just create number channels for each topic you want to subscribe to and put the right topic in.

1 Like

Thanks - I had tried adding a Channel, but could not fathom out what I should be entering in the bewildering (to me) configuration settings - all the information I found seems to make assumptions that you know far more than I do.