Baby sleep stopwatch timer

Hello.

I am trying to make a simple stopwatch for tracking baby sleep.

The flow should be like so.

toggle baby_sleep_switch on/off

When baby_sleep_switch toggles on
1# reset baby sleep stopwatch
2# stop baby awake stopwatch
3# start baby sleep stopwatch

when baby_sleep_switch toggles off
1# reset baby awake stopwatch
2# stop baby sleep stopwatch
3# start baby awake stopwatch

i have tried with history stats, where i could get both stopwatches to count, but i could not get them to reset. They just continued from the previous state where they have stopped.
I have also tried with sensor.time, which flooded my logbook and didn’t update in realtime, only once every minute.

Has anyone done something similar that they would share, or could you help me in the right direction?

We use this to track sleep and other things for our baby

I’ve made a stopwatch. I think it can be useful for your use case.

Here it is the code:

https://community.home-assistant.io/t/stopwatch-with-start-stop-resume-lap-and-reset/443994