Switch on when power below level x multiple times

Hi,

I have a cycle battery charger which misbehaves and only turns on after several times plugin it in the wallsocket.
Ideal for an automation with a ESPHOME switch.

I need to make an automation which keeps turning on the wallsocket (when LSC powersensor < 100VA) until it is above 100VA with an on/off interval of 20 seconds.
Once it is steady on it will be above 120VA until the battery is full and then it will drop below 70VA. At that point I want to switch off the LSC powerplug permanently.

I think this is not possible from the user interface.
Can someone write me a yaml?

No replies yet :frowning: Maybe I asked the question in a wrong way
When I would write in pseudocode (assuming single thread)

While NOT (switch.amp > 100) do
turn on switch
delay 60sec
moveon = false
end while

moveon = true

While switch.amp < 100 for 10 sec and moveon= true do
turn off switch
end while