mirror of
https://github.com/esphome/esphome.git
synced 2026-10-14 10:12:52 +00:00
[pipsolar] Add QET/QLT total energy sensors (#17347)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: J. Nick Koston <nick@home-assistant.io>
This commit is contained in:
co-authored by
Claude Opus 4.8
J. Nick Koston
parent
bea0ef264a
commit
2ab06fa937
@@ -286,6 +286,12 @@ void Pipsolar::handle_poll_response_(ENUMPollingCommand polling_command, const c
|
||||
case POLLING_QMN:
|
||||
handle_qmn_(message);
|
||||
break;
|
||||
case POLLING_QET:
|
||||
handle_single_int_(message, this->last_qet_, this->total_pv_generated_energy_);
|
||||
break;
|
||||
case POLLING_QLT:
|
||||
handle_single_int_(message, this->last_qlt_, this->total_output_load_energy_);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -688,6 +694,17 @@ void Pipsolar::handle_qmn_(const char *message) {
|
||||
}
|
||||
}
|
||||
|
||||
// QET and QLT each answer with one integer
|
||||
void Pipsolar::handle_single_int_(const char *message, text_sensor::TextSensor *raw, sensor::Sensor *value) {
|
||||
if (raw) {
|
||||
raw->publish_state(message);
|
||||
}
|
||||
|
||||
size_t pos = 0;
|
||||
this->skip_start_(message, &pos);
|
||||
this->read_int_sensor_(message, &pos, value);
|
||||
}
|
||||
|
||||
void Pipsolar::skip_start_(const char *message, size_t *pos) {
|
||||
if (message[*pos] == '(') {
|
||||
(*pos)++;
|
||||
|
||||
@@ -19,6 +19,8 @@ enum ENUMPollingCommand {
|
||||
POLLING_QPIWS = 4,
|
||||
POLLING_QT = 5,
|
||||
POLLING_QMN = 6,
|
||||
POLLING_QET = 7,
|
||||
POLLING_QLT = 8,
|
||||
};
|
||||
struct PollingCommand {
|
||||
uint8_t *command;
|
||||
@@ -116,6 +118,12 @@ class Pipsolar final : public uart::UARTDevice, public PollingComponent {
|
||||
PIPSOLAR_SENSOR(pv_ok_condition_for_parallel, QPIRI)
|
||||
PIPSOLAR_SENSOR(pv_power_balance, QPIRI)
|
||||
|
||||
// QET value
|
||||
PIPSOLAR_SENSOR(total_pv_generated_energy, QET)
|
||||
|
||||
// QLT value
|
||||
PIPSOLAR_SENSOR(total_output_load_energy, QLT)
|
||||
|
||||
// QMOD values
|
||||
PIPSOLAR_TEXT_SENSOR(device_mode, QMOD)
|
||||
|
||||
@@ -175,6 +183,8 @@ class Pipsolar final : public uart::UARTDevice, public PollingComponent {
|
||||
PIPSOLAR_TEXT_SENSOR(last_qpiws, QPIWS)
|
||||
PIPSOLAR_TEXT_SENSOR(last_qt, QT)
|
||||
PIPSOLAR_TEXT_SENSOR(last_qmn, QMN)
|
||||
PIPSOLAR_TEXT_SENSOR(last_qet, QET)
|
||||
PIPSOLAR_TEXT_SENSOR(last_qlt, QLT)
|
||||
|
||||
PIPSOLAR_SWITCH(output_source_priority_utility_switch, QPIRI)
|
||||
PIPSOLAR_SWITCH(output_source_priority_solar_switch, QPIRI)
|
||||
@@ -213,6 +223,7 @@ class Pipsolar final : public uart::UARTDevice, public PollingComponent {
|
||||
void handle_qpiws_(const char *message);
|
||||
void handle_qt_(const char *message);
|
||||
void handle_qmn_(const char *message);
|
||||
void handle_single_int_(const char *message, text_sensor::TextSensor *raw, sensor::Sensor *value);
|
||||
|
||||
void skip_start_(const char *message, size_t *pos);
|
||||
void skip_field_(const char *message, size_t *pos);
|
||||
|
||||
@@ -8,6 +8,7 @@ from esphome.const import (
|
||||
DEVICE_CLASS_APPARENT_POWER,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_CURRENT,
|
||||
DEVICE_CLASS_ENERGY,
|
||||
DEVICE_CLASS_FREQUENCY,
|
||||
DEVICE_CLASS_POWER,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
@@ -17,6 +18,7 @@ from esphome.const import (
|
||||
ICON_FLASH,
|
||||
ICON_GAUGE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
UNIT_AMPERE,
|
||||
UNIT_CELSIUS,
|
||||
UNIT_HERTZ,
|
||||
@@ -24,6 +26,7 @@ from esphome.const import (
|
||||
UNIT_VOLT,
|
||||
UNIT_VOLT_AMPS,
|
||||
UNIT_WATT,
|
||||
UNIT_WATT_HOURS,
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
@@ -80,6 +83,10 @@ CONF_BATTERY_VOLTAGE_OFFSET_FOR_FANS_ON = "battery_voltage_offset_for_fans_on"
|
||||
CONF_EEPROM_VERSION = "eeprom_version"
|
||||
CONF_PV_CHARGING_POWER = "pv_charging_power"
|
||||
|
||||
# QET / QLT sensors
|
||||
CONF_TOTAL_PV_GENERATED_ENERGY = "total_pv_generated_energy"
|
||||
CONF_TOTAL_OUTPUT_LOAD_ENERGY = "total_output_load_energy"
|
||||
|
||||
TYPES = {
|
||||
CONF_GRID_RATING_VOLTAGE: sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_VOLT,
|
||||
@@ -319,6 +326,18 @@ TYPES = {
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
CONF_TOTAL_PV_GENERATED_ENERGY: sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_WATT_HOURS,
|
||||
accuracy_decimals=0,
|
||||
device_class=DEVICE_CLASS_ENERGY,
|
||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||
),
|
||||
CONF_TOTAL_OUTPUT_LOAD_ENERGY: sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_WATT_HOURS,
|
||||
accuracy_decimals=0,
|
||||
device_class=DEVICE_CLASS_ENERGY,
|
||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||
),
|
||||
}
|
||||
|
||||
CONFIG_SCHEMA = PIPSOLAR_COMPONENT_SCHEMA.extend(
|
||||
|
||||
@@ -15,6 +15,8 @@ CONF_LAST_QFLAG = "last_qflag"
|
||||
CONF_LAST_QPIWS = "last_qpiws"
|
||||
CONF_LAST_QT = "last_qt"
|
||||
CONF_LAST_QMN = "last_qmn"
|
||||
CONF_LAST_QET = "last_qet"
|
||||
CONF_LAST_QLT = "last_qlt"
|
||||
|
||||
TYPES = [
|
||||
CONF_DEVICE_MODE,
|
||||
@@ -25,6 +27,8 @@ TYPES = [
|
||||
CONF_LAST_QPIWS,
|
||||
CONF_LAST_QT,
|
||||
CONF_LAST_QMN,
|
||||
CONF_LAST_QET,
|
||||
CONF_LAST_QLT,
|
||||
]
|
||||
|
||||
CONFIG_SCHEMA = PIPSOLAR_COMPONENT_SCHEMA.extend(
|
||||
|
||||
@@ -204,6 +204,12 @@ sensor:
|
||||
pv_charging_power:
|
||||
id: inverter0_pv_charging_power
|
||||
name: inverter0_pv_charging_power
|
||||
total_pv_generated_energy:
|
||||
id: inverter0_total_pv_generated_energy
|
||||
name: inverter0_total_pv_generated_energy
|
||||
total_output_load_energy:
|
||||
id: inverter0_total_output_load_energy
|
||||
name: inverter0_total_output_load_energy
|
||||
|
||||
switch:
|
||||
- platform: pipsolar
|
||||
@@ -241,3 +247,9 @@ text_sensor:
|
||||
last_qflag:
|
||||
id: inverter0_last_qflag
|
||||
name: inverter0_last_qflag
|
||||
last_qet:
|
||||
id: inverter0_last_qet
|
||||
name: inverter0_last_qet
|
||||
last_qlt:
|
||||
id: inverter0_last_qlt
|
||||
name: inverter0_last_qlt
|
||||
|
||||
Reference in New Issue
Block a user