Victron Multiplus2 with battery on Energy Dashboard

Hey Everyone,
As the title suggests I have a Victron Multiplus 2 with a lead acid battery bank setup. I have used Modbus to integrate all of the data from this and also have a Fronius Primo 5.0 AC coupled.

My question is how has anyone else managed to get the battery discharge rate/amount into the Energy Dashboard?
I have used register 842 which gives a positive and a negative number depending on if the battery is charging or discharging. But how do I use this with the dashboard? From what I can see you need two separate sensors. Or am I missing something?

I have the following slaves-:
com.victronenergy.grid slave: 30
com.victronenergy.system slave: 100
Fronius primo pv inverter slave: 20

Everything else seems to work like a charm but cant get the battery figures right.

Any ideas would be great.

Cheers

Maybe this helps: Fronius Integration into Energy dashboard - #19 by farmio

Hey @farmio,
Thanks yes I have looked at that post but still cant figure out the data flow out of the battery.

Got the charging data all good but not the load data when using the battery.

Cheers

What states Open your Home Assistant instance and show your state developer tools. does your entity have? And what did you try now?

Is this what you are asking? Sorry I am not very experienced with HA or code but try my best.

sensor.battery_current
Battery current
22	unit_of_measurement: A DC
device_class: current
friendly_name: Battery current

sensor.battery_power_system
Battery Power System
1272	unit_of_measurement: W
device_class: power

friendly_name: Battery Power System
sensor.battery_state_of_charge_system
Battery State of Charge System
88	unit_of_measurement: %

friendly_name: Battery State of Charge System
sensor.energy_into_battery
Energy_into_battery
1.40	state_class: total
source: sensor.battery_power_system
unit_of_measurement: kWh
device_class: energy
icon: mdi:chart-histogram

friendly_name: Energy_into_battery
sensor.energy_out_of_battery
Energy_out_of_battery
unknown	state_class: total
source: sensor.charge_power_system
icon: mdi:chart-histogram
friendly_name: Energy_out_of_battery

Sorry it doesnt display very well on here.

It seems I am not getting the data for charge power but I have a feeling thats when the battery is getting charged from the grid not how I thought the slave address meant discharging…

Has unknown state. How is this set up? A Riemann sum integration? Paste the yaml.

(Screenshots work quite well for the states page :wink:)

Yes thats right, this is it along with one that works fine

sensor:

# Sensors for energy dashboard
  - platform: integration
    source: sensor.battery_power_system
    name: Energy_into_battery
    unit_prefix: k
    round: 2

  - platform: integration
    source: sensor.charge_power_system
    name: Energy_out_of_battery
    unit_prefix: k
    round: 2

and heres the modbus sensors

 - name: 'Battery Power System'    # Appears to give + and - charge/discharge power in watts
        unit_of_measurement: "W"
        slave: 100
        address: 842
        data_type: int16
        scale: 1.0
        precision: 0
        device_class: power
 
      - name: 'Charge Power System'
        unit_of_measurement: "W"
        slave: 100
        address: 860
        data_type: int16
        scale: 1.0
        precision: 0
        device_class: power

I don’t know your device at all, are you sure the ‘Charge Power System’ entity provides Watts charged to the battery - when the former entity already does with positive/negative values? Maybe it’s some kind of car-charge function.

Have a look at the linked post in my first answer again about how to split positive/negative charging power values into 2 template entities and use them with integration.

Ah, yes I see what you mean now. That post looks like its exactly what I can do with my sensor thats goes + and -.
Thanks I will give it a go when I get home. Cheers

Hi, OK So this is what I have done, adapted from the post you showed me

sensor:

# Sensors for energy dashboard
  - platform: template
    sensors:
      battery_discharge_power:
        device_class: power
        friendly_name: "Battery Discharge"
        unit_of_measurement: "W"
        value_template: "{{ max(0, 0 - states('sensor.battery_power_system') | float) }}"

      battery_charge_power:
        device_class: power
        friendly_name: "Battery Charge"
        unit_of_measurement: "W"
        value_template: "{{ max(0, states('sensor.battery_power_system') | float) }}"
        
  - platform: integration
    source: sensor.battery_charge_power
    name: Battery Charge
    unit_prefix: k
    round: 2

  - platform: integration
    source: sensor.battery_discharge_power
    name: Battery Discharge
    unit_prefix: k
    round: 2

