Show how many seconds a door is open

I need to create a sensor that shows how many seconds a Gate (cover) is open or has been opened. When the cover is closed, it should show for how long was opened the last time. When the cover opens, it should start counting the seconds again from 0. Is this something feasible?

I’ve looked at History Stats, Timer Helper, etc., but after a lot of digging I assume it’s only doable via templates. Any help greatly appreciated.




  - entity:
    secondary_info: last-changed