Expose capacity details as sensors (Closes: #36) (#38)

This commit is contained in:
Sebastian Muszynski
2023-04-21 11:01:01 +02:00
committed by GitHub
parent c8b4959c63
commit d99d9b029b
16 changed files with 63 additions and 31 deletions

View File

@@ -29,7 +29,7 @@ CODEOWNERS = ["@syssi"]
# CONF_BATTERY_VOLTAGE = "battery_voltage"
CONF_SECONDARY_BATTERY_VOLTAGE = "secondary_battery_voltage"
CONF_BATTERY_CAPACITY = "battery_capacity"
CONF_BATTERY_CAPACITY_REMAINING = "battery_capacity_remaining"
CONF_STATE_OF_CHARGE = "state_of_charge"
# CONF_CURRENT = "current"
CONF_BATTERY_NOMINAL_CAPACITY = "battery_nominal_capacity"
@@ -44,8 +44,11 @@ CONF_PV_POWER = "pv_power"
CONF_CHARGING_MODE_SETTING_ID = "charging_mode_setting_id"
CONF_CONTROLLER_TEMPERATURE = "controller_temperature"
ICON_CURRENT_DC = "mdi:current-dc"
ICON_BATTERY_CAPACITY_REMAINING = "mdi:battery-50"
ICON_STATE_OF_CHARGE = "mdi:battery-50"
ICON_CURRENT_DC = "mdi:current-dc"
ICON_BATTERY_NOMINAL_CAPACITY = "mdi:battery"
ICON_BATTERY_STATUS_BITMASK = "mdi:alert-circle-outline"
ICON_CHARGING_CONTROLLER_STATUS_BITMASK = "mdi:alert-circle-outline"
ICON_PV_CONTROLLER_STATUS_BITMASK = "mdi:alert-circle-outline"
@@ -56,9 +59,11 @@ UNIT_AMPERE_HOURS = "Ah"
SENSORS = [
CONF_BATTERY_VOLTAGE,
CONF_SECONDARY_BATTERY_VOLTAGE,
CONF_BATTERY_CAPACITY_REMAINING,
CONF_STATE_OF_CHARGE,
CONF_CURRENT,
CONF_POWER,
CONF_BATTERY_NOMINAL_CAPACITY,
CONF_PV_VOLTAGE,
CONF_PV_CURRENT,
CONF_PV_POWER,
@@ -86,6 +91,13 @@ CONFIG_SCHEMA = cv.Schema(
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_BATTERY_CAPACITY_REMAINING): sensor.sensor_schema(
unit_of_measurement=UNIT_AMPERE_HOURS,
icon=ICON_BATTERY_CAPACITY_REMAINING,
accuracy_decimals=0,
device_class=DEVICE_CLASS_EMPTY,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_STATE_OF_CHARGE): sensor.sensor_schema(
unit_of_measurement=UNIT_PERCENT,
icon=ICON_STATE_OF_CHARGE,
@@ -107,6 +119,13 @@ CONFIG_SCHEMA = cv.Schema(
device_class=DEVICE_CLASS_POWER,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_BATTERY_NOMINAL_CAPACITY): sensor.sensor_schema(
unit_of_measurement=UNIT_AMPERE_HOURS,
icon=ICON_BATTERY_NOMINAL_CAPACITY,
accuracy_decimals=1,
device_class=DEVICE_CLASS_EMPTY,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_PV_VOLTAGE): sensor.sensor_schema(
unit_of_measurement=UNIT_VOLT,
icon=ICON_EMPTY,

View File

@@ -272,7 +272,7 @@ void Votronic::decode_battery_computer_info1_data_(const std::vector<uint8_t> &d
// 4 2 0x0F 0x05 Second Battery Voltage
this->publish_state_(this->secondary_battery_voltage_sensor_, votronic_get_16bit(4) * 0.01f);
// 6 2 0xC7 0x01
ESP_LOGI(TAG_INFO1, "Capacity remaining: %.0f Ah", votronic_get_16bit(6) * 1.0f);
this->publish_state_(this->battery_capacity_remaining_sensor_, votronic_get_16bit(6) * 1.0f);
// 8 2 0x20 0x00
ESP_LOGD(TAG_INFO1, "Byte 8-9: 0x%02X 0x%02X / %d %d / %d", data[8], data[9], data[8], data[9],
votronic_get_16bit(8));
@@ -317,7 +317,7 @@ void Votronic::decode_battery_computer_info2_data_(const std::vector<uint8_t> &d
ESP_LOGD(TAG_INFO2, "Byte 4-5: 0x%02X 0x%02X / %d %d / %d", data[4], data[5], data[4], data[5],
votronic_get_16bit(4));
// 6 2 0xF8 0x11
ESP_LOGI(TAG_INFO2, "Nominal capacity: %.1f Ah", votronic_get_16bit(6) * 0.1f);
this->publish_state_(this->battery_nominal_capacity_sensor_, votronic_get_16bit(6) * 0.1f);
// 8 2 0x5E 0x07
ESP_LOGD(TAG_INFO2, "Byte 8-9: 0x%02X 0x%02X / %d %d / %d", data[8], data[9], data[8], data[9],
votronic_get_16bit(8));
@@ -401,9 +401,11 @@ void Votronic::dump_config() {
LOG_SENSOR("", "Battery voltage", this->battery_voltage_sensor_);
LOG_SENSOR("", "Secondary battery voltage", this->secondary_battery_voltage_sensor_);
LOG_SENSOR("", "Battery capacity remaining", this->battery_capacity_remaining_sensor_);
LOG_SENSOR("", "State of charge", this->state_of_charge_sensor_);
LOG_SENSOR("", "Current", this->current_sensor_);
LOG_SENSOR("", "Power", this->power_sensor_);
LOG_SENSOR("", "Battery nominal capacity", this->battery_nominal_capacity_sensor_);
LOG_SENSOR("", "PV voltage", this->pv_voltage_sensor_);
LOG_SENSOR("", "PV current", this->pv_current_sensor_);
LOG_SENSOR("", "PV power", this->pv_power_sensor_);

View File

@@ -61,6 +61,12 @@ class Votronic : public uart::UARTDevice, public PollingComponent {
void set_controller_temperature_sensor(sensor::Sensor *controller_temperature_sensor) {
controller_temperature_sensor_ = controller_temperature_sensor;
}
void set_battery_capacity_remaining_sensor(sensor::Sensor *battery_capacity_remaining_sensor) {
battery_capacity_remaining_sensor_ = battery_capacity_remaining_sensor;
}
void set_battery_nominal_capacity_sensor(sensor::Sensor *battery_nominal_capacity_sensor) {
battery_nominal_capacity_sensor_ = battery_nominal_capacity_sensor;
}
void set_battery_status_text_sensor(text_sensor::TextSensor *battery_status_text_sensor) {
battery_status_text_sensor_ = battery_status_text_sensor;
@@ -99,6 +105,8 @@ class Votronic : public uart::UARTDevice, public PollingComponent {
sensor::Sensor *pv_controller_status_bitmask_sensor_;
sensor::Sensor *charging_mode_setting_id_sensor_;
sensor::Sensor *controller_temperature_sensor_;
sensor::Sensor *battery_capacity_remaining_sensor_;
sensor::Sensor *battery_nominal_capacity_sensor_;
text_sensor::TextSensor *battery_status_text_sensor_;
text_sensor::TextSensor *charging_controller_status_text_sensor_;

View File

@@ -28,7 +28,7 @@ CODEOWNERS = ["@syssi"]
# CONF_BATTERY_VOLTAGE = "battery_voltage"
CONF_SECONDARY_BATTERY_VOLTAGE = "secondary_battery_voltage"
CONF_BATTERY_CAPACITY = "battery_capacity"
CONF_BATTERY_CAPACITY_REMAINING = "battery_capacity_remaining"
CONF_STATE_OF_CHARGE = "state_of_charge"
# CONF_CURRENT = "current"
CONF_BATTERY_NOMINAL_CAPACITY = "battery_nominal_capacity"
@@ -40,12 +40,9 @@ CONF_CHARGED_CAPACITY = "charged_capacity"
CONF_CHARGED_ENERGY = "charged_energy"
CONF_PV_POWER = "pv_power"
ICON_CURRENT_DC = "mdi:current-dc"
UNIT_AMPERE_HOURS = "Ah"
ICON_BATTERY_CAPACITY = "mdi:battery-50"
ICON_BATTERY_CAPACITY_REMAINING = "mdi:battery-50"
ICON_STATE_OF_CHARGE = "mdi:battery-50"
ICON_CURRENT_DC = "mdi:current-dc"
ICON_BATTERY_NOMINAL_CAPACITY = "mdi:battery"
ICON_BATTERY_STATUS_BITMASK = "mdi:alert-circle-outline"
@@ -55,10 +52,12 @@ ICON_CHARGED_CAPACITY = "mdi:battery-charging"
ICON_CHARGING_CYCLES = "mdi:battery-sync"
ICON_ERRORS_BITMASK = "mdi:alert-circle-outline"
UNIT_AMPERE_HOURS = "Ah"
SENSORS = [
CONF_BATTERY_VOLTAGE,
CONF_SECONDARY_BATTERY_VOLTAGE,
CONF_BATTERY_CAPACITY,
CONF_BATTERY_CAPACITY_REMAINING,
CONF_STATE_OF_CHARGE,
CONF_CURRENT,
CONF_POWER,
@@ -89,9 +88,9 @@ CONFIG_SCHEMA = cv.Schema(
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_BATTERY_CAPACITY): sensor.sensor_schema(
cv.Optional(CONF_BATTERY_CAPACITY_REMAINING): sensor.sensor_schema(
unit_of_measurement=UNIT_AMPERE_HOURS,
icon=ICON_BATTERY_CAPACITY,
icon=ICON_BATTERY_CAPACITY_REMAINING,
accuracy_decimals=0,
device_class=DEVICE_CLASS_EMPTY,
state_class=STATE_CLASS_MEASUREMENT,

View File

@@ -23,7 +23,7 @@ void VotronicBle::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t
this->publish_state_(this->battery_voltage_sensor_, NAN);
this->publish_state_(this->secondary_battery_voltage_sensor_, NAN);
this->publish_state_(this->battery_capacity_sensor_, NAN);
this->publish_state_(this->battery_capacity_remaining_sensor_, NAN);
this->publish_state_(this->state_of_charge_sensor_, NAN);
this->publish_state_(this->current_sensor_, NAN);
this->publish_state_(this->power_sensor_, NAN);
@@ -149,7 +149,7 @@ void VotronicBle::decode_battery_computer_data_(const std::vector<uint8_t> &data
float battery_voltage = votronic_get_16bit(0) * 0.01f;
this->publish_state_(this->battery_voltage_sensor_, battery_voltage);
this->publish_state_(this->secondary_battery_voltage_sensor_, votronic_get_16bit(2) * 0.01f);
this->publish_state_(this->battery_capacity_sensor_, (float) votronic_get_16bit(4));
this->publish_state_(this->battery_capacity_remaining_sensor_, (float) votronic_get_16bit(4));
this->publish_state_(this->state_of_charge_sensor_, (float) data[8]);
float current = votronic_get_24bit_signed(10) * 0.001f;
@@ -218,7 +218,7 @@ void VotronicBle::dump_config() {
LOG_SENSOR("", "Battery voltage", this->battery_voltage_sensor_);
LOG_SENSOR("", "Secondary battery voltage", this->secondary_battery_voltage_sensor_);
LOG_SENSOR("", "Battery capacity", this->battery_capacity_sensor_);
LOG_SENSOR("", "Battery capacity remaining", this->battery_capacity_remaining_sensor_);
LOG_SENSOR("", "State of charge", this->state_of_charge_sensor_);
LOG_SENSOR("", "Current", this->current_sensor_);
LOG_SENSOR("", "Power", this->power_sensor_);

View File

@@ -47,8 +47,8 @@ class VotronicBle : public esphome::ble_client::BLEClientNode, public PollingCom
void set_secondary_battery_voltage_sensor(sensor::Sensor *secondary_battery_voltage_sensor) {
secondary_battery_voltage_sensor_ = secondary_battery_voltage_sensor;
}
void set_battery_capacity_sensor(sensor::Sensor *battery_capacity_sensor) {
battery_capacity_sensor_ = battery_capacity_sensor;
void set_battery_capacity_remaining_sensor(sensor::Sensor *battery_capacity_remaining_sensor) {
battery_capacity_remaining_sensor_ = battery_capacity_remaining_sensor;
}
void set_state_of_charge_sensor(sensor::Sensor *state_of_charge_sensor) {
state_of_charge_sensor_ = state_of_charge_sensor;
@@ -93,7 +93,7 @@ class VotronicBle : public esphome::ble_client::BLEClientNode, public PollingCom
sensor::Sensor *battery_voltage_sensor_;
sensor::Sensor *secondary_battery_voltage_sensor_;
sensor::Sensor *battery_capacity_sensor_;
sensor::Sensor *battery_capacity_remaining_sensor_;
sensor::Sensor *state_of_charge_sensor_;
sensor::Sensor *current_sensor_;
sensor::Sensor *power_sensor_;

View File

@@ -9,7 +9,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-votronic"
version: 1.1.0
version: 2.0.0
esp32:
board: wemos_d1_mini32
@@ -87,8 +87,8 @@ sensor:
name: "${name} battery voltage"
secondary_battery_voltage:
name: "${name} secondary battery voltage"
battery_capacity:
name: "${name} battery capacity"
battery_capacity_remaining:
name: "${name} battery capacity remaining"
state_of_charge:
name: "${name} state of charge"
current:

View File

@@ -7,7 +7,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-votronic"
version: 1.1.0
version: 2.0.0
esp32:
board: wemos_d1_mini32

View File

@@ -11,7 +11,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-votronic"
version: 1.1.0
version: 2.0.0
esp8266:
board: d1_mini

View File

@@ -11,7 +11,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-votronic"
version: 1.1.0
version: 2.0.0
esp8266:
board: d1_mini

View File

@@ -11,7 +11,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-votronic"
version: 1.1.0
version: 2.0.0
esp8266:
board: d1_mini
@@ -63,10 +63,14 @@ sensor:
name: "${name} battery voltage"
secondary_battery_voltage:
name: "${name} secondary battery voltage"
battery_capacity_remaining:
name: "${name} battery capacity remaining"
current:
name: "${name} current"
power:
name: "${name} power"
battery_nominal_capacity:
name: "${name} battery nominal capacity"
state_of_charge:
name: "${name} state of charge"
charging_mode_setting_id:

View File

@@ -11,7 +11,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-votronic"
version: 1.1.0
version: 2.0.0
esp8266:
board: d1_mini

View File

@@ -9,7 +9,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-votronic"
version: 1.1.0
version: 2.0.0
esp8266:
board: d1_mini

View File

@@ -9,7 +9,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-votronic"
version: 1.1.0
version: 2.0.0
esp8266:
board: d1_mini

View File

@@ -9,7 +9,7 @@ esphome:
comment: ${device_description}
project:
name: "syssi.esphome-votronic"
version: 1.1.0
version: 2.0.0
esp8266:
board: d1_mini

View File

@@ -70,7 +70,7 @@ esphome run esp32-ble-example.yaml
```
# Battery computer
[sensor:127]: 'votronic battery capacity': Sending state 265.00000 Ah with 0 decimals of accuracy
[sensor:127]: 'votronic battery capacity remaining': Sending state 265.00000 Ah with 0 decimals of accuracy
[sensor:127]: 'votronic state of charge': Sending state 95.00000 % with 0 decimals of accuracy
[sensor:127]: 'votronic current': Sending state -0.35800 A with 3 decimals of accuracy
[binary_sensor:036]: 'votronic charging': Sending state OFF