Turn on a wifi power plug when voltage sensor increase

I have a SMA Tripower 6000 inverter, i already can read the current incomming voltage.
But the problem is, in my street are to mutch solar installation, and sometime on phase 2 i get 260v, above 253v the inverter must shut down.

But if i power like a heather from 2000watt or something, the power i going back from 260 to around 249v.
So let say, then my solar is sendmy 6000watt and i user 2000watt directly.
If i do nothing, my inverter is going in shut and i get nothing, now i still have 4000watt left.

The idea is to get tis automated.
Is there any sollution?
Let say is voltage from sensor phase 2 i going above 253volt, a powerplug is turning on for 5minutes.
After 5minutes it’s turning off again, but if voltage it still above 253volt after it going on again.

I’m not sure I fully understand what you want. But I think you want if the voltage goes above 253V, then turn on something, and if it goes below 253V, and stays below 253V, for at least 5 minutes, then turn that something off. Is that it?

If so, I would recommend:

  1. Create a binary sensor that indicates if the voltage is above 253V. E.g., you could use the Threshold binary sensor like this:
  - platform: threshold
    name: Voltage Above 253V
    entity_id: sensor.VOLTAGE
    upper: 253

This will create binary_sensor.voltage_above_253v, which will be 'on' whenever sensor.VOLTAGE is above 253, and 'off' whenever sensor.VOLTAGE goes below 253.

  1. Create an automation that turns that something on when binary_sensor.voltage_above_253v changes to 'on', and turns that something off when binary_sensor.voltage_above_253v goes 'off' and stays 'off' for 5 minutes, like this:
  - trigger:
      - platform: state
        entity_id: binary_sensor.voltage_above_253v
        to: 'on'
      - platform: state
        entity_id: binary_sensor.voltage_above_253v
        to: 'off'
          minutes: 5
      - service_template: >
          {% if trigger.to_state.state == 'on' %}
          {% else %}
          {% endif %}
        entity_id: switch.SOMETHING

Thx for replay.
Almost good, but it more like:
This will create binary_sensor.voltage_above_253v , which will be 'on' whenever sensor.VOLTAGE is above 253 for 5 minutes and then turnoff.

But you said if after 5 minutes the voltage was still above 253V that it should stay on. I doubt you want to turn it off and then immediately turn it back on. That’s not usually something you want to do with a switch that controls any kind of power.

As example, if the power is 256v, higher then 253v the thing is turning on.
but from that moment you turn the thing on, the voltage will go lower again to around 248v
so that’s why it need to run for about 5minutes and then turn off again.
If there is mutch solar power at that moment the voltage wil go high again and it must turn on again.

Yes, that’s exactly how the code I suggested would work.

EDIT: Well it’s very close to that. This is what it will do:

When the voltage rises above 253 it will turn the switch on. As long as the voltage is above 253 the switch will stay on. When the voltage goes below 253 it will not immediately turn off the switch. The voltage has to stay below 253 for 5 minutes before the switch will be turned off.

So, e.g., if the voltage goes above 253, the switch will be turned one. If it then goes below 253 for 3 minutes and then goes back above 253, the switch will stay on. The switch will not be turned off until the voltage goes below 253 for at least 5 minutes.