Is there a way to use "arduino like" sketch in a ESP-Home project?

Hi all and sorry if the question is dumb.
I’m approaching for the very first time the ESP-HOME platform.

I would like to realize a project in which I use an ESP32 to connect via WIFI to Home Assistant and I wuold use ESPHOME.

I need to read and report to home assistant 2 analog sensor connected to a pin and activate two 5V relè switches connected to other 2 pins.

Only things: I would like that the ESP itself will make automatic activation of the switches based on the analog reading made on the sensor pins and report state of the switches to Home Assitant.

I did it previously with an Arduino using the ArduinoHA integration, but there is a problem with the MQTT in teh recent update of home assistant and I am not able to fix it, So I am thinking to switch to ESPHOME but I need the automatic functionality inside the device (not an Home Assistant automation, it must work regardless if Home assistant is up or not).

Is there something I can use?

Thanks for helping

Can you use an ‘arduino sketch’ directly in ESPHome? Technically, yes, but really only suitable for VERY special circumstances. Better is to just use ESPHome’s built-in automation features:

I think you’ll find you can do all you need quite easily this way (once you get past the initial learning curve).

Between ESPHome’s automation linked above and lambda this is super easy.

Lambda is just C++ code. If you want to do complex calculations and comparisons in ESPHome you can include lambda in your yaml. Truthfully though, based on your requirements above, you will need very little if any lambda code.

I would start slowly. Get your sensors working, then get the relays working, then add an 'on_value:` trigger to the sensor to control the relay. Don’t skip reading the Sensor Core documentation when you create your analog sensors.