diff --git a/components/jk_bms/jk_bms.cpp b/components/jk_bms/jk_bms.cpp index cc1fea90..f5426076 100644 --- a/components/jk_bms/jk_bms.cpp +++ b/components/jk_bms/jk_bms.cpp @@ -359,7 +359,7 @@ void JkBms::on_status_data_(const std::vector &data) { } void JkBms::update() { - this->read_registers(FUNCTION_READ_ALL, ADDRESS_READ_ALL); + this->query_balancer_status(); if (this->enable_fake_traffic_) { // Start: 0x4E, 0x57, 0x01, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01 diff --git a/components/jk_modbus/jk_modbus.cpp b/components/jk_modbus/jk_modbus.cpp index 50578018..74630688 100644 --- a/components/jk_modbus/jk_modbus.cpp +++ b/components/jk_modbus/jk_modbus.cpp @@ -152,5 +152,19 @@ void JkModbus::read_registers(uint8_t function, uint8_t address) { this->flush(); } +void JkModbus::query_balancer_status() { + uint8_t frame[7]; + frame[0] = 0x55; + frame[1] = 0xAA; + frame[2] = 0x01; + frame[3] = 0xFF; + frame[4] = 0x00; + frame[5] = 0x00; + frame[6] = 0xFF; + + this->write_array(frame, 7); + this->flush(); +} + } // namespace jk_modbus } // namespace esphome diff --git a/components/jk_modbus/jk_modbus.h b/components/jk_modbus/jk_modbus.h index 96ee5f6d..9005a072 100644 --- a/components/jk_modbus/jk_modbus.h +++ b/components/jk_modbus/jk_modbus.h @@ -22,6 +22,7 @@ class JkModbus : public uart::UARTDevice, public Component { void send(uint8_t function, uint8_t address, uint8_t value); void read_registers(uint8_t function, uint8_t address); + void query_balancer_status(); protected: bool parse_jk_modbus_byte_(uint8_t byte); @@ -39,6 +40,7 @@ class JkModbusDevice { void send(int8_t function, uint8_t address, uint8_t value) { this->parent_->send(function, address, value); } void read_registers(uint8_t function, uint8_t address) { this->parent_->read_registers(function, address); } + void query_balancer_status() { this->parent_->query_balancer_status(); } protected: friend JkModbus; diff --git a/esp32-example.yaml b/esp32-example.yaml index 1d7641bb..6cf45d3d 100644 --- a/esp32-example.yaml +++ b/esp32-example.yaml @@ -1,6 +1,6 @@ substitutions: name: jk-bms - external_components_source: github://syssi/esphome-jk-bms@main + external_components_source: github://syssi/esphome-jk-bms@add-jk-balancer-support tx_pin: GPIO16 rx_pin: GPIO17 @@ -17,21 +17,24 @@ wifi: ssid: !secret wifi_ssid password: !secret wifi_password +api: ota: logger: - -mqtt: - broker: !secret mqtt_host - username: !secret mqtt_username - password: !secret mqtt_password - id: mqtt_client + level: DEBUG + logs: + api.service: WARN + ota: WARN + wifi: WARN + sensor: DEBUG uart: id: uart0 - baud_rate: 115200 + baud_rate: 9600 rx_buffer_size: 384 tx_pin: ${tx_pin} rx_pin: ${rx_pin} + debug: + direction: BOTH jk_modbus: id: modbus0 @@ -66,171 +69,3 @@ sensor: name: "${name} max voltage cell" delta_cell_voltage: name: "${name} delta cell voltage" - cell_voltage_1: - name: "${name} cell voltage 1" - cell_voltage_2: - name: "${name} cell voltage 2" - cell_voltage_3: - name: "${name} cell voltage 3" - cell_voltage_4: - name: "${name} cell voltage 4" - cell_voltage_5: - name: "${name} cell voltage 5" - cell_voltage_6: - name: "${name} cell voltage 6" - cell_voltage_7: - name: "${name} cell voltage 7" - cell_voltage_8: - name: "${name} cell voltage 8" - cell_voltage_9: - name: "${name} cell voltage 9" - cell_voltage_10: - name: "${name} cell voltage 10" - cell_voltage_11: - name: "${name} cell voltage 11" - cell_voltage_12: - name: "${name} cell voltage 12" - cell_voltage_13: - name: "${name} cell voltage 13" - cell_voltage_14: - name: "${name} cell voltage 14" - cell_voltage_15: - name: "${name} cell voltage 15" - cell_voltage_16: - name: "${name} cell voltage 16" - cell_voltage_17: - name: "${name} cell voltage 17" - cell_voltage_18: - name: "${name} cell voltage 18" - cell_voltage_19: - name: "${name} cell voltage 19" - cell_voltage_20: - name: "${name} cell voltage 20" - cell_voltage_21: - name: "${name} cell voltage 21" - cell_voltage_22: - name: "${name} cell voltage 22" - cell_voltage_23: - name: "${name} cell voltage 23" - cell_voltage_24: - name: "${name} cell voltage 24" - power_tube_temperature: - name: "${name} power tube temperature" - temperature_sensor_1: - name: "${name} temperature sensor 1" - temperature_sensor_2: - name: "${name} temperature sensor 2" - total_voltage: - name: "${name} total voltage" - current: - name: "${name} current" - # https://github.com/syssi/esphome-jk-bms/issues/40 - # filters: - # - multiply: -1 - capacity_remaining: - name: "${name} capacity remaining" - capacity_remaining_derived: - name: "${name} capacity remaining derived" - temperature_sensors: - name: "${name} temperature sensors" - charging_cycles: - name: "${name} charging cycles" - total_charging_cycle_capacity: - name: "${name} total charging cycle capacity" - battery_strings: - name: "${name} battery strings" - errors_bitmask: - name: "${name} errors bitmask" - operation_mode_bitmask: - name: "${name} operation mode bitmask" - total_voltage_overvoltage_protection: - name: "${name} total voltage overvoltage protection" - total_voltage_undervoltage_protection: - name: "${name} total voltage undervoltage protection" - cell_voltage_overvoltage_protection: - name: "${name} cell voltage overvoltage protection" - cell_voltage_overvoltage_recovery: - name: "${name} cell voltage overvoltage recovery" - cell_voltage_overvoltage_delay: - name: "${name} cell voltage overvoltage delay" - cell_voltage_undervoltage_protection: - name: "${name} cell voltage undervoltage protection" - cell_voltage_undervoltage_recovery: - name: "${name} cell voltage undervoltage recovery" - cell_voltage_undervoltage_delay: - name: "${name} cell voltage undervoltage delay" - cell_pressure_difference_protection: - name: "${name} cell pressure difference protection" - discharging_overcurrent_protection: - name: "${name} discharging overcurrent protection" - discharging_overcurrent_delay: - name: "${name} discharging overcurrent delay" - charging_overcurrent_protection: - name: "${name} charging overcurrent protection" - charging_overcurrent_delay: - name: "${name} charging overcurrent delay" - balance_starting_voltage: - name: "${name} balance starting voltage" - balance_opening_pressure_difference: - name: "${name} balance opening pressure difference" - power_tube_temperature_protection: - name: "${name} power tube temperature protection" - power_tube_temperature_recovery: - name: "${name} power tube temperature recovery" - temperature_sensor_temperature_protection: - name: "${name} temperature sensor temperature protection" - temperature_sensor_temperature_recovery: - name: "${name} temperature sensor temperature recovery" - temperature_sensor_temperature_difference_protection: - name: "${name} temperature sensor temperature difference protection" - charging_high_temperature_protection: - name: "${name} charging high temperature protection" - discharging_high_temperature_protection: - name: "${name} discharging high temperature protection" - charging_low_temperature_protection: - name: "${name} charging low temperature protection" - charging_low_temperature_recovery: - name: "${name} charging low temperature recovery" - discharging_low_temperature_protection: - name: "${name} discharging low temperature protection" - discharging_low_temperature_recovery: - name: "${name} discharging low temperature recovery" - total_battery_capacity_setting: - name: "${name} total battery capacity setting" - current_calibration: - name: "${name} current calibration" - device_address: - name: "${name} device address" - sleep_wait_time: - name: "${name} sleep wait time" - alarm_low_volume: - name: "${name} alarm low volume" - manufacturing_date: - name: "${name} manufacturing date" - total_runtime: - name: "${name} total runtime" -# start_current_calibration: -# name: "${name} start current calibration" - actual_battery_capacity: - name: "${name} actual battery capacity" -# protocol_version: -# name: "${name} protocol version" - -text_sensor: - - platform: jk_bms - errors: - name: "${name} errors" - operation_mode: - name: "${name} operation mode" - battery_type: - name: "${name} battery type" - password: - name: "${name} password" - device_type: - name: "${name} device type" - software_version: - name: "${name} software version" - manufacturer: - name: "${name} manufacturer" - total_runtime_formatted: - name: "${name} total runtime formatted" diff --git a/esp8266-example.yaml b/esp8266-example.yaml index e68434fc..5d0f5afb 100644 --- a/esp8266-example.yaml +++ b/esp8266-example.yaml @@ -1,6 +1,6 @@ substitutions: name: jk-bms - external_components_source: github://syssi/esphome-jk-bms@main + external_components_source: github://syssi/esphome-jk-bms@add-jk-balancer-support tx_pin: GPIO1 rx_pin: GPIO3 @@ -17,23 +17,25 @@ wifi: ssid: !secret wifi_ssid password: !secret wifi_password +api: ota: logger: baud_rate: 0 - level: INFO - -mqtt: - broker: !secret mqtt_host - username: !secret mqtt_username - password: !secret mqtt_password - id: mqtt_client + level: DEBUG + logs: + api.service: WARN + ota: WARN + wifi: WARN + sensor: DEBUG uart: id: uart0 - baud_rate: 115200 + baud_rate: 9600 rx_buffer_size: 384 tx_pin: ${tx_pin} rx_pin: ${rx_pin} + debug: + direction: BOTH jk_modbus: id: modbus0 @@ -68,171 +70,3 @@ sensor: name: "${name} max voltage cell" delta_cell_voltage: name: "${name} delta cell voltage" - cell_voltage_1: - name: "${name} cell voltage 1" - cell_voltage_2: - name: "${name} cell voltage 2" - cell_voltage_3: - name: "${name} cell voltage 3" - cell_voltage_4: - name: "${name} cell voltage 4" - cell_voltage_5: - name: "${name} cell voltage 5" - cell_voltage_6: - name: "${name} cell voltage 6" - cell_voltage_7: - name: "${name} cell voltage 7" - cell_voltage_8: - name: "${name} cell voltage 8" - cell_voltage_9: - name: "${name} cell voltage 9" - cell_voltage_10: - name: "${name} cell voltage 10" - cell_voltage_11: - name: "${name} cell voltage 11" - cell_voltage_12: - name: "${name} cell voltage 12" - cell_voltage_13: - name: "${name} cell voltage 13" - cell_voltage_14: - name: "${name} cell voltage 14" - cell_voltage_15: - name: "${name} cell voltage 15" - cell_voltage_16: - name: "${name} cell voltage 16" - cell_voltage_17: - name: "${name} cell voltage 17" - cell_voltage_18: - name: "${name} cell voltage 18" - cell_voltage_19: - name: "${name} cell voltage 19" - cell_voltage_20: - name: "${name} cell voltage 20" - cell_voltage_21: - name: "${name} cell voltage 21" - cell_voltage_22: - name: "${name} cell voltage 22" - cell_voltage_23: - name: "${name} cell voltage 23" - cell_voltage_24: - name: "${name} cell voltage 24" - power_tube_temperature: - name: "${name} power tube temperature" - temperature_sensor_1: - name: "${name} temperature sensor 1" - temperature_sensor_2: - name: "${name} temperature sensor 2" - total_voltage: - name: "${name} total voltage" - current: - name: "${name} current" - # https://github.com/syssi/esphome-jk-bms/issues/40 - # filters: - # - multiply: -1 - capacity_remaining: - name: "${name} capacity remaining" - capacity_remaining_derived: - name: "${name} capacity remaining derived" - temperature_sensors: - name: "${name} temperature sensors" - charging_cycles: - name: "${name} charging cycles" - total_charging_cycle_capacity: - name: "${name} total charging cycle capacity" - battery_strings: - name: "${name} battery strings" - errors_bitmask: - name: "${name} errors bitmask" - operation_mode_bitmask: - name: "${name} operation mode bitmask" - total_voltage_overvoltage_protection: - name: "${name} total voltage overvoltage protection" - total_voltage_undervoltage_protection: - name: "${name} total voltage undervoltage protection" - cell_voltage_overvoltage_protection: - name: "${name} cell voltage overvoltage protection" - cell_voltage_overvoltage_recovery: - name: "${name} cell voltage overvoltage recovery" - cell_voltage_overvoltage_delay: - name: "${name} cell voltage overvoltage delay" - cell_voltage_undervoltage_protection: - name: "${name} cell voltage undervoltage protection" - cell_voltage_undervoltage_recovery: - name: "${name} cell voltage undervoltage recovery" - cell_voltage_undervoltage_delay: - name: "${name} cell voltage undervoltage delay" - cell_pressure_difference_protection: - name: "${name} cell pressure difference protection" - discharging_overcurrent_protection: - name: "${name} discharging overcurrent protection" - discharging_overcurrent_delay: - name: "${name} discharging overcurrent delay" - charging_overcurrent_protection: - name: "${name} charging overcurrent protection" - charging_overcurrent_delay: - name: "${name} charging overcurrent delay" - balance_starting_voltage: - name: "${name} balance starting voltage" - balance_opening_pressure_difference: - name: "${name} balance opening pressure difference" - power_tube_temperature_protection: - name: "${name} power tube temperature protection" - power_tube_temperature_recovery: - name: "${name} power tube temperature recovery" - temperature_sensor_temperature_protection: - name: "${name} temperature sensor temperature protection" - temperature_sensor_temperature_recovery: - name: "${name} temperature sensor temperature recovery" - temperature_sensor_temperature_difference_protection: - name: "${name} temperature sensor temperature difference protection" - charging_high_temperature_protection: - name: "${name} charging high temperature protection" - discharging_high_temperature_protection: - name: "${name} discharging high temperature protection" - charging_low_temperature_protection: - name: "${name} charging low temperature protection" - charging_low_temperature_recovery: - name: "${name} charging low temperature recovery" - discharging_low_temperature_protection: - name: "${name} discharging low temperature protection" - discharging_low_temperature_recovery: - name: "${name} discharging low temperature recovery" - total_battery_capacity_setting: - name: "${name} total battery capacity setting" - current_calibration: - name: "${name} current calibration" - device_address: - name: "${name} device address" - sleep_wait_time: - name: "${name} sleep wait time" - alarm_low_volume: - name: "${name} alarm low volume" - manufacturing_date: - name: "${name} manufacturing date" - total_runtime: - name: "${name} total runtime" -# start_current_calibration: -# name: "${name} start current calibration" - actual_battery_capacity: - name: "${name} actual battery capacity" -# protocol_version: -# name: "${name} protocol version" - -text_sensor: - - platform: jk_bms - errors: - name: "${name} errors" - operation_mode: - name: "${name} operation mode" - battery_type: - name: "${name} battery type" - password: - name: "${name} password" - device_type: - name: "${name} device type" - software_version: - name: "${name} software version" - manufacturer: - name: "${name} manufacturer" - total_runtime_formatted: - name: "${name} total runtime formatted"