Handling entry gate and garage doors with external drives

Hi .

I’m trying to integrate my garage door and entry gate, which are controlled by external drive. So the drive interface is limited all i have is Step-by-step input programmed as open-stop-close-stop and state light output (off-closed, on-open, quick-flash closing, slow-flash opening). I use state and statistic of light output to identify if the gate is open, closed or moving, this seems to work correctly bud i don’t have an idea haw to handle this sbs input with this 3 state entity.
My goal is to identify in HA how many sbs steps needs to be done to open or close the gate based on light-output state.
Is there a better way to identify slow and fast flashing than statistic? The problem with statistic is at some point fast flashing is also identified as slow flashing and delay required to count changes.
Is there a way to store last state of entity in automation which triggers on entity state change? To find out if gate is opening or closing by checking if gate is moving and previous gate state?