Victron VRM Portal API data integration

As mentioned above I wrote a detailed post on this integration; Victron/Fronius off-grid PV Energy Dashboard - MQTT and modbus integration
Try to go through steps 3 to 6; on point 6 point your MQTT explorer to your Home Assistant IP to check if the connection is working.
Let me know the results.

2 Likes

@lsgv Thank you so much for your work!
I’ve been lurking like 3 years thinking: “There will soon be a Victron Integration - as popular as it is worldwide. Even more so since it is dutch and HA is strong there”.
Now I bit the bullet and finally got it to work!

I just struggle a bit with the value template to extract some information - how e.g. would I get the valueEnum Text of the charge state?

{
	"idSite": 11111,
	"timestamp": 1646491465,
	"Device": "Solar Charger",
	"instance": 288,
	"idDataAttribute": 85,
	"description": "Charge state",
	"formatWithUnit": "%s",
	"dbusServiceType": "solarcharger",
	"dbusPath": "/State",
	"code": "ScS",
	"bitmask": 0,
	"formattedValue": "Float",
	"rawValue": 5,
	"dataAttributeEnumValues": [
		{
			"nameEnum": "Off",
			"valueEnum": 0
		},
		{
			"nameEnum": "Fault",
			"valueEnum": 2
		},
		{
			"nameEnum": "Bulk",
			"valueEnum": 3
		},
		{
			"nameEnum": "Absorption",
			"valueEnum": 4
		},
		{
			"nameEnum": "Float",
			"valueEnum": 5
		},
		{
			"nameEnum": "Storage",
			"valueEnum": 6
		},
		{
			"nameEnum": "Equalize",
			"valueEnum": 7
		},
		{
			"nameEnum": "Off",
			"valueEnum": 245
		},
		{
			"nameEnum": "Equalize",
			"valueEnum": 247
		},
		{
			"nameEnum": "Ext. Control",
			"valueEnum": 252
		}
	],
	"id": 98
},

In the Victron world there are so many system configuration variants and options that I believe it would be close to impossible to create an HA integration that would satisfy everyone. It’s magic that Victron publishes so much and gives everyone access to the inner workings of their system. And we can build solid bespoke integrations using that.

In your case, I believe you are still using the REST mode, querying the cloud VRM services. I started that way too but soon found out it is suboptimal. Especially when you have all the information served on the local network both by the MQTT broker and modbus.

I recommend not getting hung up on extracting values from JSON responses as the structure of these will change over time and your carefully tuned templates will stop working. Go the MQTT or the modbus route depending on whichever you prefer or are more comfortable with. More user friendly, more robust.

A couple of posts above in this thread you’ll see a link to a more detailed guide using MQTT including the creation of power, energy, and utility counter sensors and integration with HA Energy Dashboard. Why don’t you take a look and see if that works for you, and come back with any questions you may have?

Yeah - I am sure you’re right and appreciate the recommendation to do it locally.
It’s a bit offtopic though: I use Victron stuff in my campervan. Last summer I played around with a nice Teltonika RUTX11 Router which directly does Modbus, GPS and VPN to my Home with HA. Unfortunately though it consumes about 15 Watts and during the winter months I have just enough solar for my VenusRPI :frowning:
Currently I am researching the best method to get VenusPi and RaspAP (with Adblockin, WireGuard to Home and Speedify to combine uplinks) running on one power efficient host (like a Pi4 running 3 raspberry systems as virtual machines). That would allow me a 24/7 uplink, some nice HA automations or even controlling some ESP32 for tank sensors and similar stuff.

1 Like

Hi Luis

Many thanks for your informative article on the Cerbo GX and MQTT broker. However, I already use MQTT broker in HA for Sonoff Light switches, etc, so I am not sure how to use HA with Cerbo GX in this scenario.

Can you please assist?

Many thanks in advance
Werner

Hi Werner.

