HowTo: Home Assistant + Victron Modbus template sensors for Energy panel

Hi all,
I’ve read stuff over the net and tried to create template sensors from Victron (modbus) sensors that I have, but this is simply not available to be added into the energy panel of HA.

Have an inverter, one mppt and Pylontech bank…I don’t have any current and energy meters, so can this be done without them and how?
If anyone has something like this, please can you post the template or yaml with sensors configuration?

Not 100% clear on what you are looking will try though, I assume you have a GX device if so then its pretty easy to do modbus or mqtt.

Also as I understand a template sensor is for when you want to do something with the data, like add two values, average etc.

For mqtt I use this (the inverter should tell you what power you are using somewhere)

  #Eskom power used
  - platform: mqtt
    name: "Eskom power"
    unit_of_measurement: "W"
    device_class: "power"
    value_template: "{{ value_json.value | round(0) }}"
    state_topic: "N/102xxxxxxxxx/system/0/Ac/Grid/L1/Power"

I then use a Riemann sum integral to go from W to Wh (or kWh) (you can skip this if you can pull a sensor that already is in kWh (like diectrly from et112 carlo gavazzi)

  - platform: integration
    source: sensor.eskom_power
    name: total_eskom_power
    unit_prefix: k
    method: left
    round: 3

Edit: Not sure if you can stop here if the “platform: integration” was added to long term statistics, unsure…

Then finally to have a sensor that ticks all the long term statistics requirements (like last rest date, total increasing etc)

  #eskom power monitor
  daily_eskom_power:
    source: sensor.total_eskom_power
    cycle: daily
  monthly_eskom_power:
    source: sensor.total_eskom_power
    cycle: monthly

Plug that into to energy dashboard and it will start showing what you pull from Eskom, sorry if that’s not 1% what you where looking for

hmm, thank you Dylan…I’ll definitely use the Eskom daily power template from my Home Power Consumption sensor…

The thing is, I don’t know what to do to my modbus sensors so that they appear selectable int he energy option…when I go there, there is nothing available to select



I do have the information available from modbus

There are some other but I’m not using them at the moment…
This is my modbus yaml and I tried adding the “device_class:” but no luck

  - type: tcp
    host: 192.168.1.50
    port: 502
    name: "victron"

    sensors:
      # System
      - name: "Home Power Consumption"
        data_type: uint16
        unit_of_measurement: "W"
        scan_interval: 5
        slave: 100
        address: 817
        scale: 1
        device_class: power
      - name: "Grid Power Victron"
        data_type: int16
        unit_of_measurement: "W"
        scan_interval: 5
        slave: 100
        address: 820
        scale: 1
        device_class: power
      - name: "Inverter Temperature"
        data_type: int16
        unit_of_measurement: "C"
        device_class: temperature
        scan_interval: 60
        slave: 23
        address: 3304
        scale: 0.01


      # Battery
      - name: "Battery voltage"
        data_type: uint16
        unit_of_measurement: "V"
        slave: 100
        address: 840
        scale: 0.1
        device_class: voltage
      - name: "Battery Current Victron"
        data_type: int16
        unit_of_measurement: "A"
        slave: 100
        address: 841
        device_class: current
        scale: 0.1
      - name: "Battery Power Victron"
        data_type: int16
        unit_of_measurement: "W"
        slave: 100
        address: 842
        device_class: power
        scale: 1
      - name: "Battery SoC"
        data_type: uint16
        unit_of_measurement: "%"
        device_class: battery
        slave: 225
        address: 266
        scale: 0.1
      - name: "Victron ESS Minimum SOC"
        data_type: uint16
        slave: 100
        address: 2901
        scale: 0.1
        unit_of_measurement: "%"

      # MPPT Array
      - name: "PV Voltage"
        data_type: int16
        unit_of_measurement: "V"
        slave: 245
        address: 776
        scale: 0.01
        device_class: voltage
      - name: "PV Current"
        data_type: int16
        unit_of_measurement: "A"
        slave: 245
        address: 777
        scale: 0.1
        device_class: current
      - name: "PV Power Victron"
        data_type: uint16
        unit_of_measurement: "W"
        scan_interval: 5
        slave: 100
        address: 850
        device_class: power
        scale: 1
      - name: "PV Yield today"
        data_type: int16
        unit_of_measurement: "kWh"
        slave: 245
        address: 784
        scale: 0.1
        precision: 1
        device_class: energy
      - name: "PV Max power today"
        data_type: int16
        unit_of_measurement: "W"
        slave: 245
        address: 785
        scale: 1
        device_class: power
      - name: "PV Yield yesterday"
        data_type: int16
        unit_of_measurement: "kWh"
        slave: 245
        address: 786
        scale: 0.1
        precision: 1
        device_class: energy
      - name: "PV Max power yesterday"
        data_type: int16
        unit_of_measurement: "W"
        slave: 245
        address: 787
        scale: 1
        device_class: power

Hope I make sense :slight_smile:

Yes makes sense, your sensors you have aren’t “compatible” with long term statistics directly, that’s why you need to 1) use the integral integration (convert power kW to energy kWh) 2) set up the utility meter to start keeping track of the energy and having all the correct attributes.

