Integrating power consumption for a dynamic time

Hello all

I have been a user of home asstant for some years not and I really love it and by searching in this forum I have been able to solve a questions and problems I have had so far… But now I have a interesting question…

So, summary of question:
How can I measure power consumption from a plug based on when I turn on another switch and for a fixed time, e.g. 1-10 miinutes and show this value.

Detailed description
I have a water pump connected via a Shelly plug (not for on/off, but for energy measurement), this then feeds a number of water valves for my irrigation system (Gardena 24V valves controlled via two Sonooff 4CH PRo R2).

I then can control the valves via the GUI or via automations.

My problem is that if there is a problem with the pump (like running out of water, filter clogged, etc.) there is a overheat protection on the pump that cuts the power and needs to be manually reset. This is ok; But I need to know if this has happened or not.

So, when turing on a water valve I would like to measure power drawn by the pump over 1-10 minutes and then show this value in the GUI (or trigger notifications etc)

The pump has a pressure tank and therefore is not run contiously, only when the pressure flow falls under a certain limit, so it only draws power in bursts 3-5 times per minute (depending on the water flow required). So the power consumption must be integrated over time (min 1 minute), it is not enough to read the current value to see if the pump is active or turned off via the overheat protection.

Thanks for any input that you can provide in this topic.

Couldn’t you do something like:

If switch is on
And power consumption last 10 mins < 0,5KWh
Then trigger notification

Measure the power continuously.

If you want it for a period get the value at the start of the time span, and at the end. Subtract and you have the answer. The integration and utility meter integrations will help. and

The way I would approach this is to use the statistics sensor to calculate a 1 minute average of the power.

Your automations can then include a numeric state condition based on this power.

Thank you for the input. Now i have several ideas ro test. I was just stuck…