I have been able to create a substitute components for the dht sensor component
using the custom component and external component methods. In both, I was unable to pass the pin number and model type to the PlatformIO library object. I had to hard code both parameters like this:
::DHT dhtnew(2, DHT_MODEL_DHT22);
Using the external component, I tried putting the dhtnew object in the esphome DHT class but the parameters are not available until after the dht_dht object is created from the esphome DHT class.
I think I need to modify sensor.py so that above object creation is added before the void setup() section, with parameters from the yaml configuration.
I found that I could get the parameters using these statements:
Kind of a programming challenge for me. I want to demostrate that esphome components don’t have to be created from scratch if a stable PlatformIO library is available.
Here is a link to my repository if anyone has the time to show me how to use the esphome code generation.
Edit on Jun 28.
I SOLVED this by reviewing the tm1651 component example in the esphome repository.
I found that I could set the DHT object parameters in the setup method if a pointer was created in DHT.h
My repository above has been updated with the working code.
Add this to your yaml configuration:
This technique is useful to test an esphome component using a compatible PlatformIO library.
PS.
external_components could not find the main branch so I created the dev1 branch.
Your post helped me solve a problem that I hadn’t been able to work out by poking around. I wanted to be able to add an Adafruit library that PIO knows about as a dependency in my component definition, but I hadn’t stumbled on an example among the existing components. Even though (I think) you were looking at a slightly different problem, your pointer to the tm1651 component helped me notice the cg.add_library() method.
Each git commit has a version hash code. To find the latest version I cloned the repository and used the following git bash command to find the hash code.
git rev-parse HEAD
I got:
d6a29134401d7caae1b8fca9c452c8eb92af60c5
I support my Mitsubishi Heatpump with a pure PlatformIO project. The Library code on PlatformIO is not maintained so I just copied the latest source files and create by own version number to put into platformio.ini
My control from Home Assistant would lock up once in a while requiring a power cycle to reboot. I hope the latest commit fixes this issue.
I see this a post under ESPHome. There is a Esphome example here github.com/geoffdavis/esphome-mitsubishiheatpump
Unfortunately, it does not support all the vane (A.K.A swing_modes) and wideVane ( “<<”, “<”, “|”, “>”,">>", “SWING”) modes for my Mitsubishi Heat pump because of ESPHome Climate component limitations. I tried to convert my pure PlatformIO version to a ESPHome version based on the ESPHome Custom MQTT component but got stuck on handling the callback functions. If your code for ESPHome supports all vane and wideVane modes please post it.
The pure PlatformIO version uses the Home Assistant HVAC integration along with an automation to process the heatpump/set topic. Works to control all the features on my Mitsubishi Heat pump.