Make a stopwatch with two HC-SR04

Hello everybody !

Here is my question :

  • When i click a button on home assistant, i start the sensor, it scan every 0.05s (for example)
  • if the sensor have a distance > 100 cm, it doesn’t send anything
  • if the sensor have a distance < 100 cm (my cat pass in front of the sensor) it send something to NodeRed, and start a timer
  • the sensor is stopped

It’s to make a stopwatch for bikes.

I’ve made it with micropython + mqtt + NodeRed. It works but i meet some problems with it.
So, I don’t look at the complete solution, i just want to know if it could be possible with esphome and where to start (lambda ? Custom Sensor Component ?)

Thank you very much for your help !!!