ESPHome  2024.5.0
pylontech_sensor.cpp
Go to the documentation of this file.
1 #include "pylontech_sensor.h"
2 #include "esphome/core/helpers.h"
3 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace pylontech {
7 
8 static const char *const TAG = "pylontech.sensor";
9 
10 PylontechSensor::PylontechSensor(int8_t bat_num) { this->bat_num_ = bat_num; }
11 
13  ESP_LOGCONFIG(TAG, "Pylontech Sensor:");
14  ESP_LOGCONFIG(TAG, " Battery %d", this->bat_num_);
15  LOG_SENSOR(" ", "Voltage", this->voltage_sensor_);
16  LOG_SENSOR(" ", "Current", this->current_sensor_);
17  LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
18  LOG_SENSOR(" ", "Temperature low", this->temperature_low_sensor_);
19  LOG_SENSOR(" ", "Temperature high", this->temperature_high_sensor_);
20  LOG_SENSOR(" ", "Voltage low", this->voltage_low_sensor_);
21  LOG_SENSOR(" ", "Voltage high", this->voltage_high_sensor_);
22  LOG_SENSOR(" ", "Coulomb", this->coulomb_sensor_);
23  LOG_SENSOR(" ", "MOS Temperature", this->mos_temperature_sensor_);
24 }
25 
27  if (this->bat_num_ != line->bat_num) {
28  return;
29  }
30  if (this->voltage_sensor_ != nullptr) {
31  this->voltage_sensor_->publish_state(((float) line->volt) / 1000.0f);
32  }
33  if (this->current_sensor_ != nullptr) {
34  this->current_sensor_->publish_state(((float) line->curr) / 1000.0f);
35  }
36  if (this->temperature_sensor_ != nullptr) {
37  this->temperature_sensor_->publish_state(((float) line->tempr) / 1000.0f);
38  }
39  if (this->temperature_low_sensor_ != nullptr) {
40  this->temperature_low_sensor_->publish_state(((float) line->tlow) / 1000.0f);
41  }
42  if (this->temperature_high_sensor_ != nullptr) {
43  this->temperature_high_sensor_->publish_state(((float) line->thigh) / 1000.0f);
44  }
45  if (this->voltage_low_sensor_ != nullptr) {
46  this->voltage_low_sensor_->publish_state(((float) line->vlow) / 1000.0f);
47  }
48  if (this->voltage_high_sensor_ != nullptr) {
49  this->voltage_high_sensor_->publish_state(((float) line->vhigh) / 1000.0f);
50  }
51  if (this->coulomb_sensor_ != nullptr) {
52  this->coulomb_sensor_->publish_state(line->coulomb);
53  }
54  if (this->mos_temperature_sensor_ != nullptr) {
55  this->mos_temperature_sensor_->publish_state(((float) line->mostempr) / 1000.0f);
56  }
57 }
58 
59 } // namespace pylontech
60 } // namespace esphome
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
virtual void on_line_read(LineContents *line)