Publishing MQTT to Home Assistant from Emonpi - How to test?

Hi I am struggling to send some MQTT from my EMONPI which will go to Home Assistant. I have followed several threads here but I am confused about getting MQTT to work and so far I have not succeeded.

I believe that MQTT is running on my EMONPI and I checked that from setup. I tried some of the topics (including some with wildcards) as mentioned in the testing section of the guide MQTT - Guide | OpenEnergyMonitor I tried to use the topics in HA but nothing seems to come through.

I have now installed MQTT explorer to try and see what MQTT is publishing but I cant work out how to enter the relevant info from my emonpi account into MQTT explorer.

Setting up the MQTT Explorer connection asks for the following, in brackets is what I think I should be entering but it does not work)
Host (IP address of my emonpi)
Username (my emonpi login)
Password (my emonpi password)
After a few moments this says ‘Disconnected from server’

I would appreciate any tips on getting this working.


That’s not right. By default, an MQTT user is created called emonpi with a default password, but I would create a login for Home Assistant by connecting with ssh and using the command
sudo mosquitto_passwd /etc/mosquitto/passwd homeassistant
and then
sudo service mosquitto restart
to make sure it detects the new user (reload instead of restart may suffice but I’m not completely sure). Then put those details into HA and it should connect.

I think you’ll also want to add some “Publish to MQTT” steps to your input processors but maybe there are other ways.

Good luck!

I have managed to look at what is coming out of the emonpi MQTT service with MQTT Explorer using the default userid and password.

However I still cant see the topic in Mosquito MQTT on my HA instance. I may be formatting the topic incorrectly. I have tried and similar but my HA MQQT just sits and does not seem to receive anything.

Can anyone help me with the correct format for subscribing to an emonpi topic in HA Mosquito MQTT?

In order to break the fault finding down you can publish from MQTTexplorer to HA. In that way you easily change your topic / payload string until you find what HA accepts. The address you show is the HA home page. The normal port for MQTT is 1883. I am not sure if you need the MQTT addin running on HA too, I have it enabled and have no problem publishing MQTT message to HA. On your topic you do not need the leading / on emon, it should be emon/emonpi/power, the trailing / isn’t needed either. I hope that helps you sort out your issues.

Thanks Bob I have tried a lot of options but I just cant get it to work in Mosquito MQTT on my HA machine. Would you be able to post the exact format you use for topics on your HA? Thanks

Hi, I’ll have a look at how I post to HA tomorrow as its getting a bit late now. I usually post into Node-RED first and then into influxDb and Grafana for displaying my data. I am sure I have some stuff that posts direct to HA though. I don’t have am emonPi but I do use an ESP8266 to post to emoncms and node-RED via MQTT and HTTP POST. I run Node-RED, InfluxDb and Grafana all under HA too.

I sent you a PM Tim.

1 Like

In MQTT Explorer (assuming it has connected to the EmonPi MQTT Broker and you are using the emonpi login) try subscribing to # (this is the wildcard)

Note - you don’t start topics with a leading / (ever) so to look at the incoming data to emoncms you would subscribe to emon/#

There is probably something in MQTT Explorer that will show all available topics to subscribe to (I use MQTT.fx on Windoze).

Also note, the outgoing (publish) MQTT base topic should not be emon as that is the incoming topic to emoncms.

  - platform: emoncms
    api_key: 394c958a5f1182b06cd7628c5e9~~~~~
    id: 1

This is what you need to place in your configuration.yaml. You will need to get your own api_key from Emoncms website screen under “Setup/My Account”. Copy the R/W API key and replace the one above. You will need to amend the IP address to the one that Emoncms is running on. ( You will see the feeds turn up in HA. Note: Ensure to remove the ‘S’ from the https: if you use the original code as you will not have a security cert installed locally normally. This is what gets people, as they do have the ‘https:’ on the original code. Make sure you are stating the IP of the EMON an not the HA by mistake. This has also happen quite a lot. Enjoy. Only the Feeds will turn up by default unless you start changing stuff. MQTT doesn’t need to be the for this to work.

The OP asked about using MQTT to HA not using the Emoncms Integration.

Yep. Call learn to walk before you run. If he can get this working then at least we know he’s talking the the right boxes. Then, any thing he need to be published in the Feeds would appear. The MQTT works fine as you can set it up in HA and use the default account & Password to login. Then /# in the query to get everything. this again would confirm coms. But, each to there own. :grin:

I disagree. If the question was “how to get data from Emoncms to HA” then you would be correct. But the OP asked about MQTT so that is the answer given.

You can publish data to MQTT that you do not pass into a Feed, so it is a different question.

Hi all thanks for the continues help.

I am trying to see emon data in my HA I don’t really mind how I get it. I had assumed that the mechanism would be via MQTT but that may not be correct, I am very new to HA and I may have used the wrong terminology.

II have just managed to get some data into my HA using Davids method above, however I think previously I may have been editing the wrong configuarions.yaml file, this time I used the one in config/ and I can see data in my dashboard.

Although I can see some data it seems to be static and isn’t updating but its a big step forward to know I can get the data into HA.

I hope you have made progress. I have a similar quest. I have asked the forum how the mechanism for posting data to works, since the entries in the Sync tab are empty in my local emoncms, but I have not received any response.

I have an experimental espwroom32 board reading the mqtt messages over wifi. I could extend this to relay the mqtt messages to adafruit and from there I can link to IFTTT and Google Assistant. This seems more straight forward than penetrating the mysteries of how data gets from the local emoncms to

I wonder if there might be relevance here to your project.

Exactly what is your quest (I have answered your other question).

My Ultimate Quest is to get the data out of the emoncms ecosystem and into a IFTTT system. I would then be able to control smart plugs etc with Google Assistant.

A route seems to be to publish the mqtt values to adafruit (which I can do with an espwroom32 board reading the mqtt messages over wifi) and from there to IFTTT and from there to Google Assistant.

However the emoncms system is quite sophisticated and capable of publishing to and so I would prefer to eliminate the need for a separate piece of hardware, the espwroom32, and have the local emoncms publish directly to adafruit (or similar, from which IFTTT can read).

However I don’t understand the mechanism or settings by which the local emoncms publishes to


There is an ‘OEM’ ecosystem - emoncms (local and cloud) is just one small part of it.

You could republish the data to a different MQTT topic as part of the Input Processing (that does presume you use MQTT for this).

Such as


It doesn’t, emonhub (when set up correctly) does that usually.

Thank you again.

“You could republish the data to a different MQTT topic as part of the Input Processing (that does presume you use MQTT for this).”

I already have everything I want to deliver to IFTTT as mqtt messages. I have the currents and voltage as measured by the emon system in the garage. This includes the excess Watts. I also have the temperature, wattage and cumulative Wh of the immersion heater tank. These are all mqtt messages eg
Message arrived on topic: emon/ardAC/wTempC. Message: 50.81
which is the debug message from the espwroom32 board.

It would be easy to send these data on to adafruit as they are received. My question is whether there is a more direct way of sending the data directly to adafruit directly from the emon system. That is what I assumed “Sync” was all about.

Where are the settings for emonhub that control that, please?

Is there a config file?


You are confusing yourself by having 2 threads!!!