Modbus sensor to support state_class

A popular solar equipment company is Victron Energy and currently it integrates with Home Assistant through modbus interface.
Would be great to be able to use the sensors and measurements from Victron in the new Energy dashboard, but that is not posisble as the modbus sensors cannot have the state_class attribute to them, which makes them invisible for the Energy dashboard configuration.
Assuming this is all what would be needed in order to expose such sensors to the Energy dashboard, can this attribute be added for modbus sensors? Or to create a platform “solar” for modbus… maybe?

Sample configuration which can be done now, but not usable in Energy dashboard:

modbus:
  - type: tcp
    name: victron
    host: 192.168.xx.xxx
    port: 502

# Victron Energy Venus GX Solar Power data
    sensors:
      - name: Grid power
        unit_of_measurement: "W"
        slave: 100
        address: 820
        device_class: power

      - name: Power consumption
        unit_of_measurement: "W"
        slave: 100
        address: 817
        device_class: power

See Ability to set state_class on modbus sensor

Hey @raresv
Have you managed to get anywhere with this? I use Victron Multiplus II (with battery bank) and a fronius primo inverter. I also get all the info into HA but I can not figure my way through getting the sensors to show up in the energy dashboard.
Unfortunately I am no pro at HA…

Thanks

You can configure eg. state_class: "total_increasing" in the Modbus sensor yaml config with next release (2021.9 - currently in beta). It will be selectable then.

Remember, contrary to the initial post here, you need energy values (Wh), not power (W).

Also you can just use the Fronius integration to get your inverters data into HA. It will be compatible with the energy tab out of the box.

1 Like

Hi, Thanks for the reply. The next release looks promising then.

So are you saying until the next release it cant be done?

Here’s what I have tried so far, but am no expert.

################################
# Victron Solar Modbus Devices #
################################
modbus:
  - name: victron
    type: tcp
    host: 192.168.1.206
    port: 502
    sensors:
      - name: Inverter Power Output
        unit_of_measurement: "W"
        slave: 20
        count: 2
        data_type: uint16
        address: 1029
        scan_interval: 10
        
      - name: L1 Energy Forward
        unit_of_measurement: "kWh"
        slave: 20
        count: 2
        data_type: uint32
        address: 1046
        device_class: energy
        scan_interval: 10

Thanks for the tip on the Fronius but I was kind of hoping that as all the Fronius data gets put through the Victron Modbus, I would just use that but its an option.
Thanks

No, you could use customize but imho you are leaving non-HA-expert territory then. I’d rather go install beta 2021.9 if you can’t wait until Wednesday.
You’d also have to revert this again after doing the update then.

1 Like

I’d rather go install beta 2021.9 if you can’t wait until Wednesday.

Hmmm, think I will wait. Thanks for the info

Just trying it out now. I used to pull mostly the power metrics, not energy… so now I need to pull those also. But it seems to work. Will update here when i get it reasonably working, but the fact we can now (with the september udpate) set the state_class on modbus sensors… is great

Yes thats great news, I am no expert in HA and am a bit lost at the moment.
Let us know how you get it working if you dont mind?

Cheers

Anyone have success as yet ? I’m keen to give it a go

i failed, could you post your example file

I do successfully use the external power meter over the CGGX device for the energy dashboard.

Here the modbus configuration:

    - 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: '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

Thanks for this.
I tried this and I can’t use the sensors because they are “unavailable” - when I check the reason for this - they do not have a unique id. Did you encounter this problem and how did you get around it?

Do you have this error only with the two energy sensors or with all of them? Seems rather to be an issue with your Modbus config in general then the two sensors. Unique entity_id’s are created by the integration and can’t be influenced.

Awesome!

added the script.
I guess it takes at lest 1 hour to update any values?! At least no any errors and other energy values comes from CGGX,

I’ve got similar setup and using modbus to get data to Hass.

Thanx!

@lucode i have a 3 phased meter so i read 2603-2605 for consumption so i made 3 sensors like yours and 3 for energy to grid 2606-2608 :

    - name: "Energy from Grid L1"    
      unit_of_measurement: "kWh"
      slave: 40
      address: 2603
      data_type: uint16
      scale: 0.01
      precision: 1
      scan_interval: 20
      device_class: energy
      state_class: total_increasing
    - name: "Energy from Grid L2"    
      unit_of_measurement: "kWh"
      slave: 40
      address: 2604
      data_type: uint16
      scale: 0.01
      precision: 1
      scan_interval: 20
      device_class: energy
      state_class: total_increasing
    - name: "Energy from Grid L3"    
      unit_of_measurement: "kWh"
      slave: 40
      address: 2605
      data_type: uint16
      scale: 0.01
      precision: 1
      scan_interval: 20
      device_class: energy
      state_class: total_increasing
    - name: 'Energy to Grid L1'
      unit_of_measurement: "kWh"
      slave: 40
      address: 2606
      data_type: uint16
      scale: 0.01
      precision: 1
      scan_interval: 20
      device_class: energy
      state_class: total_increasing
    - name: 'Energy to Grid L2'
      unit_of_measurement: "kWh"
      slave: 40
      address: 2607
      data_type: uint16
      scale: 0.01
      precision: 1
      scan_interval: 20
      device_class: energy
      state_class: total_increasing
    - name: 'Energy to Grid L3'
      unit_of_measurement: "kWh"
      slave: 40
      address: 2608
      data_type: uint16
      scale: 0.01
      precision: 1
      scan_interval: 20
      device_class: energy
      state_class: total_increasing

and i added the 3 sensors (from grid) as Sources in HA and the other 3 to return to grid, is that correct way to do it ?

I don’t have 3 phases, but it seems correct.