Need help for yaml: Cyclically write and read from UART for sensor value

Hi there!
I am quite new to the world of home assistant and have successfully integrated two custom sensors using ESP8266s. However, the third one I am currently playing around with is a little bit tricky:
The ESP8266 is connected to a device via uart. What I want to achieve is something like this:

every n seconds do{
	WriteToUART("N1");
	WriteToUART("M");
	string = ReadFromUART();
	number = parseFloat(string);
	sensor1Value = nonlinearCalculation(number)
	
	WriteToUART("N2");
	WriteToUART("M");
	string = ReadFromUART();
	number = parseFloat(string);
	sensor2Value = nonlinearCalculation(number)
}

Honestly spoken I am a little bit overwhelmed by the features and the syntax is totally confusing me. I already created the uart_read_line_sensor.h but now I am lost in how to combine everything to get it working as given in the pseudo code.
Can you give me a hint maybe?

Thanks and best regards
Sven