18180682467 发表于 2022-1-20 15:23:21

求大佬解答一下 感激不尽

:'(萌新一枚 求大佬指导一下关于 esphome 自定义传感器的相关问题
1.
之前是按照官方的文档 将 my_custom_sensor.h 放在E:\esphome_config 中 .h内容如下:

class MyCustomSensor : public PollingComponent, public Sensor {
public:
// constructor
MyCustomSensor() : PollingComponent(15000) {}

float get_setup_priority() const override { return esphome::setup_priority::XXXX; }

void setup() override {
    // This will be called by App.setup()
}
void update() override {
    // This will be called every "update_interval" milliseconds.
}
};   


2.
在E:\esphome_config 中创建 io-test.yaml 内容如下:
esphome:
# ...
includes:
    - my_custom_sensor.h
# Example configuration entry
sensor:
- platform: custom
lambda: |-
    auto my_sensor = new MyCustomSensor();
    App.register_component(my_sensor);
    return {my_sensor};

sensors:
    name: "My Custom Sensor"   



3.
但是 esphome ./(esphome 所在目录)/ io-test.yaml run直接报错,如下

WARNING Please instead use:
WARNING    esphome run .\io-test.yaml
INFO Reading configuration .\io-test.yaml...
Failed config

esphome: None

'name' is a required option for .
includes:
    - my_custom_sensor.h




报错内容:'(:'(感觉是没找到.h文件 但是两个文件又在同一级目录



netsnake 发表于 2022-1-20 17:17:05

esphome ./(esphome 所在目录)/ io-test.yaml run

路径有问题吧
./io-test.yaml run 这才代表当前目录下的 io-test.yaml

E:\esphome_config\io-test.yaml

18180682467 发表于 2022-1-20 18:25:41

netsnake 发表于 2022-1-20 17:17
esphome ./(esphome 所在目录)/ io-test.yaml run

路径有问题吧


不是run E:\esphome_config\io-test.yaml? 那是需要run 哪里的呢

netsnake 发表于 2022-1-24 17:29:10

yaml里缺name关键字吧!
页: [1]
查看完整版本: 求大佬解答一下 感激不尽