question

Matt Knight avatar image
Matt Knight asked

Home Assistant integration with Victron

I'm a big fan of the open nature of Victron's platform - both the API and the data itself. We've been using this to great effect in our RV, using the rich, real-time data from our Victron CCGX not just for monitoring but also to integrate into our home automation system.

One such use case is bringing the data into Home Assistant. I'm using MQTT via an intermediary MQTT broker so that I can have multiple consumers without increasing the load on the CCGX itself. This has been running flawlessly for almost 2 years now.

Here's an example of the data I'm pulling into Home Assistant and how it appears:

The real power, however, comes from not just displaying the data but using it to make physical changes via automations.

For example, most of the time we have our inverter turned off due to the background power draw which is significant in our modest RV setup (600W solar + 300Ah lithium batteries). When dry camping and all our power is coming from solar, we have it set up to automatically turn on the inverter when the batteries hit 90%. The fridge switches from propane to AC at 95%, and at 98% the electric water heater turns on. There is hysteresis configured to turn each toggle off at lower SoCs too.

We're planning to spend this winter in a very cold climate (northern Vermont where temperatures could reach 0°F). Our RV has a 30A main breaker, which is easily exceeded if we run too many appliances - e.g. water heater, space heater, Instant Pot. I'm planning another automation which will automatically and temporarily turn off the water heater and / or space heater if we're at risk of exceeding the capacity of either our main breaker or MultiPlus output (computed in real-time based on shore power connectivity).

Having the data from the Victron system integrated alongside the data from our other home automation system (10+ environmental sensors, contact sensors, GPS, lights, appliances, media, networking data etc) is an incredibly powerful platform that is helping to make our RV more secure, more efficient and most importantly, more comfortable for us to live in.

As I said earlier, the Victron data is being ingested via MQTT but I'm hoping to find some time this winter to work on a native integration with Home Assistant. If anyone from Victron is interested in being involved in that process, please let me know!

Again, hope this inspires people with a few ideas, and thank you again to the team at Victron for making all this possible!

Assistants
10 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Would you be open to posting some of the configuration.yaml you used for setting up sensors via HomeAssistant?

1 Like 1 ·

@Matt Knight : I would love to get data from Victron into my Home Assistant through HAs MQTT broker, but i cant seem to figoure out how. Do you have a guide or something that shows how you have done this ?

0 Likes 0 ·

@Matt Knight Great work! Can you please share your config-files?

0 Likes 0 ·

@erik_aslaksen

