Hc-sr04 and more diode led

Hello everybody. I am new to the forum and the Home Assistant world and I don’t know where to start. I land here to disconnect from the Blynk app.
I’ll explain what I would like to achieve:
through the idea of arduino I compiled a sketch that runs an esp8266, an HC-SR04 and 6 led diodes to monitor a water tank, as the tank empties, the led diodes turn off. How can I do the same thing with ESPHome?
Thanks for your help.

There are many threads about water level sensors. Use search.

Unfortunately I have not found anything similar to my project. Surely you have already created something similar and I just need a starting point.
In practice, could you give me an example on how to compile the code to say: “if this happens, I turn on the led on the gpio4”?

I think you may have missed this in the docs Automations and Templates — ESPHome

Nickrout as I said at the beginning of the thread, i have just entered the Home Assistant and EspHome world and everything that is taken for granted for you is not for me. From the link I do not understand much but I will look for examples of other users and find the solution.

Usando l’IDE di Arduino, lo sketch è il seguente:

if ( distance <= 7 )
  {
    digitalWrite(LED1, HIGH);
  }
  else
  {
    digitalWrite(LED1, LOW);
  }
  if ( distance <= 14 )
  {
    digitalWrite(LED2, HIGH);
  }
  else
  {
    digitalWrite(LED2, LOW);
  }
    if ( distance <= 27 )
  {
    digitalWrite(LED3, HIGH);
  }
  else
  {
    digitalWrite(LED3, LOW);
  }

now I’ll have to figure out how to transform it for EspHome. Does anyone have a practical example to start with?