OpenEnergyMonitor Community

Publishing an input with MQTT from an EmonPi

Tags: #<Tag:0x00007fe7b1c9ce80> #<Tag:0x00007fe7b1c9cd18>

I’m trying to publish an input to mqtt. The input is called Grid and shows up in my emonpi after the usual power1, power2 etc.

I’ve set up an input process to publish it to MQTT. It’s not appearing at all.

I’ve used MQTTLens to see if it’s there and it isn’t. Is there something I’ve missed?


MQTT has a publish and subscribe mechanism.

Publish is one device sending data to the MQTT Broker
Sebscribe is one device asking the MQTT Broker for data.

Emoncms looks for any topic with the base topic emon/ and then pulls that data in as an Input.

If you want to publish data from Emoncms for other devices to use, you need to use a different base topic name else it will appear as an INput

How is Grid created in the first place. I think you have created a loop and it keeps appearing as the retain flag is set.

Hi Brian O.

I’m not familiar with MQTT but my emonEVSE requires it. I used to have it all working but I needed to rebuild this emonPi.

Grid comes from a calculated field that I send to the emoncms on that emonPi using Python

data1 = '{'
data2 = 'Grid:{}'.format(grid)
data3 = '}&apikey=xxxxxxxxxxxxxxxxxxxxx'
data = data1 + data2 + data3
r = requests.get(data)

I need to make it available to the emonEVSE via MQTT. As I understand it the emonPi needs to publish the value and emonEVSE needs to subscribe to it.

I’ve tried changing the base to emonBH like this:

but that doesn’t seem to work either.

So this is my emonEVSE side which (apart from me changing emon to emonBH for this test) hasn’t changed.

MQTT Lens shows nothing for emonBH.

Have I misunderstood and changed the wrong thing?

Brian H.


this is how I do it, hope it helps



Hi John

Yes, That’s pretty much how I had mine set up originally. I’ve tried changing the name of the MQTT feed to solarpower, just like yours in case there was some confusion with me having an input also called Grid but it’s still not working.

I’m flumoxed. My setup looks like yours and how it used to work in my old setup which would have been several years old.

I downloaded the prebuilt-card version a couple of days ago. I’m wondering if there are any problems with MQTT with it or is there some setting I should change?

Anyway, thanks for posting what your setup is.


You must see solarpower as an Input as well then.

Anything on the broker under the base topic of emon/ will be processed as an input.

Not really, as you are posting

from Python → Emoncms → MQTT → Emoncms

Because you published to the same name, that published data is then read back in as an Input and published back out - you have a loop.

What bit of that doesn’t work? Do you see it (a value published to the topic emonBHemonpi/grid) in your MQTT Lens?

Oh I see - remove the leading /

Hi Brian

D’oh! That was it. As soon as I removed that leading / it worked. And yes, Brian, you’re right I have Grid with the post to MQTT and now I see solarpower as an input as well. So it wasn’t a good idea to have the Input called Grid and to publish it to Grid.

Thanks to you and John.

1 Like