Now when I go to setup the battery in the Energy Dashboard I only see ‘Battery Discharge’ and No ‘Battery Charge’

Any ideas what I have done wrong? It think I changed the code correctly…

Not sure. Does the battery_charge already have a value? Maybe it has to be >0 but doesn’t charge over night?
What does the developer-Tools → states page say?

Yes it did when it was daytime and now its night the battery_discharge_power is showing a value that is correct.

I cant work out why I dont have the ability to select the battery charge in the energy dashboard, really weird.

Device_class and state_class is the same for charge and discharge? The battery_charge entity is not visible on the screenshot.

Sorry, I dont understand what you mean by that?


Do you mean the top one in this list? Where does that come from, I have not set this up in my config?
Sorry I am really confused with this.

its the one you are looking for, but has the wrong unit_of_measurement (% instead of kWh) - probably because you tried to do the integration (riemann) from a wrong entity first. I don’t know how to correct this - maybe just delete it and try new.
It comes from here:

the name key will be sluggified and used as entity name. Same for the sensor.battery_discharge entity.

Ah I see, well I think I do so far… Thats weird that sensor had % and not kWh. So I deleted that one and added a new one which I think cured it. Also had to swap around the 0 - in the value_template. Heres what I now have in developer tools.


and in config

# Sensors for energy dashboard
  - platform: template
    sensors:
      battery_discharge_power:
        device_class: power
        friendly_name: "Battery Discharge"
        unit_of_measurement: "W"
        value_template: "{{ max(0, 0 - states('sensor.battery_power_system') | float) }}"

      battery_charge_power:
        device_class: power
        friendly_name: "Battery Charge"
        unit_of_measurement: "W"
        value_template: "{{ max(0, states('sensor.battery_power_system') | float) }}"
        
  - platform: integration
    source: sensor.battery_charge_power
    name: Energy_into_battery
    unit_prefix: k
    round: 2

  - platform: integration
    source: sensor.battery_discharge_power
    name: Battery Discharge
    unit_prefix: k
    round: 2

and now this shows up in energy config


Will now wait and see what comes up in the energy desktop in a few hours!

Also, thanks for all your work on the Fronius intergration, its a great help to everyone with a Fronius unit.
My next project is to figure out a way of dumping excess energy into a hot water element but being able to limit the load to how much spare solar energy we have. Sort of like a load controller.

1 Like

Just trying to get this working also - have HA happy with the code and it is collecting values as seen in the states below, but when adding to the energy config I can only see the charge sensor and not the discharge.

It all looks ok to me, any ideas on what I’m missing?

EDIT: SOLVED! Discovered in the Developer Tools > Statistics that the sensor had a value mismatch. Hit fix error to change the data to the correct measurement and now I can see it in energy config.

sensor:
    - platform: integration
      source: sensor.zcell_discharge_power
      name: ZCell Battery Discharge
      unit_prefix: k
      round: 2

    - platform: integration
      source: sensor.zcell_charge_power
      name: ZCell Battery Charge
      unit_prefix: k
      round: 2

template:
  - sensor:
      - name: "zcell_discharge_power"
        unique_id: sensortemplate.batterydischarge
        device_class: power
        unit_of_measurement: "W"
        state: "{{ max(0, 0 - states('sensor.multiplus_zcell_power') | float) }}"

      - name: "zcell_charge_power"
        unique_id: sensortemplate.batterycharge
        device_class: power
        unit_of_measurement: "W"
        state: "{{ max(0, states('sensor.multiplus_zcell_power') | float) }}"

I guess you also have grid, do you have 3 phase grid system and a meter ? If so could you share your modbus configuration for the grid i mean which registers are you reading to get grid in correctly especially when there is 3 phases.

Hi, Sorry for slow response. Have been fighting the bug.

Yes I am grid tied with 3 phase and use the Victron ET340 meter.

Heres my Modbus settings, hope it helps.

################################
# Victron Solar Modbus Devices #
################################
# com.victronenergy.grid    slave: 30
# com.victronenergy.system  slave: 100
# fronius primo pv inverter slave: 20

