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
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.
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 192.168.1.29:8123/emon/emonpi/power1/ 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 192.168.1.29:8123 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.
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
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
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. (192.168.0.105) 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.
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.