How to toggle between gpio.OUT/IN with a switch?

Hey everyone! (TL/DR on last line)
I am very new to home assistant, so my first step is trying to recreate whatever i did in a previous raspbian build with a custom web interface.
I control a bunch of relay boards.
The relays that need to be set to OUT and then high/low do work OK, by following the code as stated in the documentation.

One of my relay boards though, for some reason does not work like this. If i set the GPIO to out, the relay is always on (not affected by low/high, if it’s set to input then the light goes off. So what i did was i wrote the web/bash script to toggle the GPIO between output and input on every switch click.

Is there a way to do that on Home assistant?
If so, please do explain it to me in detail as im still figuring things out.

TL/DR: Set up a switch in the interface that will toggle my GPIO between In and OUT instead of High/Low