求大佬解答一下 感激不尽
:'(萌新一枚 求大佬指导一下关于 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直接报错,如下
[33mWARNING Please instead use:[0m
[33mWARNING esphome run .\io-test.yaml[0m
[32mINFO Reading configuration .\io-test.yaml...[0m
Failed config
esphome: None
'name' is a required option for .
includes:
- my_custom_sensor.h
报错内容:'(:'(感觉是没找到.h文件 但是两个文件又在同一级目录
esphome ./(esphome 所在目录)/ io-test.yaml run
路径有问题吧
./io-test.yaml run 这才代表当前目录下的 io-test.yaml
或
E:\esphome_config\io-test.yaml netsnake 发表于 2022-1-20 17:17
esphome ./(esphome 所在目录)/ io-test.yaml run
路径有问题吧
不是run E:\esphome_config\io-test.yaml? 那是需要run 哪里的呢 yaml里缺name关键字吧!
页:
[1]