I often crash my raspberry pi when compiling esphome sensors and stuff, and noticied that it might be caused by the number of compilation threads which is 4 by default.
Is there any configuration item in the esphome addon to set the number of threads to a lower value ?
This is uncalled for. @nickrout has provided you the first step towards a likely answer. The PlatformIO options allow you to control the compilation. Look at the link inside that section.
From memory, I checked and found that the number of threads is forced/equal to number of CPU Cores, that could be improved with some prarameter to specify the number of compliation threads (-j parameter)