syssi / esphome-jbd-bms

ESPHome component to monitor and control a Xiaoxiang Battery Management System (JBD-BMS) via UART-TTL or BLE
Apache License 2.0
102 stars 28 forks source link

Add reset ESP button #69

Closed hddmax closed 7 months ago

hddmax commented 8 months ago

can you add the reset buton ?

i have tried it to add id but it doesnt work.

button:

syssi commented 7 months ago

Please try a clean build. It should just work!

hddmax commented 7 months ago

Screenshot 2024-01-28 104533 i tried it but it doesnt work ? hmmm

Compiling .pioenvs/jbd-bms-ble/src/main.o Linking .pioenvs/jbd-bms-ble/firmware.elf /data/cache/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/jbd-bms-ble/src/esphome/components/api/api_connection.o:(.literal._ZN7esphome3api13APIConnection14button_commandERKNS0_20ButtonCommandRequestE+0x0): undefined reference to esphome::button::Button::press()' /data/cache/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/jbd-bms-ble/src/esphome/components/api/api_connection.o: in functionesphome::api::APIConnection::button_command(esphome::api::ButtonCommandRequest const&)': /data/build/jbd-bms-ble/src/esphome/components/api/api_connection.cpp:795: undefined reference to esphome::button::Button::press()' /data/cache/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/jbd-bms-ble/src/main.o:(.literal._Z5setupv+0x760): undefined reference tovtable for esphome::restart::RestartButton' /data/cache/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/jbd-bms-ble/src/main.o:(.literal._Z5setupv+0x764): undefined reference to `vtable for esphome::restart::RestartButton' collect2: error: ld returned 1 exit status *** [.pioenvs/jbd-bms-ble/firmware.elf] Error 1 ========================= [FAILED] Took 79.24 seconds =========================

syssi commented 7 months ago

Is this a clean build for sure? Please provide your complete YAML configuration. I would like to reproduce the build issue locally. If you use the command line interface a clean build looks like this:

esphome clean yourconfig.yaml
esphome run yourconfig.yaml

If you use Home Assistant or the ESPHome Dashboard there is a clean button somewhere if you select the ESPHome node (tile).

hddmax commented 7 months ago

yes i did a clean yaml over HA,

here the full code:

substitutions:
  name: jbd-bms-ble
  bms0: "${name} bms0"
  bms1: "${name} bms1"
  bms2: "${name} bms2"
  external_components_source: github://syssi/esphome-jbd-bms@main
  bms0_mac_address: A4:C1:38:2A:95:DB
  bms1_mac_address: A4:C1:38:A2:EA:D8
  bms2_mac_address: A4:C1:38:E6:3F:18

esphome:
  name: ${name}

esp32:
  board: esp32dev
  framework:
    type: esp-idf

external_components:
  - source: ${external_components_source}
    refresh: 0s

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

ota:
  password: "xxxxx"

logger:
  level: DEBUG

api:

esp32_ble_tracker:
  on_ble_advertise:
    then:
      - lambda: |-
          if (x.get_name().rfind("xiaoxiang", 0) == 0) {
            ESP_LOGI("ble_adv", "New JBD-BMS found");
            ESP_LOGI("ble_adv", "  Name: %s", x.get_name().c_str());
            ESP_LOGI("ble_adv", "  MAC address: %s", x.address_str().c_str());
            ESP_LOGD("ble_adv", "  Advertised service UUIDs:");
            for (auto uuid : x.get_service_uuids()) {
              ESP_LOGD("ble_adv", "    - %s", uuid.to_string().c_str());
            }
          }

ble_client:
  - mac_address: ${bms0_mac_address}
    id: client0
  - mac_address: ${bms1_mac_address}
    id: client1
  - mac_address: ${bms2_mac_address}
    id: client2

jbd_bms_ble:
  - id: bms0
    ble_client_id: client0
    update_interval: 15s
  - id: bms1
    ble_client_id: client1
    update_interval: 15s
  - id: bms2
    ble_client_id: client2
    update_interval: 15s

binary_sensor:
  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms0
    balancing:
      name: "${bms0} balancing"
    charging:
      name: "${bms0} charging"
    discharging:
      name: "${bms0} discharging"
    online_status:
      name: "${bms0} online status"

  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms1
    balancing:
      name: "${bms1} balancing"
    charging:
      name: "${bms1} charging"
    discharging:
      name: "${bms1} discharging"
    online_status:
      name: "${bms1} online status"

  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms2
    balancing:
      name: "${bms2} balancing"
    charging:
      name: "${bms2} charging"
    discharging:
      name: "${bms2} discharging"
    online_status:
      name: "${bms2} online status"    

sensor:
  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms0
    battery_strings:
      name: "${bms0} battery strings"
    current:
      name: "${bms0} current"
    power:
      name: "${bms0} power"
    charging_power:
      name: "${bms0} charging power"
    discharging_power:
      name: "${bms0} discharging power"
    state_of_charge:
      name: "${bms0} state of charge"
    nominal_capacity:
      name: "${bms0} nominal capacity"
    charging_cycles:
      name: "${bms0} charging cycles"
    capacity_remaining:
      name: "${bms0} capacity remaining"
    battery_cycle_capacity:
      name: "${bms0} battery cycle capacity"
    total_voltage:
      name: "${bms0} total voltage"
    average_cell_voltage:
      name: "${bms0} average cell voltage"
    delta_cell_voltage:
      name: "${bms0} delta cell voltage"
    min_cell_voltage:
      name: "${bms0} min cell voltage"
    max_cell_voltage:
      name: "${bms0} max cell voltage"
    temperature_1:
      name: "${bms0} temperature 1"
    cell_voltage_1:
      name: "${bms0} cell voltage 1"
    cell_voltage_2:
      name: "${bms0} cell voltage 2"
    cell_voltage_3:
      name: "${bms0} cell voltage 3"
    cell_voltage_4:
      name: "${bms0} cell voltage 4"
    cell_voltage_5:
      name: "${bms0} cell voltage 5"
    cell_voltage_6:
      name: "${bms0} cell voltage 6"
    cell_voltage_7:
      name: "${bms0} cell voltage 7"
    cell_voltage_8:
      name: "${bms0} cell voltage 8"
    cell_voltage_9:
      name: "${bms0} cell voltage 9"
    cell_voltage_10:
      name: "${bms0} cell voltage 10"
    cell_voltage_11:
      name: "${bms0} cell voltage 11"
    cell_voltage_12:
      name: "${bms0} cell voltage 12"
    cell_voltage_13:
      name: "${bms0} cell voltage 13"
    cell_voltage_14:
      name: "${bms0} cell voltage 14"
    cell_voltage_15:
      name: "${bms0} cell voltage 15"
    cell_voltage_16:
      name: "${bms0} cell voltage 16"
    operation_status_bitmask:
      name: "${bms0} operation status bitmask"
    errors_bitmask:
      name: "${bms0} errors bitmask"
    balancer_status_bitmask:
      name: "${bms0} balancer status bitmask"
    software_version:
      name: "${bms0} software version"

  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms1
    battery_strings:
      name: "${bms1} battery strings"
    current:
      name: "${bms1} current"
    power:
      name: "${bms1} power"
    charging_power:
      name: "${bms1} charging power"
    discharging_power:
      name: "${bms1} discharging power"
    state_of_charge:
      name: "${bms1} state of charge"
    nominal_capacity:
      name: "${bms1} nominal capacity"
    charging_cycles:
      name: "${bms1} charging cycles"
    capacity_remaining:
      name: "${bms1} capacity remaining"
    battery_cycle_capacity:
      name: "${bms1} battery cycle capacity"
    total_voltage:
      name: "${bms1} total voltage"
    average_cell_voltage:
      name: "${bms1} average cell voltage"
    delta_cell_voltage:
      name: "${bms1} delta cell voltage"
    min_cell_voltage:
      name: "${bms1} min cell voltage"
    max_cell_voltage:
      name: "${bms1} max cell voltage"
    temperature_1:
      name: "${bms1} temperature 1"
    cell_voltage_1:
      name: "${bms1} cell voltage 1"
    cell_voltage_2:
      name: "${bms1} cell voltage 2"
    cell_voltage_3:
      name: "${bms1} cell voltage 3"
    cell_voltage_4:
      name: "${bms1} cell voltage 4"
    cell_voltage_5:
      name: "${bms1} cell voltage 5"
    cell_voltage_6:
      name: "${bms1} cell voltage 6"
    cell_voltage_7:
      name: "${bms1} cell voltage 7"
    cell_voltage_8:
      name: "${bms1} cell voltage 8"
    cell_voltage_9:
      name: "${bms1} cell voltage 9"
    cell_voltage_10:
      name: "${bms1} cell voltage 10"
    cell_voltage_11:
      name: "${bms1} cell voltage 11"
    cell_voltage_12:
      name: "${bms1} cell voltage 12"
    cell_voltage_13:
      name: "${bms1} cell voltage 13"
    cell_voltage_14:
      name: "${bms1} cell voltage 14"
    cell_voltage_15:
      name: "${bms1} cell voltage 15"
    cell_voltage_16:
      name: "${bms1} cell voltage 16"
    operation_status_bitmask:
      name: "${bms1} operation status bitmask"
    errors_bitmask:
      name: "${bms1} errors bitmask"
    balancer_status_bitmask:
      name: "${bms1} balancer status bitmask"
    software_version:
      name: "${bms1} software version"

  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms2
    battery_strings:
      name: "${bms2} battery strings"
    current:
      name: "${bms2} current"
    power:
      name: "${bms2} power"
    charging_power:
      name: "${bms2} charging power"
    discharging_power:
      name: "${bms2} discharging power"
    state_of_charge:
      name: "${bms2} state of charge"
    nominal_capacity:
      name: "${bms2} nominal capacity"
    charging_cycles:
      name: "${bms2} charging cycles"
    capacity_remaining:
      name: "${bms2} capacity remaining"
    battery_cycle_capacity:
      name: "${bms2} battery cycle capacity"
    total_voltage:
      name: "${bms2} total voltage"
    average_cell_voltage:
      name: "${bms2} average cell voltage"
    delta_cell_voltage:
      name: "${bms2} delta cell voltage"
    min_cell_voltage:
      name: "${bms2} min cell voltage"
    max_cell_voltage:
      name: "${bms2} max cell voltage"
    temperature_1:
      name: "${bms2} temperature 1"
    cell_voltage_1:
      name: "${bms2} cell voltage 1"
    cell_voltage_2:
      name: "${bms2} cell voltage 2"
    cell_voltage_3:
      name: "${bms2} cell voltage 3"
    cell_voltage_4:
      name: "${bms2} cell voltage 4"
    cell_voltage_5:
      name: "${bms2} cell voltage 5"
    cell_voltage_6:
      name: "${bms2} cell voltage 6"
    cell_voltage_7:
      name: "${bms2} cell voltage 7"
    cell_voltage_8:
      name: "${bms2} cell voltage 8"
    cell_voltage_9:
      name: "${bms2} cell voltage 9"
    cell_voltage_10:
      name: "${bms2} cell voltage 10"
    cell_voltage_11:
      name: "${bms2} cell voltage 11"
    cell_voltage_12:
      name: "${bms2} cell voltage 12"
    cell_voltage_13:
      name: "${bms2} cell voltage 13"
    cell_voltage_14:
      name: "${bms2} cell voltage 14"
    cell_voltage_15:
      name: "${bms2} cell voltage 15"
    cell_voltage_16:
      name: "${bms2} cell voltage 16"
    operation_status_bitmask:
      name: "${bms2} operation status bitmask"
    errors_bitmask:
      name: "${bms2} errors bitmask"
    balancer_status_bitmask:
      name: "${bms2} balancer status bitmask"
    software_version:
      name: "${bms2} software version"

text_sensor:
  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms0
    errors:
      name: "${bms0} errors"
    operation_status:
      name: "${bms0} operation status"
    device_model:
      name: "${bms0} device model"

  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms1
    errors:
      name: "${bms1} errors"
    operation_status:
      name: "${bms1} operation status"
    device_model:
      name: "${bms1} device model"

  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms2
    errors:
      name: "${bms2} errors"
    operation_status:
      name: "${bms2} operation status"
    device_model:
      name: "${bms2} device model"

switch:
  - platform: ble_client
    ble_client_id: client0
    name: "${bms0} enable bluetooth connection"

  - platform: ble_client
    ble_client_id: client1
    name: "${bms1} enable bluetooth connection"

  - platform: ble_client
    ble_client_id: client2
    name: "${bms2} enable bluetooth connection"  

  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms0
    charging:
      name: "${bms0} charging"
    discharging:
      name: "${bms0} discharging"

  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms1
    charging:
      name: "${bms1} charging"
    discharging:
      name: "${bms1} discharging"

  - platform: jbd_bms_ble
    jbd_bms_ble_id: bms2
    charging:
      name: "${bms2} charging"
    discharging:
      name: "${bms2} discharging"   

button:
  - platform: restart
    name: "ESP_JBD_reset"
syssi commented 7 months ago

Please make sure your ESPHome version is up-to-date (2023.12.9). The YAML builds fine here:

Linking .pioenvs/jbd-bms-ble/bootloader.elf
Building .pioenvs/jbd-bms-ble/bootloader.bin
Creating esp32 image...
Successfully created esp32 image.
Linking .pioenvs/jbd-bms-ble/firmware.elf
RAM:   [==        ]  16.1% (used 52796 bytes from 327680 bytes)
Flash: [=======   ]  65.6% (used 1203065 bytes from 1835008 bytes)
Building .pioenvs/jbd-bms-ble/firmware.bin
Creating esp32 image...
Successfully created esp32 image.
esp32_create_combined_bin([".pioenvs/jbd-bms-ble/firmware.bin"], [".pioenvs/jbd-bms-ble/firmware.elf"])
Wrote 0x1371f0 bytes to file /tmp/.esphome/build/jbd-bms-ble/.pioenvs/jbd-bms-ble/firmware-factory.bin, ready to flash to offset 0x0
==================================================================== [SUCCESS] Took 71.98 seconds ====================================================================
INFO Successfully compiled program.
syssi commented 7 months ago

If you change the substitutions.name from jbd-bms-ble to something else a new build folder will be created. May be this is a workaround.

hddmax commented 7 months ago

now it works , i have no glue why :-)

image