Ledc and pwm speed fan with a twist

Hello guys

I’m new to esphome a done some digging for my current project. I have the feeling I am pretty close to what I need but can quite put it together.

Here’s the thing

I got some vents in my house which runs with 12V DC and can be controlled with a pwm signal. Here’s the twist. Those vents can blow forward and reverse and it’s controlled with the same pwm signal. Meaning from 0-50% it’s blowing outward (with 0 being the maximum and 50% being off) and from 50-100% it’s sucking air in (where 100% is maximum).

Now what I tried to do.
I added a speed fan in my yaml (and it’s showing up in HA with speed control and direction control)
And I added a ledc to a gpio pin.

I tinkered a little bit with template and such but what I want is a way to mangle the value that is send to the gpio pin just before sending and do some math so the fan spins in the right way.

Any hint is appreciated. Thank you all in advance.