I used the instructions Custom Sensor Component — ESPHome but when I check the Config it gives me “Integration error: custom_component - Integration ‘custom_component’ not found.”
My configuration.yaml:
default_config:
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
logger:
default: critical
logs:
# log level for HA core
homeassistant.core: fatal
esphome:
includes:
- my_custom_component.h
custom_component:
- lambda: |-
auto my_custom = new MyCustomComponent();
return {my_custom};
components:
- id: my_custom_id
my_custom_component.h
#include "esphome.h"
class MyCustomComponent : public Component, public CustomMQTTDevice {
public:
void setup() override {
pinMode(6, OUTPUT);
subscribe("the/topic", &MyCustomComponent::on_message);
subscribe_json("the/json/topic", &MyCustomComponent::on_json_message);
}
void on_message(const std::string &payload) {
if (payload == "ON") {
digitalWrite(6, HIGH);
publish("the/other/topic", "Hello World!");
} else {
digitalWrite(6, LOW);
publish("the/other/topic", 42);
}
}
void on_json_message(JsonObject root) {
if (!root.containsKey("key"))
return;
int value = root["key"];
publish_json("the/other/json/topic", [=](JsonObject root2) {
root2["key"] = "Hello World";
});
}
};
What am I missing?