Hi everyone,
I’m trying to calculate the amount of electricity a) that we consume and b) that we feed into the grid from two different sets of solar panels.
I’ve been doing this in Excel using the meter readings at the end of the month, but I’d like to see the numbers on a daily or even hourly basis in Home Assistant.
I already have the individual meter readings via MQTT in Home Assistant, so I thought it would be pretty easy.
When we weren’t feeding any electricity into the grid in the winter, the calculations worked out, but now that we’re starting to feed electricity into the grid, the results are not plausible. It appears that the entire production is being consumed, yet in addition, we’re feeding a certain amount into the grid.
The formula that works in Excel is as follows:
New panels own consumption = Z3 – (Z1 – Z2)
I created a sensor to record the consumption as follows:
name: "New Panels Own Consumption v1"
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
state: "{{ ((states('sensor.z3_filtered')|float(0)) - ((states('sensor.z1_filtered')|float(0)) - (states('sensor.z2_filtered')|float(0)))) }}"
I’m not sure if it’s the content of the template or maybe even the state_class attribute in the source and combined sensors that could be causing the problem, or maybe a combination of the two?
I tried with more and fewer brackets in the template of the New Panels Own Consumption v1 sensor, but of the variations that are valid templates, the outcome remained the same.
Can anyone spot anything obviously wrong?
Thank you!
I am not entirely sure what the different Z values represent, but looking at the formular it looks like either your state class or your formular is wrong.
State class total_increasing just works with increasing values. When e.g. Z1 increases more than Z2 and Z3 your result value decreases. This will result in an reset of the total amount.
Rewriting your formular the problem becomes a bit clearer:
Value = Z2 + Z3 - Z1
From the docs:
" For sensors with state_class STATE_CLASS_TOTAL_INCREASING, a decreasing value is interpreted as the start of a new meter cycle or the replacement of the meter. It is important that the integration ensures that the value cannot erroneously decrease in the case of calculating a value from a sensor with measurement noise present. This state class is useful for gas meters, electricity meters, water meters etc."
Either use total as state class or make sure that your value always grows.
Thank you for taking the time to read through my problem and for what seem to be very valuable insights!
The different Z values are the meter readings (Z stands for Zähler (meter in German)). We have two sets of solar panels with different rates for what we feed into the grid. This has resulted in a total of 4 meters to contend with.
Z3 (and Z4, which is not depicted in this scenario) measure production.
Z2 is a two-way meter that measures the combined amount that we a) take from the grid and b) consume from the new solar panels. In the other direction, it measures what the old panels send towards Z1 on its way to the grid.
Z1 is a two-way meter that measures what we use from the grid and feed into the grid from both sets of solar panels.
Based on what I work out using the individual meter readings from one day to the next in Excel, the formula seems fine.
What you wrote about the total amount being reset when Z1 increases more than Z2 and Z3 is exactly the problem: as soon as we feed something into the grid, especially from both sets of solar panels at the same time, Z1 does indeed increase more than Z2 and potentially more than Z3, depending on the amount that the new solar panels are generating at the time.
So, I’m going to try changing the state class of the New Panels Own Consumption v1 sensor to total.
The state class of the New Panels Own Consumption v1 sensor has been set to total for close to 24 hours. Unfortunately, the result is the same as it was with total_increasing.
According to the Z3 sensor, the new panels produced 22 kWh today.
According to the daily sensor (from the Utility Meter integration) that I have for the New Panels Own Consumption v1 sensor, we consumed 29.88 kWh from the new panels. That’s impressive given that they produced only 22 kWh
If I take the individual meter reading increases for Z1, Z2, and Z3 over the last 24 hours and plug them into the formula that you reworked, I get plausible numbers:
Value = Z2 + Z3 - Z1
Value = 7 + 22 - 26
Value = 3
Of the 22 kWh that the new panels produced, we consumed 3 and therefore fed 19 into the grid. That fits.
So there’s obviously still something wrong somewhere.
The daily sensor that I’m using via the Utility Meter integration has New Panels Own Consumption v1 as its source. This is what I see for the daily sensor in the developer tools:
state_class: total
unit_of_measurement: kWh
device_class: energy
friendly_name: New Panels Own Consumption v1
The state class of the individual meter reading sensors has to be total_increasing, right? After all, the individual meter readings do count up.
Does anything else stand out as being suspect?