Energy dashboard doesn't sums up at the same Grid in and Grid out

Hi,
I have energy meter in my installation (3 phases) that gives me values for L1, L2 and L3. The numbers are positive when I buy energy and negative when I sell energy. I have therefore made new sensors based on these so I have L1_From_Grid, L2_From_Grid and L3_From_Grid also I made 3 similar sensor for the negative values , L1_To_Grid, L2_To_Grid and L3_To_Grid. I have added these 6 sensors to the energy dashboard, all good so far.

The issue is that my Utility meter from the utility company sums things up meaning that if i deliver 1kWh on L1 and consume 1kWh (at the same time) on L2 the sum consumed from the grid is 0kWh therefore it’s important to sum things at the same time to get the overall picture. What I see now on energy dash board is for example how much I exported and how much i imported separately where this is misleading and is not correct in my case. How can I fix this ?

/donnib

I’d suggest to create 2 template sensors, 1 for import and 1 for export, which each only show a value when the sum of the 3 is positive (import) and negative (export) respectvely.

So something like this:

    - name: "Power Export"
      unique_id: power_export
      unit_of_measurement: 'W'
      state: >
        {% if (((states('sensor.L1') | float(0)) + (states('sensor.L2') | float(0)) + (states('sensor.L3') | float(0))) < 0) %}
          {{(states('sensor.L1') | float(0)) + (states('sensor.L2') | float(0)) + (states('sensor.L3') | float(0))}}
        {% else %}
          0
        {% endif %}

    - name: "Power Import"
      unique_id: power_import
      unit_of_measurement: 'W'
      state: >
        {% if (((states('sensor.L1') | float(0)) + (states('sensor.L2') | float(0)) + (states('sensor.L3') | float(0))) > 0) %}
          {{(states('sensor.L1') | float(0)) + (states('sensor.L2') | float(0)) + (states('sensor.L3') | float(0))}}
        {% else %}
          0
        {% endif %}

Where ‘sensor.L1’ to L3 stand for the sensors which you get from your meter directly. In this case you would end up with 2 sensors which you could use in the energy dashboard directly. The result should be the same as your energy company then.

Thank you for your reply. I was thinking to do that but why would that solve the problem? The important part is that when the sum is done its done on instantaneous data for example the sum is not 0kwh if i use 1kwh now and then 5min later export 1kwh. The sum in this case is that i exported 1kwh and imported one 1kwh so i have to pay for that 1kwh and get payed for the 1kwh I exported and this is what i want to see, obviously the import is at one price and export is at another price (something that can’t be specified in hass). Right now hass looks at totals so if i exported during today 5kwh in the morning but in the afternoon i imported 5kwh it thinks i dont have to pay but thats wrong.

The important thing actually is to understand what sensors upper meter gives you in Homeassistant. I assumed the L1 through L3 sensors would be the current values in W, not kWh. If this is not the case I need to rethink.
What integration are you using to get the sensors in Homeassistant? Let’s start there, and maybe you can list the sensors with their unit of measurement.

The sensors are pulled in using modbus and they are indeed in W :

 -  name: victron
    retry_on_empty: true
    retries: 10
    type: tcp
    host: 10.10.0.85
    port: 502
    sensors:
    - name: 'Grid L1'
      unit_of_measurement: "W"
      slave: 40
      address: 2600
      data_type: int16
      scale: 1.0
      precision: 0
      scan_interval: 20
      device_class: power
    - name: 'Grid L2'
      unit_of_measurement: "W"
      slave: 40
      address: 2601
      data_type: int16
      scale: 1.0
      precision: 0
      scan_interval: 20
      device_class: power
    - name: 'Grid L3'
      unit_of_measurement: "W"
      slave: 40
      address: 2602
      data_type: int16
      scale: 1.0
      precision: 0
      scan_interval: 20
      device_class: power

