Converting custom component to external component

Hi,

Last year i managed to create two custom components for logging “serial” data from my heatpump device.

I tried to convert those into external components without any luck for days now…

I created the correct file/folder structure on my github, and i created new .yaml “ctc2esp-ext.yaml” for external component instead of custom component “ctc2esp.yaml”

While compailing i do get following error:

ctc2esp.yaml: In lambda function:
ctc2esp.yaml:58:35: error: expected type-specifier before ‘DP’
ctc2esp.yaml:65:42: error: could not convert ‘{, , , , , }’ from ‘’ to ‘std::vectoresphome::binary_sensor::BinarySensor*
ctc2esp.yaml: In lambda function:
ctc2esp.yaml:78:35: error: expected type-specifier before ‘HP’
ctc2esp.yaml:85:53: error: could not convert ‘{, , , , , }’ from ‘’ to ‘std::vectoresphome::sensor::Sensor*
Archiving .pioenvs\ctc2esp\lib8a0\libAsyncTCP-esphome.a
Compiling .pioenvs\ctc2esp\lib524\WiFi\WiFiScan.cpp.o
Compiling .pioenvs\ctc2esp\lib524\WiFi\WiFiServer.cpp.o
Compiling .pioenvs\ctc2esp\lib524\WiFi\WiFiUdp.cpp.o
*** [.pioenvs\ctc2esp\src\main.cpp.o] Error 1

Could some one point me into right direction ? Or a step by step guide for conversion of custom components into external components?

Github : mercix/CTC2ESP

Best regards
/Mercix

I think the easiest is to copy an existing sensor from the components’ directory that is similar in operation to yours and modify it to work with your code instead. You will have to structure your own CPP code to match the copied code, such as how sensors are set up, etc. You can look at a simple one such as the “dht” sensor, which provides a couple of sensors to give you an idea. Furthermore, you can pass the uart used as a config parameter for the sensor.

This page is also very helpful:

You need something to pull your two headers in to the build directory before your lambda can use the class definitions. That is what this little snippet was doing:

esphome:
...
  includes:
    - dp.h
    - hp.h

What you should be doing is writing your sensor code in hp/dp.cpp along with a bit of python code to parse the yaml rather than doing it in a lambda. Pick an existing simple component, and use that as an example.