I posted similarly in the github issue but thought I’d give it a go here as well to maximize the potential help I can get on this. I picked up a few of the DS2413 chips in very tiny tsoc6 form. I “dead-bug” soldered it to some headers so I can prototype on a breadboard and verified it’s functionality using Adafruit’s example code here:
So now I’ve moved onto attempting a custom component to use these things. Admittedly, this is my first custom component and my coding is limited mostly to bash scripting and 101 level C so this is going to be a learning experience no doubt. i.e. constructors and classes are very new to me.
So that said, would be helpful if y’all had some advice to get me going. I’ve read the custom output and custom sensor pages and have started trying to understand some of the example custom components I’ve found.
edit: This device supports being an input or output – working on output first as that is my immediate use case.
First question, are the esp_one_wire and/or dallas libraries that esphome usable in a custom component? i.e. can I leverage the functions that scan the bus for devices?
Here’s what I have so far, and no it doesn’t work.
in custom_component_DS2413.h:
#include "esphome.h"
#include "esp_one_wire.h"
namespace esphome {
namespace dallas {
#define DS2413_FAMILY_ID 0x3A
#define DS2413_ACCESS_READ 0xF5
#define DS2413_ACCESS_WRITE 0x5A
#define DS2413_ACK_SUCCESS 0xAA
#define DS2413_ACK_ERROR 0xFF
// static const uint8_t DALLAS_MODEL_DS2413 =
class DS2413CustomComponent : public Component, public BinaryOutput {
public:
ESPOneWire oneWire(GPIOPin *pin);
uint8_t address[8] = {0, 0, 0, 0, 0, 0, 0, 0};
void setup() override {
ESP_LOGD("custom", "Looking for a DS2413 on the bus");
OneWire.reset_search();
}
void write_state(bool state) override {}
};
} // namespace dallas
} // namespace esphome
and in the relevant yaml:
esphome:
<<: !include templates/devices/wemos_d1_mini_core.yaml
includes:
- custom_component_DS2413.h
libraries:
- "esp_one_wire.h"
dallas:
- pin: D3
output:
- platform: custom
type: binary
lambda: |-
auto my_custom_binary_output = new DS2413CustomComponent();
App.register_component(my_custom_binary_output);
return {my_custom_binary_output};
outputs:
- id: sw_01 # note that the DS2413 has two GPIO so I also need to figure out multiple outputs here
TTIA!
-J