and the corresponding template sensors :

    to_grid_l1_power:
      device_class: power
      friendly_name: "Energy to grid L1"
      unit_of_measurement: "W"
      value_template: "{{ max(0, 0 - states('sensor.grid_l1') | float) }}"
    to_grid_l2_power:
      device_class: power
      friendly_name: "Energy to grid L2"
      unit_of_measurement: "W"
      value_template: "{{ max(0, 0 - states('sensor.grid_l2') | float) }}"
    to_grid_l3_power:
      device_class: power
      friendly_name: "Energy to grid L3"
      unit_of_measurement: "W"
      value_template: "{{ max(0, 0 - states('sensor.grid_l3') | float) }}"
    from_grid_l1_power:
      device_class: power
      friendly_name: "Energy from grid L1"
      unit_of_measurement: "W"
      value_template: "{{ max(0, states('sensor.grid_l1') | float) }}"
    from_grid_l2_power:
      device_class: power
      friendly_name: "Energy from grid L2"
      unit_of_measurement: "W"
      value_template: "{{ max(0, states('sensor.grid_l2') | float) }}"
    from_grid_l3_power:
      device_class: power
      friendly_name: "Energy from grid L3"
      unit_of_measurement: "W"
      value_template: "{{ max(0, states('sensor.grid_l3') | float) }}"

and the integration sensors that then is used in energy dashboard

- platform: integration
  source: sensor.to_grid_l1_power
  name: To Grid L1
  unit_prefix: k
  round: 2
- platform: integration
  source: sensor.to_grid_l2_power
  name: To Grid L2
  unit_prefix: k
  round: 2
- platform: integration
  source: sensor.to_grid_l3_power
  name: To Grid L3
  unit_prefix: k
  round: 2
- platform: integration
  source: sensor.from_grid_l1_power
  name: From Grid L1
  unit_prefix: k
  round: 2
- platform: integration
  source: sensor.from_grid_l2_power
  name: From Grid L2
  unit_prefix: k
  round: 2
- platform: integration
  source: sensor.from_grid_l3_power
  name: From Grid L3
  unit_prefix: k
  round: 2

which I understand that I could make two sensors instead of 6 in group of 3 as per the example from you.

OK, so…the values in W are instantaneous values. So if you create the sensors as I mentioned:

    - name: "Power Export"
      unique_id: power_export
      unit_of_measurement: 'W'
      state: >
        {% if (((states('sensor.grid_l1') | float(0)) + (states('sensor.grid_l2') | float(0)) + (states('sensor.grid_l3') | float(0))) < 0) %}
          {{(states('sensor.grid_l1') | float(0)) + (states('sensor.grid_l2') | float(0)) + (states('sensor.grid_l3') | float(0))}}
        {% else %}
          0
        {% endif %}

    - name: "Power Import"
      unique_id: power_import
      unit_of_measurement: 'W'
      state: >
        {% if (((states('sensor.grid_l1') | float(0)) + (states('sensor.grid_l2') | float(0)) + (states('sensor.grid_l3') | float(0))) > 0) %}
          {{(states('sensor.grid_l1') | float(0)) + (states('sensor.grid_l2') | float(0)) + (states('sensor.grid_l3') | float(0))}}
        {% else %}
          0
        {% endif %}

You would have 2 sensors giving you the (almost) instantaneous values, which actually represent the Power you are importing.

Now the Integration platform, let’s you calculate the Energy consumption out of over time, giving you a value in kWh, so:

- platform: integration
  source: sensor.power_import
  name: Power Import kWh
  unit_prefix: k
  round: 2
- platform: integration
  source: sensor.power_export
  name: Power Export kWh
  unit_prefix: k
  round: 2

These could now be added to the energy dashboard:

and under each of these 2 options you can enter the corresponding import and export rates:

That should do the trick for you…

@Remko yes i think you are right this would work. I tried and made the new sensors and they have values in them however very small 0.03kwh (import) and -0.03kwh export but i cant choose them in the energy dashboard. Any idea why ?

Maybe you could post a few history graphs of these sensors…

image

image

image

image

image

image

image

Maybe this is a problem :

That it’s total and not total_increasing ?

I find the values from the 3 sensors akward. This looks like the net value is always 0. Grid L2 hardly does anything and the other 2 are almost each others inverted values.

This would mean you are not using any grid consumption or export…So I am not sure what to make of that. Looks like either the integration is wrong, or I am completely misunderstanding it.

Been reading a tiny about about the Victron integration and maybe…you are using the wrong L1 to L3 sensors? There are 2 in the Modbus adress list which maybe could work. You are currently using these:

com.victronenergy.grid Grid L1 - Power 2600 int16
com.victronenergy.grid Grid L2 - Power 2601 int16
com.victronenergy.grid Grid L3 - Power 2602 int16

But how about these:

com.victronenergy.system Grid L1 820 int16
com.victronenergy.system Grid L2 821 int16
com.victronenergy.system Grid L3 822 int16

