Energy monitoring how to make monitor sensors

Hi everyone,
I’m configuring the energy section into HA. I have this situation right now: I have two meters, (both shelly 3em cause I have a 3 phases line for my house and 3 phases solar panels). One is outisde the inverter and it’s looking the solar panel production, the other is right before the house consumptions so it’s looking the loads. I need to define now two sensors (which comes from the same equation by the way) which are returned energy and grid consumption. I can find them in this way:

Solar production - house consumption = if positive, feed in energy (returned energy), if negative grid consumption. How can I do these kind of sensors?

Many thanks.

I’m a beginner but I think I had a similar problem which I partially fixed yesterday.

I have two inverters but only one of them reports to HA (it produces roughly three times more PV than the smaller one). So I had to create sensors that multiplied the reporting inverter’s results by 1.3 to get a more accurate figure in HA.

It’s pretty close… but still needs work. I’ll have to adjust the formula for both sensors. Particularly for the PV to grid, because it’s not directdly proportional to the PV production (ie depends how much the house is using). And I suspect that the default value at the end of each of the long lines in red shouldn’t be 0 … though I’m not sure.

Anyway… your formulas will be different but the same approach might work for you.

I created a template for each sensor in configuration.yaml - code will follow. Then I had to edit the customise.yaml file to create states for both entities so the energy tab would see them… note the last line in the configuration.yaml file.

# Template for sensor with calculated cumulative PV Energy Output of JFY and Fronius
  - sensor:
      - name: "both inverters"
        unit_of_measurement: "kWh"
        state: >
          {{ ((states ('sensor.energy_day_fronius_inverter_system_http_192_168_0_100') | float) * 0.0013) | round (3, default=0) }}

# Template for sensor. Calculated PV exported to grid. Consequent on "Both Inverters" template/sensor
#     ? calculation not direct multiplication - as some of extra PV will go to house cf all to grid
#    energy_real_produced is a running value not daily so ? default not zero. Energy tab calculates change over an hour
  - sensor:
      - name: "pv to grid"
        unit_of_measurement: "kWh"
        state: >
          {{ ((states ('sensor.energy_real_produced_fronius_meter_0_http_192_168_0_100') | float) * 0.00115) | round (3, default=0) }}

    customize: !include customize.yaml

and here’s the customise.yaml

  device_class: energy
  state_class: total_increasing

  device_class: energy
  state_class: total_increasing

Will be watching for advice from someone more expert than me… there’s probably better ways to do it.

I have updates for this matter: I need to create two power sensor, one called grid consumption power defined by house consumption is > solar production but it’s 0 when solar production > house consumption and then another called feed in power defined by solar production > house consumption but it’s 0 when house consumption is < solar production. Then I have to integrate it in order to get and energy sensor for the grid consumption and returned energy which I’ll re-call it into energy section.