1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-30 00:52:20 +01:00

Add NTC and resistance sensor (#560)

* Add NTC and resistance sensor

Fixes https://github.com/esphome/feature-requests/issues/248

* Fix

* Fix platformio4 moved get_project_dir
This commit is contained in:
Otto Winter
2019-05-28 16:00:00 +02:00
committed by GitHub
parent 9fa1a334e6
commit 61ba2e0f35
12 changed files with 321 additions and 2 deletions

View File

@@ -0,0 +1,31 @@
#include "ntc.h"
#include "esphome/core/log.h"
namespace esphome {
namespace ntc {
static const char *TAG = "ntc";
void NTC::setup() {
this->sensor_->add_on_state_callback([this](float value) { this->process_(value); });
if (this->sensor_->has_state())
this->process_(this->sensor_->state);
}
void NTC::dump_config() { LOG_SENSOR("", "NTC Sensor", this) }
float NTC::get_setup_priority() const { return setup_priority::DATA; }
void NTC::process_(float value) {
if (isnan(value)) {
this->publish_state(NAN);
return;
}
float lr = logf(value);
float v = this->a_ + this->b_ * lr + this->c_ * lr * lr * lr;
float temp = 1 / v - 273.15f;
ESP_LOGD(TAG, "'%s' - Temperature: %.1f°C", this->name_.c_str(), temp);
this->publish_state(temp);
}
} // namespace ntc
} // namespace esphome