This is quite easy if you have Home Assistant (HA) running on the same network as your Victron CCGX. I use the Modbus capability instead of MQTT, since it is more direct.

  • Enable Modbus on the CCGX (Menu -> Settings -> Services -> Modbus TCP = Enabled
  • Add "modbus: !include modbus.yaml" to configuration.yaml (in HA).
  • Create the file modbus.yaml and add items similar to the following:
# modbus:
  - name: victron
    type: tcp
    host: 192.168.xx.xx  # use the IP address of your CCGX
    port: 502
    sensors:
      - name: "Grid Power"
        scan_interval: 10
        unit_of_measurement: "W"
        slave: 100
        address: 820

      - name: "PV Power"
        scan_interval: 10
        unit_of_measurement: "W"
        slave: 100
        address: 850

      - name: "AC Loads"
        scan_interval: 10
        unit_of_measurement: "W"
        slave: 100
        address: 817

      - name: "Inverter State"
        scan_interval: 10
        slave: 246
        address: 31 

      - name: "ESS State"
        scan_interval: 10
        slave: 100
        address: 2900

The modbus slave and address values may need to be adjusted to suit the equipment you have in your system - see the "Modbus TCP Register List" spreadsheet at this link: Technical information

  • The modbus sensors, defined in modbus.yaml, will then appear as regular sensors in HA (e.g. sensor.grid_power, sensor.ac_loads). You can then customise the icons for each sensor etc.
1 Like 1 ·

Hi, do you have any idea how to make the Victron sensors useful in the new Energy dashboard which Home Assistant now launched?

I think the modbus integration does not expose the "state_class" attribute on sensors, which is required by the Energy dashboard in order to use them (as described here: https://www.home-assistant.io/more-info/statistics/)

I tried adding the state_class in the sensor configuration but the configuration is invalid. Any other way to expose Victron info to HA so that it's usable in the Energy dashboard?


0 Likes 0 ·

Yea, i played with this for a while, and finally got it working...

Here is an example of a few Energy Integrations i have set up in my sensors.yaml after my Sensors and Sensor templates...

I have also included example of sensor template, for defining + or - energy flow from one sensor.

After you have set these up, they should show up in the drop down lists in the energy setup.

#TEMPLATES
  - platform: template
    sensors:
      energy_from_grid:
        friendly_name: "Energy spent from Grid"
        device_class: energy
        value_template: >-
          {% set value = (('%1f' | format(states('sensor.energy_gridW') | int)) | int) %}
          {% if value > 0 -%}
            {
  { value | abs}}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: "W"

#ENERGY INTEGRATIONS
  - platform: integration
    source: sensor.energy_from_grid
    name: energy_spent
    unit_prefix: k
    round: 2
    
  - platform: integration
    source: sensor.energy_to_grid
    name: energy_earned
    unit_prefix: k
    round: 2
    
  - platform: integration
    source: sensor.energy_shedpvw
    name: e_ShedPV
    unit_prefix: k
    round: 2
    
0 Likes 0 ·
Thank you for this! Especially useful the template config to handle negative/positive values meaning to/from grid.

Got mine reasonably working, but I think a native integration with Home Assistant would be great. I'm pondering building one myself but i don't like using modbus as i could not find an enough easy to use modbus client software to be able to test operations besides configuring in HA and restarting. So.. side-question here: does anyone know a reasonably simple and good modbus windows app for doing such tests/exercises?


0 Likes 0 ·

Any update on this project? I’m currently also using home assistant with a Victron installation.

I found it easier to work with mqtt instead of modbus and also the update rate on mqtt is higher then on modbus in HA

0 Likes 0 ·
Are there any news on an official HA integration?
0 Likes 0 ·
Das würde mich auch interessieren.

Das ist mir alles zu hoch, ich brauch eine normale HA Integration! Zahle gerne dafür. :p


0 Likes 0 ·
11 Answers
mvader (Victron Energy) avatar image
mvader (Victron Energy) answered ·

Hey @Matt Knight, very interesting! I'm interested in being involved - mainly to help where I can to give tips and tricks of what we'd think is the best approach.

Not so much - I'm afraid - in actual developing.

One thing thats good for you to be aware of is this: https://www.victronenergy.com/live/venus-os:extended.

And otherwise, sounds very promising, Home Assistant. I'm not too familiar with it right now I'm afraid; too little time to play with anything outside direct Victron eco-system :).

10 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Looks very interesting - I'll have to read up more on that. I will say I've been using NodeRED very successfully in my setup for a while, but it's got to the point where Home Assistant can do so much of what I need that I'm able to pull some of the more complex logic back out of NodeRED and put it in Home Assistant.

Home Assistant is great, and it'd be great to see Victron amongst the 1,685 integrations they already have! https://www.home-assistant.io/integrations/

I'm happy to do the development - it's just Python, so nice and accessible.

Where some Victron support would be appreciated would be on any best practices for interacting with the Victron GX system. I'm sure I'll discover uncertainties as I go, but for example:

Would MQTT or modbus TCP be the preferred architectural integration for the Victron? Python & Home Assistant can (and do) happily support both.

0 Likes 0 ·

Hi again, yes Home Assistant looks *much* more accessible than Node-RED does.

MQTT vs ModbusTCP: good question. I guess both work for us. MQTT allows the option to implement some sort of security - though we don't currently do that for the MQTT on LAN option.

Both have a CPU penalty when enabled (catching all the D-Bus signal changes).

MQTT is "closer" to the internal databus we use (D-Bus), since there is a one on one mapping between MQTT topics and D-Bus paths [1]. But the disadvantage is that we might change path now and then, which for MQTT is then too bad - any application using it will have to adopt.

Whereas for ModbusTCP we'll make more efforts in keeping it stable.

D-Bus paths, and therewith MQTT topics, won't change often though, a lot things break also internally for us in case we change one.

I'll think about it a bit more - but currently I don't see a clear winner for the Home Assistant application.


[1] https://github.com/victronenergy/dbus-mqtt

0 Likes 0 ·

Any progress to integrate Victron to Home Assistant?

0 Likes 0 ·

I am soooo looking forward to see Victron integration to Home assistant.

Any progress?

0 Likes 0 ·

Have the same wishes!
Yes the Modbus and the MQTT are pretty easy, but you have to manually configure every sensor.

Would be way easier with an integration, so the sensors are directly seen.

So hope this is going to happen!

1 Like 1 ·

Using modbus is dead easy, once you get your head around the syntax needed.

Works like a charm in home assistant.


0 Likes 0 ·

Thanks @nickdb . Ill have a look at it. The advantage mqtt have is that i can have other clients connected to the HA´s MQTT broker. Also, as far as i understand you manually have to add each device to HA if you use modbus ?

Will Victron also forward device data on the nmea2000 network into modbus ?

0 Likes 0 ·

@Matt Knight would you will willing to share you HA config that produces the screen shot you shared?

0 Likes 0 ·

Wouldn’t it be possible to run both Venus OS and Home Assistant on the ‘same’ Pi making it easy to integrate into HA.

0 Likes 0 ·

+1 interested in a HA Add-on and Integration

0 Likes 0 ·
fenix avatar image
fenix answered ·

How do we define Unique Id

2 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Are you referring to the device ID used in the MQTT paths? If so there is no UUID currently but there has been mention that victron will be moving to some kind of UUID to reference the device

0 Likes 0 ·
hummingbear avatar image
hummingbear answered ·

I didn't know about home assistant until I read this post and I'm fascinated. I've been editing the venus html react app to give me a sudo dashboard to monitor my power and also toggle some custom relays and wifi outlets I have setup. There is some additional logic i've wanted to build out and was going to use NodeRed but it sounds like HA might be a bit more friendly.

I'm curious how you're using MQTT via an intermediary MQTT broker and connecting that to HA? Could you or do you already have a place where you can share how you've setup your current integrations? I'm a developer and would be glad to pair on getting some integrations built out for Victron. One thing I would love to see is a UUID for devices as the device IDs can change and I've had issues with that.


My dashboard below:

1607966149876.png

1607966169456.png


1607966149876.png (111.0 KiB)
1607966169456.png (96.6 KiB)
1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

how did you edit the HTML5 app, is there any tutorial?
0 Likes 0 ·
David Borg avatar image
David Borg answered ·

There were this Youtube video from Victron https://www.youtube.com/watch?v=9vDSRh6rmis

But no exemple or instructions how to make it?
Cant find any other information either?

For us that dont know modbus, mqtt, node-red, python.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Stephen Kunkel avatar image
Stephen Kunkel answered ·

I saw this post while searching as a noob to all of this. I found this blog from a European gentleman that helped me succeed in setting up a nice dashboard for my "V" things. Felt like sharing with all the other noobs that don't have time for courses in coding/automation but have a requirement with a low budget. https://www.imval.tech/index.php/blog/add-your-victron-system-in-home-assistant#comments

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

wittyhat avatar image
wittyhat answered ·

Just wanted to add that I put together a detailed overview of how to integrate victron energy management (via Cerbo GX) into home assistant, on a boat, here:

https://boathackers.com/boat-energy-management-using-victron-and-home-assistant/

9 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

That's a nice setup you have there. :)

You are supplying data to the home assistant energy distribution dashboard but I don't see in your configuration where you are pulling the data via modbus to feed into it. Can you elaborate on what you have set up for that?

0 Likes 0 ·

yeah i noticed that too and have same question.....

@wittyhat maybe you could let us know how you did that or even share the homeassistant code ?

0 Likes 0 ·
I'm confused about what you're asking for. The entire post is a step by step guide to how to get the data, including all code and configuration for homeassistant?
0 Likes 0 ·
@wittyhat on your hass dashboard you have the new energy dashboard showing power from PV, grid and battery. which of the sensors have you used for the energy dashboard ?
0 Likes 0 ·

Oh I see, sorry for misunderstanding! You can convert Modbus sensors to integration sensors to calculate energy values which can be ingested by Home Assistant energy-management features. I'll probably do a 2nd post about this, but here's an example of taking the "solar_power" modbus sensor and creating a new "solar_energy" sensor based on it:



- platform: integration

source: sensor.solar_power

name: Solar energy

unit_prefix: k

unit_time: h

method: left

round: 2

0 Likes 0 ·
In the case of victrons solarchargers they already reports its total lifetime yield which I believe is more suitable since it should be more exact and will keep tickdng when home assistant isn't running.


Not that the integrating sensor isn't a great thing! It's good if there's no other option.


0 Likes 0 ·
Cool, that will be a good example for me to start.

By the way, how did you make the distribution graph (energy flow diagram)?

I thought I may use a web-page card to show the native local victron console, but yours looks so stylish ;)

