8static const double NTC_A = 0.0011591051055979914;
9static const double NTC_B = 0.00022878183547845582;
10static const double NTC_C = 1.0396291358342124e-07;
11static const float PULLUP_RESISTANCE = 10000.0f;
12static const uint16_t ADC_MAX = 1023;
14struct SunGTIL2Message {
16 uint8_t ac_waveform[277];
30 char serial_number[10];
35static const uint16_t MESSAGE_SIZE =
sizeof(SunGTIL2Message);
37static_assert(MESSAGE_SIZE == 350,
"Expected the message size to be 350 bytes");
48 return "Starting voltage too low";
58 if (adc_value >= ADC_MAX || adc_value == 0) {
62 float ntc_resistance = PULLUP_RESISTANCE / ((
static_cast<float>(ADC_MAX) / adc_value) - 1.0f);
63 double lr = log(
double(ntc_resistance));
64 double v = NTC_A + NTC_B * lr + NTC_C * lr * lr * lr;
65 return float(1.0 / v - 273.15);
79 memcpy(&msg, this->
rx_message_.data(), MESSAGE_SIZE);
82 if ((msg.end[0] != 0) || (msg.end[38] != 0x08))
85 ESP_LOGVV(TAG,
"Frequency raw value: %02x", msg.frequency);
86 ESP_LOGVV(TAG,
"Unknown values: %02x %02x %02x %02x %02x", msg.unknown1, msg.unknown2, msg.unknown3, msg.unknown4,
103#ifdef USE_TEXT_SENSOR
104 if (this->
state_ !=
nullptr) {
118 LOG_SENSOR(
"",
"AC Power", this->
ac_power_);
119 LOG_SENSOR(
"",
"DC Power", this->
dc_power_);
123#ifdef USE_TEXT_SENSOR
124 LOG_TEXT_SENSOR(
"",
"State", this->
state_);
void publish_state(float state)
Publish a new state to the front-end.
float calculate_temperature_(uint16_t adc_value)
static constexpr size_t STATE_BUFFER_SIZE
void handle_char_(uint8_t c)
text_sensor::TextSensor * state_
void dump_config() override
sensor::Sensor * dc_power_
text_sensor::TextSensor * serial_number_
sensor::Sensor * limiter_power_
std::vector< uint8_t > rx_message_
sensor::Sensor * dc_voltage_
const char * state_to_string_(uint8_t state, std::span< char, STATE_BUFFER_SIZE > buffer)
sensor::Sensor * ac_power_
sensor::Sensor * ac_voltage_
sensor::Sensor * temperature_
void publish_state(const std::string &state)
bool read_available(F &&on_byte)
Same as read_available_chunks(), calling on_byte(uint8_t) once per byte.
struct @66::@67 __attribute__
Wake the main loop task from an ISR. ISR-safe.
ESPHOME_LOG_TAG(TAG, "sun_gtil2")