I would like to get a mobile notification in case of the power of my water pump drops 10 times or more in a hour. My basic script looks like this and I stucked at this point. Every assistance greatly welcome.
You will probably need to create a “counter” entity to keep track of the number of times the power has dipped. To do this for a rolling 1-hour window can be tricky, as an ordinary counter entity probably won’t work. Your automation entity would work, but unfortunately automation triggerings are not states, they are attributes, making it a bit harder to track.
The easiest approach may be to create two entities: a templatebinary_sensor that turns TRUE whenever your automation runs (i.e. its current attribute > 0), and a history_stats sensor tracking the count of that binary sensor for the past 60 minutes.
(It should be possible to do this with a single entity using the SQL integration to query the recorder database directly, but I’d need to be at my desk to figure that SQL code.)
Either way, your automation, just like you have above, will trigger every time the power drops, allowing your stats/sql counter to keep track of the number of times it is happening. But in the actions, add an IF condition that only sends a notification when the counter sensor =10.