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