Influxdb interfacer

I’ve created a PR for an influx interfacer:

and a sneak preview of 2 of my emonhub interfacers publishing directly to influxdb

It’s starting to look at something


I haven’t got all metrics in yet, they just started pushing in this evening, but first results are promising.
I hope to create a dashboard with all my specific appliances and daily load of them, so I can find out where to replace/cut the cord :slight_smile:
As you can see, my calibration is a bit off. I tried my best to match them all with the correct specs, but the spread is just to big. Most of the time my real meter load is 0, which is bad for those CT’s ranged for 100A, which I’m using on my main circuit lines. The measurements from my inverter are also in the system, but using them as calibration made the offset even worse for some of the sensors, so I’ll have to live with the slight differences.

Nice work @ziporah thats a great idea, thanks for sharing! I will test and get this pull request merged

I’ve looked at the mqtt code as well, but this needs some rework. Currently it will only capture emonhub/tx//value topics and requires the value to be in int. I’m thinking of modifying the code so it can use RPICT4V3/dishwasher for example, so I can grab kwhd values from emoncms and publish them in influxdb, that would make the grafana setup even more powerfull. Now it requires quite some work to view my house load for example, since I need to combine 3 phases and 3 measurements per phase in grafana to get the overall usage as my hybrid inverter tries to balance my meter load to 0, while if I export it directly out of emoncms, it just takes one input.

You have any suggestions for naming or can I just extend the on_message function with additional logic to subscribe to pub_topics for example instead of pub_channels?
I can also parse pub_channels to be able to use non-emonhub-prefix as subscriptions

def on_connect(self, client, userdata, flags, rc):
....
# Subscribe to MQTT topics
# Need additional topics here
self._mqttc.subscribe(str(self._settings["node_format_basetopic"]) + "tx/#")
...
def on_message(self, client, userdata, msg):
...
# Need logic here
for channel in self._settings["pubchannels"]:
# Add cargo item to channel
self._pub_channels.setdefault(channel, []).append(rxc)
self._log.debug("%d Sent to channel' : %s", rxc.uri, channel)

I suggest you offer both a value (int or float) and a JSON input.

The value input is more obvious as emoncms will only publish values via MQTT currently.

Base it on a specified base topic that the interfacer then subscribes to. You can then pass multiple values to the interfacer.

[edit]
The other thing to consider is to pull data into InfluxDB via MQTT and Telegraf. This is how I do it currently.

1 Like

Apologies if I am not seeing it, but assuming this is ready for use, could you provide some examples of how to set this up?

I’ve not really used EmonHub much beyond it being on the EmonPi but I would love to get a copy of the feeds into my InfluxDB which has all my OpenHab data in (including 2 other power monitoring sources) and be able to display alongside other stats.

this is the configuration example and this should push all channels you’re subscribed to into influx.
You need another interfacer reading from mqtt so the influxdb kan catch those metrics and inject them into your influx instance. As stated above, it will now only read emonhub/tx//value topics. The other modifications are not in place.

@ziporah - did you get around to doing an InfluxDB v2 interfacer at all?

My emonpi is out of action at the moment while my house is being renovated, and I’m trying to think about how I want everything set up in the new house. I am going more and more into Home Assistant now, and have that set up to pipe into InfluxDB. I think having emon data in there too will be awesome. So I came across this :).

But I am using v2 since I set all this up recently.

I would be up for writing the v2 interfacer myself, but I figured if you have done it already then might as well ask.

hello @mattjgalloway the interfacer is merged in the main code branch, it uses a post to insert the data, so I would just give it a go and see if it works with influx v2. I’m still using influx v1.8.x, but I am pushing data directly from the serial port using emonhub into influx and homeassistant. The setup should be straight forward. I haven’t tried v2 myself, could you let me know the result ? Happy to help if assistance is required

Ah, v2 is quite different in that you have to use a token rather than password, putting it in an HTTP header. And you use an organisation and bucket rather than a database. It’s changed quite a lot.

I am happy to go add support for it. I am not sure yet if it’s best to have a separate interfacer for it, or have an api version setting in your one. I’ll have a look.

You could just add a configuration variable to be set in the emonhub interfacer declaration.

Yep indeed. I’ll take a look and see which option makes the most sense. I think it depends how much code is different between the two implementations tbh.

I have been doing more thinking on what I want though, and I’m likely to not push straight from emonhub into influxdb. Because really I’m going to want the processed feeds in influxdb. So I’ll probably poll in Home Assistant from emoncms (using the integration) and then get automatic influxdb push through Home Assistant.