ESPHome 2025.6.3
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 {
6namespace pylontech {
7
8static const char *const TAG = "pylontech.sensor";
9
10PylontechSensor::PylontechSensor(int8_t bat_num) { this->bat_num_ = bat_num; }
11
13 ESP_LOGCONFIG(TAG,
14 "Pylontech Sensor:\n"
15 " Battery %d",
16 this->bat_num_);
17 LOG_SENSOR(" ", "Voltage", this->voltage_sensor_);
18 LOG_SENSOR(" ", "Current", this->current_sensor_);
19 LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
20 LOG_SENSOR(" ", "Temperature low", this->temperature_low_sensor_);
21 LOG_SENSOR(" ", "Temperature high", this->temperature_high_sensor_);
22 LOG_SENSOR(" ", "Voltage low", this->voltage_low_sensor_);
23 LOG_SENSOR(" ", "Voltage high", this->voltage_high_sensor_);
24 LOG_SENSOR(" ", "Coulomb", this->coulomb_sensor_);
25 LOG_SENSOR(" ", "MOS Temperature", this->mos_temperature_sensor_);
26}
27
29 if (this->bat_num_ != line->bat_num) {
30 return;
31 }
32 if (this->voltage_sensor_ != nullptr) {
33 this->voltage_sensor_->publish_state(((float) line->volt) / 1000.0f);
34 }
35 if (this->current_sensor_ != nullptr) {
36 this->current_sensor_->publish_state(((float) line->curr) / 1000.0f);
37 }
38 if (this->temperature_sensor_ != nullptr) {
39 this->temperature_sensor_->publish_state(((float) line->tempr) / 1000.0f);
40 }
41 if (this->temperature_low_sensor_ != nullptr) {
42 this->temperature_low_sensor_->publish_state(((float) line->tlow) / 1000.0f);
43 }
44 if (this->temperature_high_sensor_ != nullptr) {
45 this->temperature_high_sensor_->publish_state(((float) line->thigh) / 1000.0f);
46 }
47 if (this->voltage_low_sensor_ != nullptr) {
48 this->voltage_low_sensor_->publish_state(((float) line->vlow) / 1000.0f);
49 }
50 if (this->voltage_high_sensor_ != nullptr) {
51 this->voltage_high_sensor_->publish_state(((float) line->vhigh) / 1000.0f);
52 }
53 if (this->coulomb_sensor_ != nullptr) {
54 this->coulomb_sensor_->publish_state(line->coulomb);
55 }
56 if (this->mos_temperature_sensor_ != nullptr) {
57 this->mos_temperature_sensor_->publish_state(((float) line->mostempr) / 1000.0f);
58 }
59}
60
61} // namespace pylontech
62} // namespace esphome
virtual void on_line_read(LineContents *line)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7