Your sensor must look like this;

Edit: Add the 1st one under sensor and the second as a new one for utility meter

sensor:
  #total grid power consumed
  - platform: integration
    source: sensor.grid_power_victron
    name: total_grid_power_victron
    unit_prefix: k
    method: left
    #or right or trapezoidal for methods
    round: 3

utility_meter:
  #Grid power monitor
  grid_power_victron:
    source: sensor.total_grid_power_victron
    cycle: daily
  monthly_grid_power_victron:
    source: sensor.total_grid_power_victron
    cycle: monthly
1 Like

done :slight_smile:
Thank you

I created two sensor yaml files as per your advice
and added the sensor under “Electricity grid”

I think now I have to wait for a bit till it populates the data (it does say that :))

Any ideas how do I integrate Victron MPPT and Pylontech?
From what I saw, Victron MPPT does have “Produced yesterday” and “Produced today” info

EDIT: I’ll use the same template for the other sensors - the mppt and the battery one so that should work.
I’ll do it tomorrow and advise :slight_smile:

That error doesn’t look positive, lets give it some time to create long term stats.

Also remember the battery is positive for out negative for in so you need to split those or else I would guess you will only get the difference + losses (use a template sensor for that)

Just to confirm that it is working :slight_smile:

I used your sensor templates and its looks good…
Now hunting the battery templates :slight_smile:

Thank you once more!

1 Like

Have posted it here to split it, let me know if you need any more help

Dylan, I am just not getting this right
Since 3AM I am breaking my brain and just can’t get it right :frowning:

I have tried absolutely everything I possibly could and am now without any ideas

Please help if you can and post your configs and yamls and I’ll try and fit it in

Will do,
Use this from yours

      - name: "Battery Power Victron"
        data_type: int16
        unit_of_measurement: "W"
        slave: 100
        address: 842
        device_class: power

Then use this (have edits to your names), this will split your sensor.battery.power.victron into say

template:
  #Split power in and out of battery
  - sensor:
      - name: "Battery power victron input"
        unit_of_measurement: "W"
        state: >
          {% if states('sensor.battery.power.victron')|float >= 0 %}
            {{ states('sensor.battery.power.victron') }}
          {% else %}
            0
          {% endif %}
      - name: "Battery power victron output"
        unit_of_measurement: "W"
        state: >
          {% if states('sensor.battery.power.victron')|float < 0 %}
            {{ -1 * states('sensor.battery.power.victron')|float }}
          {% else %}
            0
          {% endif %}

With these two new sensors (sensor.battery.power.victron_input and sensor.battery.power.victron_output) as before “Riemann sum integral” and then “Utility meter”

I did all the way to splitting but I don’t see individual sensors, so my first question would be Do I have to split the charge and discharge sensors into two different yaml files?

Tried splitting them and still I can’t see the Battery power victron input or Battery power victron output sensors.
This is bizzare
Sensors from the template are correct and when I go to Developer Tools, they work fine

Lost!

mine is like this;

sensor:
  #Battery power
  - platform: mqtt
    name: "Battery power"
    unit_of_measurement: "W"
    device_class: "power"
    value_template: "{{  value_json.value | round(1) }}"
    state_topic: "N/xxxxxxxxxx/battery/512/Dc/0/Power"

  #total battery input power
  - platform: integration
    source: sensor.battery_input_power
    name: total_battery_input_power
    unit_prefix: k
    method: left
    round: 3
  #total battery output power
  - platform: integration
    source: sensor.battery_output_power
    name: total_battery_output_power
    unit_prefix: k
    method: left
    round: 3


template:
  #Split power in and out of battery
  - sensor:
      - name: "Battery input power"
        unit_of_measurement: "W"
        state: >
          {% if states('sensor.battery_power')|float >= 0 %}
            {{ states('sensor.battery_power') }}
          {% else %}
            0
          {% endif %}
      - name: "Battery output power"
        unit_of_measurement: "W"
        state: >
          {% if states('sensor.battery_power')|float < 0 %}
            {{ -1 * states('sensor.battery_power')|float }}
          {% else %}
            0
          {% endif %}


utility_meter:
  #total battery input power
  daily_battery_input_power:
    source: sensor.total_battery_input_power
    cycle: daily
  monthly_battery_input_power:
    source: sensor.total_battery_input_power
    cycle: monthly

  #total battery output power
  daily_battery_output_power:
    source: sensor.total_battery_output_power
    cycle: daily
  monthly_battery_output_power:
    source: sensor.total_battery_output_power
    cycle: monthly

image