syssi / esphome-jk-bms

ESPHome component to monitor and control a Jikong Battery Management System (JK-BMS) via UART-TTL or BLE
Apache License 2.0
480 stars 161 forks source link

add a utility meter to the firmware #252

Closed amgstone closed 1 year ago

amgstone commented 1 year ago

add a utility meter to the firmware to connect to the "Battery" dashboard. So that you can add and see how much went into the accumulator and how much came out.

syssi commented 1 year ago

You can find the solution here: https://github.com/syssi/esphome-jk-bms/issues/80

amgstone commented 1 year ago

I can insert a utility meter into this firmware, gives an error

substitutions:
  name: ble
  external_components_source: github://syssi/esphome-jk-bms@main
  mac_address: C8:47:8C:E8:FF:73
  protocol_version: JK02

esphome:
  name: ${name}
  project:
    name: "syssi.esphome-jk-bms"
    version: 1.3.0

esp32:
  board: nodemcu-32s
  framework:
    type: esp-idf
    version: latest

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

logger:

api:
  encryption:
    key: "eqVtRZEcrMMZUMkO7GvrSCyCe//cZuQnIsvLbIJ2iZQ="

ota:
  password: "e1d447bf8bc832253849bbb3867e6e86"

wifi:
  ssid: "Irena_house"
  password: "1212121212"

  ap:
    ssid: "Ble Fallback Hotspot"
    password: "6T8A5xN6qtU3"

esp32_ble_tracker:

time:
  - platform: sntp

ble_client:
  - mac_address: ${mac_address}
    id: client0

jk_bms_ble:
  - ble_client_id: client0
    protocol_version: ${protocol_version}
    throttle: 5s
    id: bms0

binary_sensor:
  - platform: jk_bms_ble
    balancing:
      name: "${name} balancing"
    charging:
      name: "${name} charging"
    discharging:
      name: "${name} discharging"

button:
  - platform: jk_bms_ble
    retrieve_settings:
      name: "${name} retrieve settings"
    retrieve_device_info:
      name: "${name} retrieve device info"

number:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    balance_trigger_voltage:
      name: "${name} balance trigger voltage"
    cell_count:
      name: "${name} cell count"
    total_battery_capacity:
      name: "${name} total battery capacity"
    cell_voltage_overvoltage_protection:
      name: "${name} cell voltage overvoltage protection"
    cell_voltage_overvoltage_recovery:
      name: "${name} cell voltage overvoltage recovery"
    cell_voltage_undervoltage_protection:
      name: "${name} cell voltage undervoltage protection"
    cell_voltage_undervoltage_recovery:
      name: "${name} cell voltage undervoltage recovery"
    balance_starting_voltage:
      name: "${name} balance starting voltage"
    voltage_calibration:
      name: "${name} voltage calibration"
    current_calibration:
      name: "${name} current calibration"
    power_off_voltage:
      name: "${name} power off voltage"
    max_balance_current:
      name: "${name} max balance current"
    max_charge_current:
      name: "${name} max charge current"
    max_discharge_current:
      name: "${name} max discharge current"

sensor:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    min_cell_voltage:
      name: "${name} min cell voltage"
    max_cell_voltage:
      name: "${name} max cell voltage"
    min_voltage_cell:
      name: "${name} min voltage cell"
    max_voltage_cell:
      name: "${name} max voltage cell"
    delta_cell_voltage:
      name: "${name} delta cell voltage"
    average_cell_voltage:
      name: "${name} average cell voltage"
    total_voltage:
      name: "${name} total voltage"
    current:
      name: "${name} current"
    power:
      name: "${name} power"
    charging_power:
      name: "${name} charging power"
    discharging_power:
      name: "${name} discharging power"
    temperature_sensor_1:
      name: "${name} temperature sensor 1"
    temperature_sensor_2:
      name: "${name} temperature sensor 2"
    power_tube_temperature:
      name: "${name} power tube temperature"
    state_of_charge:
      name: "${name} state of charge"
    capacity_remaining:
      name: "${name} capacity remaining"
    total_battery_capacity_setting:
      name: "${name} total battery capacity setting"
    charging_cycles:
      name: "${name} charging cycles"
    total_charging_cycle_capacity:
      name: "${name} total charging cycle capacity"
    total_runtime:
      name: "${name} total runtime"
    balancing_current:
      name: "${name} balancing current"
    errors_bitmask:
      name: "${name} errors bitmask"

switch:
  - platform: jk_bms_ble
    charging:
      name: "${name} charging"
    discharging:
      name: "${name} discharging"
    balancer:
      name: "${name} balancer"

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

text_sensor:
  - platform: jk_bms_ble
    errors:
      name: "${name} errors"
    total_runtime_formatted:
      name: "${name} total runtime formatted"
amgstone commented 1 year ago

utility meter dont work

substitutions:
  name: ble
  external_components_source: github://syssi/esphome-jk-bms@main
  mac_address: C8:47:8C:E8:FF:73
  protocol_version: JK02

esphome:
  name: ${name}
  project:
    name: "syssi.esphome-jk-bms"
    version: 1.3.0

esp32:
  board: nodemcu-32s
  framework:
    type: esp-idf
    version: latest

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

logger:

api:
  encryption:
    key: "eqVtRZEcrMMZUMkO7GvrSCyCe//cZuQnIsvLbIJ2iZQ="

ota:
  password: "e1d447bf8bc832253849bbb3867e6e86"

wifi:
  ssid: "Irena_house"
  password: "1212121212"

  ap:
    ssid: "Ble Fallback Hotspot"
    password: "6T8A5xN6qtU3"

esp32_ble_tracker:

ble_client:
  - mac_address: ${mac_address}
    id: client0

