Can I use this sensor(scd40) instead of S8 with 4.2 DIY?
Not without you modding the hardware to be able to plug it into a different location and updating the software so support it.
Hardware is not a problem.Do you mean that existing software doesn’t support any other co2 sensors, except s8?
Correct, the default firmware doesn’t automatically support sensors that aren’t supported, so you would have to modify the Arduino code to add support for that sensor and what I2C address it is using.
There is also an ESPHome firmware configuration for these devices and adding support for the scd40 is pretty straight forward:
SCD4X COâ‚‚, Temperature and Relative Humidity Sensor - ESPHome - Smart Home Made Simple
The board has extra headers for I2C but it doesn’t look like the sensor uses the same pinout, so you would have to run your own wires to get it connected to the correct locations.