Custom component with existing sensor

Hi all,

Are there any examples or explanations available (or would someone be willing to explain) how to create a custom component that uses an existing sensor model. Specifically, I’ve got a “one wire” (dallas) temperature sensor, which I’d like to be able to use the temperature value from in my component. I’m unclear on how that would be done though. I’m sure it has been done plenty of times, I’m just not seeing it!

The other option I thought of would be to create a DallasTemperatureSensor instance and read get_temp_c() - is that possible?

Thanks,
Allan

So the Dallas sensor is not standalone? I am confused why you simply wouldn’t use the Dallas component directly.

It does work independently - setting it up I can see that the debug is printing out the current temperature. What I’m unclear on is how to use that temperature in my custom component on ESPHome.

Ah - ok - wasn’t clear.

No idea but the last post in this thread may help:

Thanks - however that appears to be HA specific (I know this is a HA forum :slight_smile: It does say general ESPHome questions can be asked as well though).

I’ve been hacking around and I’m just not getting anywhere, in part due to the dynamic build nature of ESPHome. I don’t know how to include:

#include "esphome/components/dallas/dallas_component.h"
#include "esphome/components/dallas/esp_one_wire.h"

wtihout setting up the Dallas component in the YAML, which I was going to side step since I could just set it up in my component.

However, I’m thinking now that a better way would be to somehow pass the DallasTemperatureSensor instance to my custom component. Can I figure out how to do that though… Nope. Any suggestions welcome!