0 Likes 0 ·

It is the standard energy card in home assistant:

type: energy-distribution
link_dashboard: true
1 Like 1 ·
Nice, didn't know that this was already build in. Will try once I made the ModBus config.
0 Likes 0 ·
sesshoumaru avatar image
sesshoumaru answered ·

Once my home assistant is set up I also would like to integrate my Quattro II + Pylontech system into it. I know there is docker grafana ( https://github.com/victronenergy/venus-docker-grafana ) but Home Assistant also uses Grafana with influxDB to record its states. Would be a waste to have it twice.


Would really be a great thing if somebody, maybe even victron, provide a custom component for home assistant. Thats the future and all the automation possibilities would be greatly appreciated.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

ajm avatar image
ajm answered ·

@Matt Knight do you perhaps have any info regarding an official HA integration I see you have done cool things would be great to have a chat.I recently started using modbus.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

sesshoumaru avatar image
sesshoumaru answered ·

How is the "preferred" way to integrate Victon in 2022 with HA?
Are there works on an integration? Over ModbusTCP? Over MQTT?


My system is finally up and I would like to integrate now with HA :)

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

dylan-hyslop avatar image
dylan-hyslop answered ·

Just to bump up this thread, I was also very disappointed to not see a Victron integration on the Home Assistant website, A lot of victron's competitors etc are all there.

Has anyone found a step by step instruction on how to do the integration via modbus?


2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Juha Tuomala avatar image
Juha Tuomala answered ·

Correct if I'm wrong, but there is no Home Assistant topic in this forum? Who could make it happen?

2 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

There are plenty of topics about home assistant. You are welcome to open your own.

I suspect something is being lost in translation.

Just search for it..

1 Like 1 ·
I meant this forum topic, it's a technical concept in this software. It helps to follow topics that you select.
0 Likes 0 ·