Fix current sensor (Closes: #13) (#14)

This commit is contained in:
Sebastian Muszynski
2023-02-08 23:20:20 +01:00
committed by GitHub
parent 7f35247eff
commit 224fffd0b6
4 changed files with 67 additions and 2 deletions

View File

@@ -101,6 +101,13 @@ void VotronicBle::update() {
// Battery computer status frame
this->on_votronic_ble_data_(0x22, {0xE8, 0x04, 0xBF, 0x04, 0x09, 0x01, 0x60, 0x00, 0x5F, 0x00,
0x9A, 0xFE, 0xFF, 0xF0, 0x0A, 0x5E, 0x14, 0x54, 0x02, 0x04});
// Battery computer status frame (max current: +8388.607 A)
this->on_votronic_ble_data_(0x22, {0xE8, 0x04, 0xBF, 0x04, 0x09, 0x01, 0x60, 0x00, 0x5F, 0x00,
0xFF, 0xFF, 0x7F, 0xF0, 0x0A, 0x5E, 0x14, 0x54, 0x02, 0x04});
// Battery computer status frame (min current: -8388.608 A)
this->on_votronic_ble_data_(0x22, {0xE8, 0x04, 0xBF, 0x04, 0x09, 0x01, 0x60, 0x00, 0x5F, 0x00,
0x00, 0x00, 0x80, 0xF0, 0x0A, 0x5E, 0x14, 0x54, 0x02, 0x04});
}
if (this->node_state != espbt::ClientState::ESTABLISHED) {
@@ -141,8 +148,13 @@ void VotronicBle::decode_battery_computer_data_(const std::vector<uint8_t> &data
auto votronic_get_16bit = [&](size_t i) -> uint16_t {
return (uint16_t(data[i + 1]) << 8) | (uint16_t(data[i + 0]) << 0);
};
auto votronic_get_24bit = [&](size_t i) -> uint32_t {
return (uint32_t(data[i + 2]) << 16) | (uint32_t(data[i + 1]) << 8) | (uint32_t(data[i + 0]) << 0);
uint32_t val = (uint32_t(data[i + 2]) << 16) | (uint32_t(data[i + 1]) << 8) | (uint32_t(data[i + 0]) << 0);
if (val & 0x800000) {
val |= ~0xffffff;
}
return val;
};
ESP_LOGI(TAG, "Battery computer data received");
@@ -158,7 +170,8 @@ void VotronicBle::decode_battery_computer_data_(const std::vector<uint8_t> &data
this->publish_state_(this->battery_capacity_sensor_, (float) votronic_get_16bit(4));
this->publish_state_(this->state_of_charge_sensor_, (float) data[8]);
float current = (float) ((int16_t) votronic_get_24bit(10)) * 0.001f;
float current = (float) ((int32_t) votronic_get_24bit(10)) * 0.001f;
ESP_LOGV(TAG, " Current (raw): 0x%02X%02X%02X (%.3f A)", data[12], data[11], data[10], current);
this->publish_state_(this->current_sensor_, current);
this->publish_state_(this->charging_binary_sensor_, (current > 0.0f));
this->publish_state_(this->discharging_binary_sensor_, (current < 0.0f));

View File

@@ -95,7 +95,30 @@
4A.05.BF.04.18.01.60.00.64.00.DE.FA.FF.F0.0A.5E.14.54.02.04
4A.05.BF.04.18.01.60.00.64.00.F6.FA.FF.F0.0A.5E.14.54.02.04
4E.05.BF.04.18.01.60.00.64.00.F6.FA.FF.F0.0A.5E.14.54.02.04
61.05.BF.04.18.01.60.00.64.00.01.15.00.F0.0A.5E.14.54.02.04
61.05.BF.04.18.01.60.00.64.00.61.15.00.F0.0A.5E.14.54.02.04
61.05.BF.04.18.01.60.00.64.00.E9.14.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.01.15.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.12.14.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.2A.14.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.31.15.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.42.14.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.49.15.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.4F.0F.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.5A.14.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.72.14.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.8A.14.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.9B.13.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.B3.13.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.B9.14.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.D1.14.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.E9.14.00.F0.0A.5E.14.54.02.04
63.05.BF.04.18.01.60.00.64.00.FA.13.00.F0.0A.5E.14.54.02.04
63.05.C3.04.18.01.60.00.64.00.2A.14.00.F0.0A.5E.14.54.02.04
63.05.C3.04.18.01.60.00.64.00.5A.14.00.F0.0A.5E.14.54.02.04
63.05.C3.04.18.01.60.00.64.00.72.14.00.F0.0A.5E.14.54.02.04
63.05.C3.04.18.01.60.00.64.00.B3.13.00.F0.0A.5E.14.54.02.04
63.05.C3.04.18.01.60.00.64.00.E9.14.00.F0.0A.5E.14.54.02.04
E6.04.BF.04.09.01.60.00.5F.00.82.FE.FF.F0.0A.5E.14.54.02.04
E6.04.BF.04.09.01.60.00.5F.00.9A.FE.FF.F0.0A.5E.14.54.02.04
E6.04.BF.04.09.01.60.00.5F.00.B2.FE.FF.F0.0A.5E.14.54.02.04

View File

@@ -141,6 +141,34 @@
4A.05.F0.07.02.00.00.00.00.14.56.00.09.14.00.1D.00.1C.00
4A.05.FA.07.02.00.00.00.00.14.56.00.09.14.00.1D.00.1C.00
4A.05.FE.07.02.00.00.00.00.14.56.00.09.14.00.1D.00.1C.00
61.05.38.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
61.05.3C.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.00.08.02.00.00.00.00.15.56.00.09.14.00.1D.00.1D.00
63.05.06.08.02.00.00.00.00.15.56.00.09.14.00.1D.00.1D.00
63.05.0E.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.2A.08.02.00.00.00.00.15.56.00.09.14.00.1D.00.1D.00
63.05.2C.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.2E.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.30.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.30.08.02.00.00.00.00.15.56.00.09.14.00.1D.00.1D.00
63.05.34.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.34.08.02.00.00.00.00.15.56.00.09.14.00.1D.00.1D.00
63.05.36.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.38.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.3A.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.3C.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.3E.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.40.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.42.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.44.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.48.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.4A.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.4E.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.50.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.52.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.54.08.01.00.00.00.00.15.56.00.09.14.00.1D.00.0E.00
63.05.AC.07.02.00.00.00.00.15.56.00.09.14.00.1D.00.1D.00
63.05.E6.07.02.00.00.00.00.15.56.00.09.14.00.1D.00.1D.00
E6.04.76.05.00.00.00.00.00.06.56.00.09.18.00.22.00.00.00
E8.04.74.05.00.00.00.00.00.06.56.00.09.18.00.22.00.00.00
E8.04.76.05.00.00.00.00.00.06.56.00.09.18.00.22.00.00.00

View File

@@ -3,5 +3,6 @@
votronic_ble:
- ble_client_id: client0
id: votronic0
throttle: 0ms
update_interval: 1s
enable_fake_traffic: true