OpenEnergyMonitor Community

MQTT - a very basic question

Might someone remind me how I check whether an inbound MQTT arrives at my emonPi (which I use as my sole MQTT broker) &/or is then passed on out again?

I have set a separate RPi to send out MQTT messages, but they are not arriving on may Home Assistant instance. Being able to check what is happening on the emonPi will help fault finding.


It has been a while since I used MQTT, so I have to dig up some old notes. In the mean time, here is a link that may help.
‘’'Publishing an input with MQTT from an EmonPi - #2 by borpin

Many thanks @dlmpryor . From that linked thread …

So on the basis that the inbound MQTT messages are not being shown as Inputs within my emonPi, I will take it that the messages are not arriving. They used to, but for some reason stopped, so I will have to investigate why.

A shell script on the other RPi has this content

#!/bin/bash -x
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games 
sleep 20
rtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h -p 1883 -u emonpi -P emonpimqtt2016

But there is no home/rtl topic within my emonCMS. And looking at the emonHub log file, I see no reference to the word rtl either. So perhaps it is not being generated on the other RPi.

Emoncms only picks up topics on a base topic you specify (by default emon).

Cannot see how they did. Wrong base topic.

Use an MQTT client and connect to the Broker, then you can see what is appearing at the broker (I use MQTT.fx from the Windows Store on my Win machine).

BTW, I created a service file for rtl_433 (and suggested it was included).

Works well for me :slight_smile:

Thanks @borpin - I am obviously not the only one wanting to do this :blush:. I’m afraid that my Linux knowledge is sufficiently low as to not really understand a service file. But FWIW, these are the Dummies notes that I have cobbled together so far concerning restarting after boot …

To make the Raspberry Pi start the process on boot up automatically, do the following

In Terminal type export & look for a line that is similar to
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
In my case it was
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games"

Type sudo nano . In the file type (on 4 lines)

#!/bin/bash -x export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games***** sleep 20 rtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h YOUR_MQTT_BROKER_IP -p 1883 -u YOUR_MQTT_BROKER_USERNAME -P YOUR_MQTT_BROKER_PASSWORD
… and then save it (Cntl+O, ENTER, Cntl+X)

Now make it executable with sudo chmod +x

Test that it works by running sudo ./ and it should be OK.

Up until this point all is fine for me, but when I did this yesterday I continued with the next bit but something broke. Not 100% sure my notes are quite right …

Open a new Terminal window and type sudo nano /etc/rc.local and put in it …

cd /home/pi(adjust path as required)
*/the/full/path/to/ & NB: Don’t forget the “&”; in my case, it was *
cd /home/pi/ &
exit 0 NB: This line should already be there, but I include it here to show where to put these lines

Type sudo nohup ./ & (don’t forget the &)
Reboot the Pi and it should provide the Watchman data automatically from now on

What you have done is actually far more complicated!

1 Like

I did get some help with that :cold_face: :blush:

New Question …

I would like to send an MQTT message from Home Assistant to my emonPi which is my MQTT broker. The Topic Name is barns_pv, and this is the Actions section of an Automation.

service: mqtt.publish
  topic: emon/barns_pv
  payload_template: '{{ trigger.to_state.state }}'
  retain: true

Using MQTT Explorer I see that the message is arriving, but it is not within the emon “folder”. How would I change this?

Is it just a matter of adding a new “node” within emonHub, possibly something like this?

[[17]] #16 is the last node currently listed
nodename = barns_pv
names = #not_sure_what_to_put_here#
datacodes = #not_sure_what_to_put_here#
scales = 1
units = W
whitening = 1

Or something else? Many thanks!