Alerting with total_increasing deltas and returned energy calculation

Hi there,

i’m trying to create a kind of alerting rule and doing some calculation based on statitstics deltas of my total_increasing entities.

Specifically i want to set up a rule for water loss detection. Something like if during the night hours the value never goes down to 10L every 5 minutes or if it goes over a threshold. I already have a statistics graph like this for water consumption:

Then what i want to do is to create a fake entity measuring the returned energy from my PV plant. I already have a multimeter measuring the total (total_increasing) consumed energy (including the PV) and the PV production (another total_increasing) from my inverters.
What is the easiest way to subtract each delta to have the eventually returned energy?

Thanks!

“Never going down to 10” is the same as “staying above 10”.

triggers:
  - trigger: state
    entity_id: sensor.water
    above: 10
    for:
      minutes: 5
  - trigger: state
    entity_id: sensor.water
    above: 42 #threshold
conditions:
  - condition: sun
    entity_id: sun.sun
    state: "below_horizon"
actions:
...

Use a template sensor. Either from the UI helpers menu or in YAML.

So you are suggesting setting up an automation. Maybe the condition checking just the sun is not enough as it should check only “sleep hours”.
I also don’t think the trigger is going to work as it is because i have a total_increasing counter that obv is always above 10L.

Feel free to ignore my advice it but it is exactly what you asked for.

Feel free to contradict me, i’m saying i’ve tried and that is not enough for a total_increasing sensor as the value is always increasing.

This is not a total increasing sensor:

As i said in first post it is a statistics graph on a total_increasing sensor.

I don’t think i understand the process. What should i create as a template? The subtraction between the 2 total increasing counters? That way the stats should have the correct value?

This is what i’ve done so far with the power (i don’t know it’s the most efficient way):

 - name: FV theo 2.8.0 kW
    unit_of_measurement: "kW"
    device_class: "power"
    unique_id: fv_theo280w
    state: >
     {% set fvkw = (states('sensor.inv_11_power') | float)
     + (states('sensor.inv_12_power') | float)
     + (states('sensor.inv_13_power') | float)
     + (states('sensor.inv_14_power') | float)
     + (states('sensor.inv_15_power') | float)
     + (states('sensor.inv_16_power') | float) %}
     {% set qegw = (states('sensor.qeg_power') | float) %}
     {% if fvkw < qegkw %}
     {{ ((fvkw - qegkw) * 0) | round(2) }}
     {% else %}
     {{ ((fvkw - qegkw) * 1) | round(2) }}
     {% endif %}

If there’s any other suggestions i’m still looking for the optimal solution.

Still haven’t found a way to get the statistics from a total_increasing sensor as a value to use for widget visibility in dashboard or alerting.
Probably a workaround can be creating for example an utility meter with reset every 15m and use that value as a threshold.
Problem is that it doesn’t considere “last 15m” but bucket of 15m each and at the 16th minute it will always be 0.
And i was also trying to avoid creating entities over entities and make my system more complex.

I’ll share what I’ve done so far since it seems it is a very niche need.
I had to create a couple of entities even if i wasn’t really happy about it.

I created a statistic helper on my total_increasing sensor wiht “Absolute distance” to get the consumption from the latest hour.
Then i created another statistic helper with the lowest value of the latest 10 days (with 240h as max age time).
This way i can directly use this value for “alert” visibility on the home assistant dashboard or even for automation.
I can for example use it to detect if there’s a water leak if the lowest hourly value in latest days is strangely high.

Still haven’t found an optimal solution for calculated returned energy without creating too much entities…