Controlling polarity for a solenoid

I’m looking for a way to control this valve with HA. At first I figured I could use a simple ESP8266 with a relay. But it requires reversing the polarity to close the valve. Is there a way to do this with HA? Preferably with ESPhome and an ESP device?