jk_bms_ble:
  - ble_client_id: client0
    protocol_version: ${protocol_version}
    throttle: 5s
    id: bms0

binary_sensor:
  - platform: jk_bms_ble
    balancing:
      name: "${name} balancing"
    charging:
      name: "${name} charging"
    discharging:
      name: "${name} discharging"

button:
  - platform: jk_bms_ble
    retrieve_settings:
      name: "${name} retrieve settings"
    retrieve_device_info:
      name: "${name} retrieve device info"

number:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    balance_trigger_voltage:
      name: "${name} balance trigger voltage"
    cell_count:
      name: "${name} cell count"
    total_battery_capacity:
      name: "${name} total battery capacity"
    cell_voltage_overvoltage_protection:
      name: "${name} cell voltage overvoltage protection"
    cell_voltage_overvoltage_recovery:
      name: "${name} cell voltage overvoltage recovery"
    cell_voltage_undervoltage_protection:
      name: "${name} cell voltage undervoltage protection"
    cell_voltage_undervoltage_recovery:
      name: "${name} cell voltage undervoltage recovery"
    balance_starting_voltage:
      name: "${name} balance starting voltage"
    voltage_calibration:
      name: "${name} voltage calibration"
    current_calibration:
      name: "${name} current calibration"
    power_off_voltage:
      name: "${name} power off voltage"
    max_balance_current:
      name: "${name} max balance current"
    max_charge_current:
      name: "${name} max charge current"
    max_discharge_current:
      name: "${name} max discharge current"

time:
  - platform: sntp

sensor:
  - platform: total_daily_energy
    name: "BMS 1 Total Charging Energy Today"
    power_id: ble_charging_power
    unit_of_measurement: kWh
    icon: mdi:counter
    accuracy_decimals: 3
    restore: true
    filters:
      - multiply: 0.001 
  - platform: total_daily_energy
    name: "BMS 1 Total Discharging Energy Today"
    power_id: ble_discharging_power
    unit_of_measurement: kWh
    icon: mdi:counter
    accuracy_decimals: 3
    restore: true
    filters:
      - multiply: 0.001      

  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    min_cell_voltage:
      name: "${name} min cell voltage"
    max_cell_voltage:
      name: "${name} max cell voltage"
    min_voltage_cell:
      name: "${name} min voltage cell"
    max_voltage_cell:
      name: "${name} max voltage cell"
    delta_cell_voltage:
      name: "${name} delta cell voltage"
    average_cell_voltage:
      name: "${name} average cell voltage"
    total_voltage:
      name: "${name} total voltage"
    current:
      name: "${name} current"
    power:
      name: "${name} power"
    charging_power:
      name: "${name} charging power"
      id: ble_charging_power
    discharging_power:
      name: "${name} discharging power"
      id: ble_discharging_power
    temperature_sensor_1:
      name: "${name} temperature sensor 1"
    temperature_sensor_2:
      name: "${name} temperature sensor 2"
    power_tube_temperature:
      name: "${name} power tube temperature"
    state_of_charge:
      name: "${name} state of charge"
    capacity_remaining:
      name: "${name} capacity remaining"
    total_battery_capacity_setting:
      name: "${name} total battery capacity setting"
    charging_cycles:
      name: "${name} charging cycles"
    total_charging_cycle_capacity:
      name: "${name} total charging cycle capacity"
    total_runtime:
      name: "${name} total runtime"
    balancing_current:
      name: "${name} balancing current"
    errors_bitmask:
      name: "${name} errors bitmask"

switch:
  - platform: jk_bms_ble
    charging:
      name: "${name} charging"
    discharging:
      name: "${name} discharging"
    balancer:
      name: "${name} balancer"

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

text_sensor:
  - platform: jk_bms_ble
    errors:
      name: "${name} errors"
    total_runtime_formatted:
      name: "${name} total runtime formatted"
syssi commented 1 year ago

The configuration looks good to me. Could you explain what isn't working in detail?

amgstone commented 1 year ago

Screenshot_2023-02-19-23-43-06-717_io homeassistant companion android http://joxi.ru/MAjegKyTj5VyX2 battery dont work

amgstone commented 1 year ago

How can I give you access to HA so you know?

amgstone commented 1 year ago

I'm sorry, it's being updated, but the utility meter somehow works strangely, the information is not updated once an hour Screenshot_2023-02-20-08-07-02-951_io homeassistant companion android

syssi commented 1 year ago

Please monitor the behavior over a few days.

amgstone commented 1 year ago

what am i doing wrong? my utility meter does not work.

sensor:

syssi commented 1 year ago

Could you describe what's not working?

amgstone commented 1 year ago

utility meter inverter does not transmit values ​​to HA. there is a mistake somewhere.

syssi commented 1 year ago

Does the ESPHome node report a value greater zero? Could you provide some logs?

amgstone commented 1 year ago

can you add utility meter in yaml?

syssi commented 1 year ago

esp32-ble-example-plus-energy-meter.yaml.txt

amgstone commented 1 year ago

It works well for me. looked at 12 o'clock resets

syssi commented 1 year ago

If the ESHome node looses the time source it's unable to reset once a day.

amgstone commented 1 year ago

flash and the time will be updated

robio339 commented 1 year ago

I thought that i deleted my post fast enough but forgot on email notifications. I did flash this esp multiple times since this happened. I also changed name manually (from ${name} total ... to bms total....) and it went to 0, but after midnight again didn't reset. Yesterday before posting I changed it back to ${name} total .... and after changing entity's in entity card to new ones values stayed the same as with previous entity. I remembered than that the same entity is used in energy dashboard but there the values worked fine all the time. So i deleted entity card, created new one and everything was fine. Values were both on 0 and time on clock was also 00:00 ;). I will see tonight at midnight what will happen. Thanks for replying and keep on good work. Best regards Robert