wow i didn’t expect you to dig in into the Victron but great you did, yes i do use those sensors, i am not sure the other ones are different but first let me explain what you see.

I try to keep the grid as close to 0W as possible since i have battery therefore you see postitive values on one phase and negative on another. That’s why you see the inverted values because the inverter produces same energy used on one phase on it’s own phase so in the end the net sum is 0W and i don’t pay for the electricity. All this because the installation is 3 phase but the inverter (actually i have two, one on L1 and one on L3) are single phase.

Ok, then I think the values you are seeing are correct. Maybe not the export since that is the inverted value, so it would need to be:

    - name: "Power Export"
      unique_id: power_export
      unit_of_measurement: 'W'
      state: >
        {% if (((states('sensor.grid_l1') | float(0)) + (states('sensor.grid_l2') | float(0)) + (states('sensor.grid_l3') | float(0))) < 0) %}
          {{(((states('sensor.grid_l1') | float(0)) + (states('sensor.grid_l2') | float(0)) + (states('sensor.grid_l3') | float(0))) * -1 )}}
        {% else %}
          0
        {% endif %}

    - name: "Power Import"
      unique_id: power_import
      unit_of_measurement: 'W'
      state: >
        {% if (((states('sensor.grid_l1') | float(0)) + (states('sensor.grid_l2') | float(0)) + (states('sensor.grid_l3') | float(0))) > 0) %}
          {{(states('sensor.grid_l1') | float(0)) + (states('sensor.grid_l2') | float(0)) + (states('sensor.grid_l3') | float(0))}}
        {% else %}
          0
        {% endif %}
- platform: integration
  source: sensor.power_import
  name: power_import_kwh
  unit_prefix: k
  round: 2
- platform: integration
  source: sensor.power_export
  name: power_export_kwh
  unit_prefix: k
  round: 2

To get them in the energy dashboard I think you need to add (for example) daily utility meters as follows:

utility_meter:
  power_export_daily:
    source: sensor.power_export_kwh
    name: Exported Power Daily
    cycle: daily
  power_import_daily:
    source: sensor.power_import_kwh
    name: Imported Power Daily
    cycle: daily

In the energy dashboard you can use daily values, or monthly, or yearly…doesn’t matter actually. I use daily values in my configuration.

Ok i think i found the issue why it didn’t show up in Energy dashboard, i was missing device_class: power on the template sensors. Now it shows up but i spent more than one hour to try figuring out how to remove the negative value, i deleted the sensor → i went to statistics → clicked fix issue → clicked remove still when i added the sensor again in the config file the negative value was there again. I removed from database entries regarding the sensor but still it was showing up so i renamed the sensor completely but i hate the fact beeing required to do that…hmmm

@Remko got another quesiton relared to this which you may know, i would like to have a sensor that shows to me the consumed energy i have used from the grid today taking into account the facts we discussed earlier that i export energy and buy energy during the day so it’s only the energy that i buy when i am not also exporting that i want to know. Can i somehow use utility meter integration or does the energy dashboard already have a sensor for me that has this calculated ?

If you used the above templates, the “power_imported_daily” should be exactly this value. Since this utility meter only counts the net imported value. So this should be the amount of power which you actually import from the grid and where you need to pay money for. The same is valid for the exported_power_daily sensor…

power_imported_daily ? Is this a sensor/entity or ? I can’t find it in my hass and yes i did the above.

If you created the configuration as per my post above, something like that should be available…

1 Like

@Remko so still having issues with this :

Here is the output from Victron system which i know is correct since i know from the utility company that the consumption from Grid and return are indeed also what they see.

and here is in details what Victron believes i consumed and from where :

and here is what HASS shows for today :

so Solar production seems correct, what i consumed from grid is wrong, same goes for export, the same goes for total consumption and the battery info.

I get battery info from following modbus sensor and the rest is what you helped me with :

- name: 'Battery Power System'
      unit_of_measurement: "W"
      slave: 100
      address: 842
      data_type: int16
      scale: 1.0
      precision: 0
      scan_interval: 20
      device_class: power

and then i template two 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) }}"

and then two integrations sensors:

- 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

any ideas what’s going on ? I have a feeling it’s the issue that it’s not summing correctly when i export 1kwh and use 1kwh at the same time that give 0kwh export and 0kwh import if it happens at the same time.