After this post I kind of re-wrote it in another more complete post you can find here
Let me know if this answers your question otherwise I’ll try to help even though I’m definitely not an MQTT expert.
In the meantime, just for info, I’ve moved on from using MQTT to directly integrate Venus OS using modbusTP. There were two reasons: first, I’m also using modbus for the automation of my pool filters, SWC and sensors which do not offer MQTT so it made sense to consolidate onto one protocol rather than two. Secondly I simplify the whole setup by not having to run two MQTT brokers, one on the CCGX and another one on HA. I’m planning on following up on my post with this change but time is lacking.
Just let me know if you could sort it out.

Hi Luis

Firstly thank you for your guide. I’m completely new to all this and was able to understand for the most part.

I successfully followed your guide until step 6 and everything is working fine. I even managed to add battery soc as a sensor. But the value is not translating properly.

My question is, how do I add the data from the topics successfully so I can use it in my automations?

Also, will you add instructions for modbus integration and would this be better?

Regards

How did you get things working in the Energy dashboard when using Modbus? I have all the entities working here, but I can’t add them to the Energy dashboard due to them not having uniqueIDs.

Attached a snippet of one of my modbus configuration files. I’m using unique_id as you can see. Did you try it and if yes do you get errors?

# Power and energy flows
# COO = ConsumtionOnOutput = consommation des charges
- name: Consumption On Output
  unique_id: consumption_on_output
  state_class: measurement
  device_class: power
  scan_interval: 30
  slave: 100
  data_type: uint16
  address: 817
  unit_of_measurement: 'W'
# AIP = ActiveInPower = Puissance entrée générateur
- name: Active In Power
  unique_id: active_in_power
  state_class: measurement
  device_class: power
  scan_interval: 30
  slave: 100
  data_type: int16
  address: 823
  unit_of_measurement: 'W'

Attention, these are “power” entities, you need to transform them into “energy” entities by using the “integration” integration (yes, that can be confusing).

# Intégration des entités puissance en énergie
- platform: integration
  source: sensor.active_in_power
  method: left
  unit_prefix: k
  name: Energy from Grid

The resulting “energy” entities are what you can/need to configure into your Energy Dashboard.

Let me know if it works.

Since last core update the victron data via mqtt are not longer available.
Any Idea what has changed?

Have you looked into 2022.12: It does matter! - Home Assistant
The MQTT sensor configuration has changed. Did you catch that and changed your sensor configurations to the new standard?
As a rule, I always read the release notes in full especially the breaking changes part.

Does anybody has an example how to convert the old sensor into the new version?

That was running in the config yaml until update…

sensor:

VICTRON PV SOLAR

  • platform: mqtt
    unique_id: victron_cons_L1
    name: “victron_cons_L1”
    state_topic: ‘N/d41243b5xxxx/system/0/Ac/Consumption/L1/Power’
    unit_of_measurement: “W”
    value_template: “{{ value_json.value | float(0) | round(0) }}”

I’ve tried also this with no result

VICTRON PV SOLAR

mqtt:
sensor:

  • name: “victron_cons_L1”
    unique_id: victron_cons_L1
    state_topic: “N/d41243bxxxxx/system/0/Ac/Consumption/L1/Power”
    unit_of_measurement: “W”
    value_template: “{{ value_json.value | float(0) | round(0) }}”

To share code you need to use the preformated text using the editing sign

</>

that you find at the top of your comment text editing window. That way your exact formatting comes through and you will get better advice. This bring said, your MQTT sensor configuration should look like:

# Example configuration.yaml entry
mqtt:
  sensor:
    - state_topic: "home/bedroom/temperature"

In your case I guess this would be (note the indentations, YAML requires strict indentations to work):

mqtt:
  sensor:
    - name: “victron_cons_L1”
    - unique_id: victron_cons_L1
    - state_topic: “N/d41243bxxxxx/system/0/Ac/Consumption/L1/Power”
    - unit_of_measurement: “W”
    - value_template: “{{ value_json.value | float(0) | round(0) }}”

Give it a try and let me know if it works.

