Turn off something and after turn it on again if it was on, based on sensor value

Hi community! First time here, but using HA since 2018. Never did more complex automations, so I need your help to achieve something.
My goal is turn off a vehicle charger (if it was turned on) if energy current consumed by my entire house exceeds 50A. And turn it on again when the energy current drops below 10A.
I would know how to do this automation, if I didn’t need to know if the charger was already on before the automation runs.
Do I need a variable to hold a true/false value, so I know if the charger was on or off in the time the automation was triggered? How can I do that?
I appreciate any help.
Thanks!

When the automation triggers create a scene to save the state of the charger before you turn it off. Then restore the scene when the energy current drops below 10A.