I was struggling for quite some time with how to get the statistical and realtime data from a victron Venus GX control block. Everything connects to it and so it should know about all the numbers that all the devices push to it.

Luckily, there is quite a simple solution I was not aware of. Tons of documentation and quite easy to set up.

Here’s what you will need:

  • Linux computer in the same network
  • Port 1883 open between you linux server and the Venus system
  • mosquitto, maybe other compatible mqqt broker
  • telegraf data acquisition suite
  • influx database (or any other) to store the data

Linux system setup

First, we need a Linux server that will be the mqtt broker to receive the data from the Venus GX. I will use a Arch Linux installation, as I like the distribution quite a lot. There are some extra steps to consider for this distro though.

As part of the installation, you’ll need to install a helper, such as yay! to take advantage of the AUR packages and easy installation. You’ll need a couple things to get you started.

# get the yay git cloned, getting the sources
git clone https://aur.archlinux.org/yay-git.git
cd yay-git/
# next line requires packages: make, fakeroot, gcc. Install them with sudo pacman -S make fakeroot gcc
# Make the package and install it
makepkg -si

Next on the list is to make the telegraf suite run on the server. Now telegraf is present in the AUR, so after a successful installation of yay, this should be a breeze. Of course, you can install it from git as well. This package is not present in the standard Arch repositories

# install the suite from AUR
yay -S aur/telegraf-bin
sudo systemctl enable telegraf
# don't forget to install the mosquitto package
sudo pacman -S mosquitto
sudo pacman -Ss mosquitto
community/mosquitto 2.0.15-2 [installed]
    An Open Source MQTT Broker


Setup of Victron Venus GX

MQTT service is not enabled on the Victron device by default. Let’s quickly navigate the right place to enable it:

Click anywhere into the overview to get a menu

Go to Settings

In Settings, find services, second to last from the bottom

Enable SSL MQTT. If on local network only, you can enable the plaintext MQTT as well. Otherwise I’d discourage from this.

There you go, you just enabled the MQTT services for the Victron GX.

Testing the connection and evironment details

Now, with the MQTT service enabled on the Victron Venus GX and the mosquitto package installed on the Linux system and these two being on the same network, let’s test it out. -v is verbous -I is the client name prefix, choose whatever you want, -h is the host and -p is port. -t is the transmit message.

# In short, this will just subscribe (read) all the output from the MQTT from that particular IP address, # being the wildcard in MQTT. 

mosquitto_sub -I myclient_ -v -h 192.168.1.104 -p 1883 -t '#'

# The result here:

N/38d26970ba3a/system/0/Ac/ConsumptionOnOutput/L1/Current {"value": 0.9200000166893005}
N/38d26970ba3a/system/0/Ac/Consumption/L1/Power {"value": 204}
N/38d26970ba3a/system/0/Ac/Consumption/L1/Current {"value": 0.9200000166893005}
N/38d26970ba3a/system/0/Dc/Vebus/Current {"value": -4.099999904632568}
N/38d26970ba3a/system/0/Dc/Vebus/Power {"value": -204}
N/38d26970ba3a/system/0/Batteries {"value": [{"id": "com.victronenergy.battery.socketcan_can1", "temperature": 27.799999237060547, "power": 79, "current": 1.600000023841858, "soc": 52, "active_battery_service": true, "instance": 512, "state": 1, "name": "Pylontech battery", "voltage": 49.45000076293945}]}

All you need to do is find the proper metrics you want to monitor, for example the voltage of battery:

mosquitto_sub -I myclient_ -v -h 192.168.1.104 -p 1883 -t 'N/+/system/0/Dc/Battery/Voltage'

# and the result
N/38d26970ba3a/system/0/Dc/Battery/Voltage {"value": 49.13999938964844}
N/38d26970ba3a/system/0/Dc/Battery/Voltage {"value": 49.130001068115234}
N/38d26970ba3a/system/0/Dc/Battery/Voltage {"value": 49.099998474121094}
N/38d26970ba3a/system/0/Dc/Battery/Voltage {"value": 49.09000015258789}
N/38d26970ba3a/system/0/Dc/Battery/Voltage {"value": 49.08000183105469}

# or using wildcards
mosquitto_sub -I victron_ -v -h 192.168.1.104 -p 1883 -t 'N/+/+/+/+/Battery/+'

