Automation to shut off devices if house power consumption is over a certain value

So, if there is already a discussion I did not find it.

Since my contract does not allow me to go over a certain instant power consumption it will trip the breaker on my utility meter and I want to avoid that for obvious reasons.

I’m trying to:

  • Check if whole house instant consumption it’s, lets say, over 3 Kw
  • If it is shut off devices one by one and check if it’s under 3 Kw
  • Repeat

How i can do that with an automation or addon?