modbus:
  - name: victron
    retry_on_empty: true
    retries: 10
    type: tcp
    host: 192.168.1.206
    port: 502
    
    sensors:
      - name: 'AC Consumption L1'
        unit_of_measurement: "W"
        slave: 100
        address: 817
        data_type: uint16
        scan_interval: 3
        device_class: power
    
      - name: 'Multiplus Grid power'
        unit_of_measurement: "W"
        slave: 100
        address: 820
        data_type: int16
        scan_interval: 3
        device_class: power
        
      - name: 'Multiplus Energy from Grid'
        unit_of_measurement: "kWh"
        slave: 30
        address: 2603
        data_type: uint16
        scale: 0.01
        precision: 1
        scan_interval: 20
        device_class: energy
        state_class: total_increasing
        
      - name: 'L2 Energy from Grid'
        unit_of_measurement: "kWh"
        slave: 30
        address: 2604
        data_type: uint16
        scale: 0.01
        precision: 1
        scan_interval: 20
        device_class: energy
        state_class: total_increasing
        
      - name: 'L3 Energy from Grid'
        unit_of_measurement: "kWh"
        slave: 30
        address: 2605
        data_type: uint16
        scale: 0.01
        precision: 1
        scan_interval: 20
        device_class: energy
        state_class: total_increasing
    
      - name: 'Multiplus Energy to Grid'
        unit_of_measurement: "kWh"
        slave: 30
        address: 2606
        data_type: uint16
        scale: 0.01
        precision: 1
        scan_interval: 20
        device_class: energy
        state_class: total_increasing
    
      - name: 'Fronius Solar power'
        unit_of_measurement: "W"
        slave: 100
        address: 850
        data_type: uint16
        device_class: power
# Battery        
      - name: 'Battery current'
        unit_of_measurement: "A DC"
        slave: 100
        address: 841
        data_type: int16
        scale: 0.1
        precision: 0
        device_class: current

      - name: 'Battery Power System'    # Appears to give + and - charge power in watts
        unit_of_measurement: "W"
        slave: 100
        address: 842
        data_type: int16
        scale: 1.0
        precision: 0
        device_class: power
 
      - name: 'Battery State of Charge System'
        unit_of_measurement: "%"
        slave: 100
        address: 843
        data_type: uint16
        scale: 1
        precision: 0
         
    
    
      - name: Grid Power L1
        unit_of_measurement: "W"
        slave: 30
        address: 2600

      - name: Grid Voltage L1
        unit_of_measurement: "Vac"
        slave: 30
        address: 2616
        scale: 0.1
        
      - name: Grid Current L1
        unit_of_measurement: "A"
        slave: 30
        address: 2617
        scale: 0.1 
        precision: 2
        
      - name: Grid Power L2
        unit_of_measurement: "W"
        slave: 30
        address: 2601
        
      - name: Grid Voltage L2
        unit_of_measurement: "Vac"
        slave: 30
        address: 2618
        scale: 0.1
        
      - name: Grid Current L2
        unit_of_measurement: "A"
        slave: 30
        address: 2619
        scale: 0.1
        precision: 2
        
      - name: Grid Power L3
        unit_of_measurement: "W"
        slave: 30
        address: 2602
        
      - name: Grid Voltage L3
        unit_of_measurement: "Vac"
        slave: 30
        address: 2620
        scale: 0.1
        
      - name: Grid Current L3
        unit_of_measurement: "A"
        slave: 30
        address: 2621
        scale: 0.1
        precision: 2
        
      - name: Inverter Power Output
        unit_of_measurement: "W"
        slave: 20
        address: 1029
        precision: 2
        
      - name: Grid L1 Energy From Grid
        unit_of_measurement: "kWh"
        slave: 30
        address: 2603
        scale: 0.1
        precision: 2
        
      - name: L1 Energy Forward
        unit_of_measurement: "kWh"
        slave: 20
        count: 2
        data_type: uint32
        address: 1046
        device_class: energy
        scan_interval: 10

hola estoy intentando usar su pntilla para crear los sensores de mis baterias para luegousarlos con la suma de riemman tengo un fronius 24 gen i un smart meter cuando creo la plantilla me sale este error
ValueError: Template error: float got invalid input ‘unknown’ when rendering template '- platform: template
podria orientarme a que es devido no tengo mucha experiencia en esto gracias