# result
N/38d26970ba3a/system/0/Dc/Battery/BatteryService {"value": "com.victronenergy.battery.socketcan_can1"}
N/38d26970ba3a/system/0/Dc/Battery/ConsumedAmphours {"value": null}
N/38d26970ba3a/system/0/Dc/Battery/Current {"value": 2.0}
N/38d26970ba3a/system/0/Dc/Battery/Power {"value": 98}
N/38d26970ba3a/system/0/Dc/Battery/ProductId {"value": 45065}
N/38d26970ba3a/system/0/Dc/Battery/Soc {"value": 52}
N/38d26970ba3a/system/0/Dc/Battery/State {"value": 1}
N/38d26970ba3a/system/0/Dc/Battery/Temperature {"value": 27.799999237060547}
N/38d26970ba3a/system/0/Dc/Battery/TemperatureService {"value": "com.victronenergy.battery.socketcan_can1"}
N/38d26970ba3a/system/0/Dc/Battery/TimeToGo {"value": null}
N/38d26970ba3a/system/0/Dc/Battery/Voltage {"value": 49.459999084472656}
N/38d26970ba3a/system/0/Dc/Battery/VoltageService {"value": "com.victronenergy.battery.socketcan_can1"}
N/38d26970ba3a/system/0/Dc/Battery/Current {"value": 1.899999976158142}
N/38d26970ba3a/system/0/Dc/Battery/Power {"value": 93}
N/38d26970ba3a/system/0/Dc/Battery/Current {"value": 2.0}
N/38d26970ba3a/system/0/Dc/Battery/Power {"value": 98}
N/38d26970ba3a/system/0/Dc/Battery/Current {"value": 1.899999976158142}
N/38d26970ba3a/system/0/Dc/Battery/Power {"value": 93}
N/38d26970ba3a/system/0/Dc/Battery/Current {"value": 2.0}
N/38d26970ba3a/system/0/Dc/Battery/Power {"value": 98}

There is one little caveat to this. The information relayed, does end after a certain period of time (found 5 minutes). This can be avoided by opening another window and sending a keepalive signal to keep the stream flowing. Please note the mosquitto_pub and not mosquitto_sub

mosquitto_pub  -h 192.168.1.104 -m '' -t 'R/38d26970ba3a/keepalive'

I recommend putting this command into the crontab of the Linux server:

# Either with crontab -e
*/5 * * * * mosquitto_pub -h 192.168.1.104 -m '' -t 'R/38d26970ba3a/keepalive'

# Or a one-liner to add the line to crontab
(crontab -l 2>/dev/null; echo "*/5 * * * * mosquitto_pub -h 192.168.1.104 -m '' -t 'R/38d26970ba3a/keepalive'") | crontab -

Configure the automated data acquisition via telegraf

Now to configure the mqqt consumer module of telegraf. The config files are located under /etc/telegraf/telegraf.d and we make a new file here, called input.mqtt or whatever you wish it to be called, with this content. Keep in mind, this is the setup for my installation. You can look up your

[[inputs.mqtt_consumer]]
  servers = ["tcp://192.168.1.104:1883"]
  topics = ["N/+/vebus/+/Ac/Out/P", "N/+/system/0/Batteries","N/+/vebus/+/Ac/ActiveIn/P","N/+/solarcharger/+/Yield/Power
","N/+/system/0/Dc/Battery/Voltage"]
  data_format = "json"

#[[inputs.mqtt_consumer.topic_parsing]]
#  topic = "/38d26970ba3a/system/0/Dc/Battery/Voltage"
#  measurement = "/measurement/_/_/_/_/_"
#  tags = "/id/_/_/type/_/_"
#  fields = "/_/_/_/_/_/volts" 

The load into a database is not really part of this short article, but just for the sake of information, consider this:

[root@archfiler ~]# cat /etc/telegraf/telegraf.d/output.influx.conf 
[[outputs.influxdb]]
  urls = ["http://influxdb-telegraf"]
  database = "telegraf"
  # retention_policy = ""

  ## Write consistency (clusters only), can be: "any", "one", "quorum", "all".
  ## Only takes effect when using HTTP.
  # write_consistency = "any"

  ## Timeout for HTTP messages.
  timeout = "20s"

And then a grafana configured display of these values over time:

Pretty simple, or? Let me know in the comments.

Cheers.