Hallo und guten Tag. Ich entschuldige mich, dass ich auf deutsch schreibe, aber da bin ich sicher, dass ich keine Fehler erkläre.

Ich habe seit 3 Wochen ein Victron System mit 1xMultiplus2, 1xCerbo GX und 2xMPPT Lader.
Ich habe es irgendwie geschafft, dass über mqtt Daten gesendet werden. Aber ich finde keine Tageswerte, wie sie im VRM gezeigt werden.
Nun habe ich gesucht und die Seite “vrm api docs.victronenergy .com/#/” gefunden.
Hier “VRM API documentation” kann ich mit der Email Adresse und dem Passwort einen Token erstellen. Egal wie ich diesen verwende, komme ich nicht weiter.
Ich wollte im nächsten Schritt hier “VRM API documentation” weiter machen.
image
Die Informationen von @lsgv Luis sind hervorragend geschrieben, aber ich habe den nächsten Schritt aus den Texten nicht erlesen können. Was kann ich tun?
Allgemein suche ich eine Möglichkeit, Tageswerte für Solarertrag und Verbrauch zu bekommen.
Danke fürs Lesen.
Guido

Hello Guido. My German is quite limited and rusty but I got the point.

This original post is quite old and dates from the time I did not know better and how to use Victron MQTT broker to establish a local connection rather then using VRM and be dependent on the internet connection.

Do you need to use VRM because your HA instance is not on the same network as your Victron installation? That is really the only case I can think of for using the API. If that is the case, then I’ll try to dust off my memories and help you as much as I can.

Otherwise please take a look at this post Victron/Fronius off-grid PV Energy Dashboard - MQTT and modbus integration - #32 by lsgv

Let me know.

Danke für die schnelle Antwort :smiling_face_with_three_hearts:

Ich habe die Komponenten im selben Netzwerk. Ich habe auch Werte im mqtt, siehe Screenshot.

Es ist gut erkennbar, dass die MPPT Laderegler arbeiten und im eigenen Netz ein Verbrauch ist.
Am Ende des Tages ist es aber nicht möglich, die Summer der Verbräuche zu lesen.

Ich finde nur etwas von den MPPT Ladern “/solarcharger/277/History/Daily/0/Yield” als Zusammenfassung.
Mein Ziel ist es, eine Auswertung zu bekommen, die die Tages-Ergebnisse zeigt.

Ok then, you can use MQTT. To get daily results you can do the following:

  • If you have not done it yet, create MQTT sensor in HA for whatever power flows you need, production, consumption, etc. using MQTT Sensor - Home Assistant
  • From the power (in Watt or kWatt) sensor create an energy sensor (power x time = energy) using the integration integration Integration - Riemann sum integral - Home Assistant
  • Using this sensor, create a daily Utility Meter using Utility Meter - Home Assistant
  • You can use the same energy sensor in Utility Meter to create daily, weekly, monthly etc. sensors so you can keep historical track of your production/consumption.

Let me know if this is clear or if you need any further help.

Danke für deine Mühe :grinning:

Es ist viel zu lesen.
:thinking:
Ich werde sehr bald daran arbeiten und testen, ob ich es kann. Auf dem ersten Blick, kann ich nicht sagen, ob ich weiter komme. Ich werde es dich wissen lassen.
Gruß Guido

ich habe die 3 Seiten gelesen und ich denke, ich verstehe was es für Arbeit bedeutet. Ich werde es jetzt noch nicht tun. Ein Freund hat mir mein System zusammen gestellt. Ich kann es mir nicht erlauben, da einen Fehler einzubauen. :sneezing_face:
Ich werde einfach am Monatsende, die Daten aus dem VRM Portal per Download nehmen und sie ablegen.

Es sind die Daten, die im Grunde das aussagen, was ich von der Anlage wissen will. Ich dachte, es ginge automatisch.
Ich danke für deine Zeit und Mühe.
Evtl. schaue ich in einiger Zeit noch erneut nach der Lösung… Dazu muss ich sicherer mit dem eigenen System sein.
Gruß Guido