Hauptmenü

JK BMS

Begonnen von domo, 16 März 2024, 16:19:16

Vorheriges Thema - Nächstes Thema

domo

I have a 12V LIFEPO4 4KW battery with a JK BMS.  I have installed the RS485 adapter, which seems to be isolated, which is a good thing.  I will connect this to a WROVER32 running tasmota, and use two pins as a modbus RS485 bridge.  I am running FHEM on a RASPI, which communicates with a lot of of other tasmota sensors using MQTT. Does a module exist for decoding and categorizing the BMS stream which I will hopefully be able to receive on the PI?  Have I missed something ?  Will this work like I imagine it could ?  I would like to get the information so that I can control the charging routine for the battery pack, which presently gets any energy which is above +5W according to the main power meter reading using an optical magnetic adapter on the face of the meter (also tasmota).  I get a reading every second from the Stromzahler.  The software and hardware performs quite well presently, but extra info from the BMS could be an advantage. The charger is a server PSU (maximum 70A @ 13.7V) controlled from the PWM on tasmota. Any input or comment would be appreciated. Thanks.

Gisbert

#1
Hi domo,

please check this link: https://github.com/syssi/esphome-jk-bms
In a couple of weeks, I'm gonegoing to a have JK-BMS and I will either use this code or something similiar from GitHub.

Cheers
Gisbert
Aktuelles FHEM | PROXMOX | Fujitsu Futro S740 | Debian 12 | UniFi | Homematic, VCCU, HMUART | ESP8266 | ATtiny85 | Wasser-, Stromzähler | tuya local | Wlan-Kamera | SIGNALduino, Flamingo Rauchmelder FA21/22RF | RHASSPY | DEYE | JK-BMS | ESPHome

domo

hi Gisbert, cool, i'll wait for your feedback.. 

domo

so this is what the JK BMS is sending, I think it is ok, it needs to be parsed into different values:
4E5700FD00000000060001790C010CDA020CDA030CDA040CDA80001781001782001583052484000085458602870042890000498E8A00048B00008C00038E05A08F0410900E10910DDE920005930A28940A5A95000596012C97002898012C9900C89A001E9B0B549C00039D019E00649F0050A00064A10064A20014A30046A40050A5FFECA60003A7FFECA8FFF6A904AA0000011DAB01AC01AD03C5AE01AF00B0000AB114B231323334000000000000B300B4496E707574205573B532333034B60005C653B731312E58575F5331312E32365F5F5FB800B90000011DBA496E70757420557365726461534261745F31325632383041C001000000006800004AD0

best regs

domo

Hello Gisbert, I decoded locally on the esp32 using berry script, and MQTT.PUBLISH commands.it works great. I think it is the best way to go.  Regards domo

Gisbert

Hi domo,

I have to wait for another ESP32 which hopefully will arrive in about 2 weeks. The battery and the JK-BMS are now working since a couple of days.
My plan is to use syssis code: https://github.com/syssi/esphome-jk-bms. The connection seems to be easy as no further components besides the ESP32 board are necessary. 3 of the 4 pins (JST 1.25mm pitch) of the port called GPS are necessary. The 4th pin is the voltage of the battery (about 50~56 V) - this must not be used.
I will send the data via MQTT to Fhem. Syssis code is based on ESPHome / Python which needs to be installed on your computer. I followed the instructions of this page for another project (my DEYE hybrid inverter), it worked right from the start: https://smarthomeyourself.de/wiki/esphome/esphome-mit-python-ueber-die-kommandozeile-flashen/.

Regards
Gisbert
Aktuelles FHEM | PROXMOX | Fujitsu Futro S740 | Debian 12 | UniFi | Homematic, VCCU, HMUART | ESP8266 | ATtiny85 | Wasser-, Stromzähler | tuya local | Wlan-Kamera | SIGNALduino, Flamingo Rauchmelder FA21/22RF | RHASSPY | DEYE | JK-BMS | ESPHome

domo

Hi Gisbert, yes I looked at that project a lot, I used the file jk_bms.cpp to template my berry script, which is working quite nicely, it sends the mqtt already decoded to my rasberry pi, where FHEM gets it.  so i guess you will look at decoding the data on your host.  yes that pin4 is a no no, it has battery voltage on it, best leave it alone.  so i have a small non FHEM related question, regarding berry script, why can't i use *=-1 to invert an integer ?  this is very frustrating, it simply will not accept it, neither will a=-a , i am at my limit trying to get the mqtt.publish current reading negative when it should be...  I have built a bespoke controller for my battery pack, with two charger and discharger PWMs which control a modified server power supply and a solar inverter to charge and discharge the battery.  My pack is only 4KW so not too big.  I guess i will need a few more panels on the roof now to charge that in one day. hope to hear how you get on too.  best regards Domo.

Gisbert

#7
Hi domo,

from a former project, I get used to ESPHome which seems to be much user friendly than Arduino code. Therefore I will use the ESPHome code.

When I want to transform a reading in something else, I use most likely the attribut userReadings, e.g. in your case
attr userReadings Device newreading {0-ReadingsNum($name,'oldreading,'')}
Regards
Gisbert
Aktuelles FHEM | PROXMOX | Fujitsu Futro S740 | Debian 12 | UniFi | Homematic, VCCU, HMUART | ESP8266 | ATtiny85 | Wasser-, Stromzähler | tuya local | Wlan-Kamera | SIGNALduino, Flamingo Rauchmelder FA21/22RF | RHASSPY | DEYE | JK-BMS | ESPHome

Gisbert

Hi domo,

I got finally the code from syssi working.
It took a couple of ESP32 boards until it worked.
The ESP32 Boards from AliExpress had a bad quality - I returned them.
The quality of boards from AZ-Delivery were good as expected. Unfortunately, I killed the 1st board. The colors of my cables were missleading and I put 55V on one of the GPIOs - it crackled and I send the ESP to heaven, RIP. The second works now perfect.
I reduced the reading cycle from 5 to 10 seconds when I realized that my server was under pressure.

I give the code from syssi some time and check later whether there are better codes available.

Regards
Gisbert
Aktuelles FHEM | PROXMOX | Fujitsu Futro S740 | Debian 12 | UniFi | Homematic, VCCU, HMUART | ESP8266 | ATtiny85 | Wasser-, Stromzähler | tuya local | Wlan-Kamera | SIGNALduino, Flamingo Rauchmelder FA21/22RF | RHASSPY | DEYE | JK-BMS | ESPHome

domo

Hi Gisbert, sounds good, keep in touch about findings, I am actually reading the BMS at 1 second intervals, I need the battery status, especially the current, I need to watch the power taken from the battery, so I monitor it closely. Best regards

holle75

Hallo Gisbert, ich auch gerade an dem Thema. JK Inverter BMS (das aktuelle) und natürlich möchte ich die Einzelspannungen der Zellen irgendwie in fhem sehen. Auf der Verbindung auch noch Einstellungen im BMS setzen zu können, wäre die Krönung (aber nicht essentiell). Jetzt am erruieren, wie.

Mein CAN Port ist von der Anlage belegt, bleibt nur RS485 Port oder Bluetooth. Da ja immer die Wahl der Technik und des Weges der komplizierteste Part ist: Was ist deiner und wie hast du es gemacht? Am liebsten wäre mir via MQTT weil der Server in fhem sowieso läuft, aber ich erinnere mich noch dunkel (Jahre her) dass das gar nicht so einfach war. Jahre her ist es auch, dass ich mit Arduinos und ESp32 gebastelt habe. Alles vergessen, was nicht prinzipiell war ;)

Würde mich über deine Erkenntnisse freuen. Habe zwar oben alles gelesen, aber wie gesagt, Weg und Technik und das Verständnis von diesen .... altes Hirn.

Gisbert

#11
Hallo holle75,

ich hab eigentlich nur die Anweisungen befolgt, die im GitHub-Projekt von syssi vorgegeben werden: https://github.com/syssi/esphome-jk-bms
Du musst dich mit ESPHome beschäftigen, und wie du ESPHome, bzw. die entsprechende YAML-Datei auf einen ESP32 geflasht bekommst.
Um ESPHome zu flashen, bin ich einer Anleitung von haus-automatisierung.com gefolgt (falsch erinnert, siehe nächster Beitrag, genauer Link folgt später). Ich hänge dann auch meine yaml-Datei an, die ich für mein JK-BMS benutze (den Typ schreib ich auch dazu).

Viele Grüße Gisbert
Aktuelles FHEM | PROXMOX | Fujitsu Futro S740 | Debian 12 | UniFi | Homematic, VCCU, HMUART | ESP8266 | ATtiny85 | Wasser-, Stromzähler | tuya local | Wlan-Kamera | SIGNALduino, Flamingo Rauchmelder FA21/22RF | RHASSPY | DEYE | JK-BMS | ESPHome

holle75

Danke Gisbert, sehr nett.

ESPHome bekomme ich hin. Also hatte ich damals. Das war, meine ich mich zu erinnern, damals der simpelste Weg was das flashen angeht. Will sagen, hatte auf Anhieb funktioniert.

Was ich nicht mehr weiß, hatte ESPHome via MQTT kommuniziert (scheint so, ja, eben deinem Link gefolgt)? Und wie wird das Platinchen am BMS kontaktiert (ok, Rs485 Port laut deinem Link)?

Kannst du auch ins BMS "schreiben"? Kannst du mir auch noch gleich deine fhem DEF RAW hinterlassen? Entschuldige so zu drängen, aber das spart immer 10 Stunden Gepröbel wenn man direkt auf den richtigen Weg geleitet wird. Zu viele Baustellen gerade mal wieder (Eine Zelle war in der Battery defekt. Aber nur "ein bißchen". Du kannst dir vorstellen wieviel Freude und Zeit es bedeutet das erstmal einzukreisen und herauszufinden ... und wieviel Zeit du vergeudest die ersetzte Zelle im laufenden Betrieb, weil sonst kein Strom aufm Land, zu laden und zu balancen)

"Mein" BMS habe ich jetzt auf der syssi Übersicht nicht direkt gesehen, aber ich probiere es einfach mal aus, dann.

Danke!

Gisbert

Hallo holle75,

ESPHome hatte ich über diesen Link in Windows installiert: https://smarthomeyourself.de/wiki/esphome/esphome-mit-python-ueber-die-kommandozeile-flashen/

MQTT vom ESP32 rauszusenden ist vglw. einfach. Bitte schaue in den Code, dann wirst du es verstehen und sehen, dass es tatsächlich einfach ist.

Mögliche Stolpersteine:
esp32:
  board: nodemcu-32s
  framework:
    type: esp-idf
Ich habe ein ESP32-Board von AZ-Delivery im Einsatz. Bei anderen Boards müssen u.U. andere Einträge gemacht werden.

#Optional manual IP - damit gelingt ein wireless update in Home Assistant und in ESPHome
  manual_ip:
    static_ip: 192.168.2.63
    gateway: 192.168.2.1
    subnet: 255.255.255.0
Bitte zuerstmal auskommentieren, da ja die IP-Adresse des ESP32 noch unbekannt sein dürfte. Anschließend mit den richtigen Daten nochmals ESPHome laufen lassen. Damit sind Updates vom PC aus extrem einfach durchzuführen.

Die Funktionsweise der secrets.yaml kennst du sicher, da werden die Credentials gespeichert.

Zur Zeit lese ich nur die Daten vom BMS per MQTT aus, ich schreibe nichts per MQTT ins BMS. Bei meinem DEYE 3-Phasen-Wechselrichter schreibe ich auch Register per MQTT. Dazu publishe ich aus Fhem und der ESP lauscht wie folgt "on message":
mqtt:
  broker: !secret my_broker
  port: !secret my_port
  topic_prefix: "/DEYE"
  username: !secret my_username
  password: !secret my_password
  on_message:
    - topic: /DEYE/Batt/off
      then:
        - select.set:
            id: ${device_type}_Battery_Mode
            option: "No Batt"
        - mqtt.publish:
            topic: /DEYE/Batt/state
            payload: "Battery is OFF!"         
    - topic: /DEYE/Batt/on
      then:
        - select.set:
            id: ${device_type}_Battery_Mode
            option: "Use Batt V"
        - mqtt.publish:
            topic: /DEYE/Batt/state
            payload: "Battery is ON!"
    - topic: /DEYE/MaxBattCharge/current
      payload: "40"
      then:
        - number.set:
            id: ${device_type}_Maximum_battery_charge_current
            value: 40
    - topic: /DEYE/MaxBattCharge/current
      payload: "30"
      then:
        - number.set:
            id: ${device_type}_Maximum_battery_charge_current
            value: 30
    - topic: /DEYE/MaxBattCharge/current
      payload: "20"
      then:
        - number.set:
            id: ${device_type}_Maximum_battery_charge_current
            value: 20
    - topic: /DEYE/MaxBattCharge/current
      payload: "10"
      then:
        - number.set:
            id: ${device_type}_Maximum_battery_charge_current
            value: 10
    - topic: /DEYE/MaxBattCharge/current
      payload: "80"
      then:
        - number.set:
            id: ${device_type}_Maximum_battery_charge_current
            value: 80
    - topic: /DEYE/battery_float/voltage
      payload: "55"
      then:
        - number.set:
            id: ${device_type}_Battery_float_voltage
            value: 55
    - topic: /DEYE/battery_float/voltage
      payload: "55.4"
      then:
        - number.set:
            id: ${device_type}_Battery_float_voltage
            value: 55.4
    - topic: /DEYE/battery_float/voltage
      payload: "55.8"
      then:
        - number.set:
            id: ${device_type}_Battery_float_voltage
            value: 55.8

Wichtig ist auch, ob das Register "number", "select" oder was auch immer ist.
Im obigen Beispiel sende ich auch vom ESP32 etwas zurück, um sicherzustellen, dass die Kommunikation erfolgreich war:
        - mqtt.publish:
            topic: /DEYE/Batt/state
            payload: "Battery is OFF!"

Prinzipiell mache ich es so, dass ich essentielle Änderungen vorort mache. Register von Fhem per MQTT zu schreiben kann fatal enden, d.h. man sollte sich absolut sicher sein, was man tut, und mutig sein, ist hier absolut falsch.

Mein Fhem-Device:
defmod JK_BMS MQTT_DEVICE
attr JK_BMS IODev MyBroker
attr JK_BMS autoSubscribeReadings jk-bms/#
attr JK_BMS event-min-interval total_voltage:300,capacity_remaining:600
attr JK_BMS event-on-change-reading Zeitstempel,average_cell_voltage,balancing,\
,capacity_remaining,capacity_remaining_derived,charging_cycles,current:0.2,\
,delta_cell_voltage,power:10,power_tube_temperature,temperature_sensor_1,\
,temperature_sensor_2,total_charging_cycle_capacity,total_runtime,\
,total_runtime_formatted,total_voltage:0.02,errors
attr JK_BMS icon measure_battery_100
attr JK_BMS room DEYE
attr JK_BMS stateFormat {'SOC: '.ReadingsNum($name,'capacity_remaining','').'%<br/>\
charging cycle: '.ReadingsNum($name,'charging_cycles','').'<br/>\
power: '.-round(ReadingsNum($name,'power','')/1000,3).' kW<br/>\
current: '.-round(ReadingsNum($name,'current',''),2).' A<br/>\
Ø cell voltage: '.ReadingsNum($name,'average_cell_voltage','').' V<br/>\
Δ cell voltage: '.round(ReadingsNum($name,'delta_cell_voltage','')*1000,0).' mV<br/>\
battery voltage: '.ReadingsNum($name,'total_voltage',''). 'V<br/>'\
.ReadingsVal($name,'IPaddress','').'<br/>\
<span style="vertical-align: +0px;; font-size: 85%;;">'.ReadingsVal($name,'Zeitstempel','').'</span>'}
attr JK_BMS subscribeReading_actual_battery_capacity jk-bms/sensor/jk-bms_actual_battery_capacity/state
attr JK_BMS subscribeReading_average_cell_voltage jk-bms/sensor/jk-bms_average_cell_voltage/state
attr JK_BMS subscribeReading_balancing jk-bms/binary_sensor/jk-bms_balancing/state
attr JK_BMS subscribeReading_balancing_switch jk-bms/binary_sensor/jk-bms_balancing_switch/state
attr JK_BMS subscribeReading_binary_sensor_charging jk-bms/binary_sensor/jk-bms_charging/state
attr JK_BMS subscribeReading_binary_sensor_discharging jk-bms/binary_sensor/jk-bms_discharging/state
attr JK_BMS subscribeReading_capacity_remaining jk-bms/sensor/jk-bms_capacity_remaining/state
attr JK_BMS subscribeReading_capacity_remaining_derived jk-bms/sensor/jk-bms_capacity_remaining_derived/state
attr JK_BMS subscribeReading_cell_voltage_1 jk-bms/sensor/jk-bms_cell_voltage_1/state
attr JK_BMS subscribeReading_cell_voltage_10 jk-bms/sensor/jk-bms_cell_voltage_10/state
attr JK_BMS subscribeReading_cell_voltage_11 jk-bms/sensor/jk-bms_cell_voltage_11/state
attr JK_BMS subscribeReading_cell_voltage_12 jk-bms/sensor/jk-bms_cell_voltage_12/state
attr JK_BMS subscribeReading_cell_voltage_13 jk-bms/sensor/jk-bms_cell_voltage_13/state
attr JK_BMS subscribeReading_cell_voltage_14 jk-bms/sensor/jk-bms_cell_voltage_14/state
attr JK_BMS subscribeReading_cell_voltage_15 jk-bms/sensor/jk-bms_cell_voltage_15/state
attr JK_BMS subscribeReading_cell_voltage_16 jk-bms/sensor/jk-bms_cell_voltage_16/state
attr JK_BMS subscribeReading_cell_voltage_2 jk-bms/sensor/jk-bms_cell_voltage_2/state
attr JK_BMS subscribeReading_cell_voltage_3 jk-bms/sensor/jk-bms_cell_voltage_3/state
attr JK_BMS subscribeReading_cell_voltage_4 jk-bms/sensor/jk-bms_cell_voltage_4/state
attr JK_BMS subscribeReading_cell_voltage_5 jk-bms/sensor/jk-bms_cell_voltage_5/state
attr JK_BMS subscribeReading_cell_voltage_6 jk-bms/sensor/jk-bms_cell_voltage_6/state
attr JK_BMS subscribeReading_cell_voltage_7 jk-bms/sensor/jk-bms_cell_voltage_7/state
attr JK_BMS subscribeReading_cell_voltage_8 jk-bms/sensor/jk-bms_cell_voltage_8/state
attr JK_BMS subscribeReading_cell_voltage_9 jk-bms/sensor/jk-bms_cell_voltage_9/state
attr JK_BMS subscribeReading_charging jk-bms/switch/jk-bms_charging/state
attr JK_BMS subscribeReading_charging_cycles jk-bms/sensor/jk-bms_charging_cycles/state
attr JK_BMS subscribeReading_charging_power jk-bms/sensor/jk-bms_charging_power/state
attr JK_BMS subscribeReading_current jk-bms/sensor/jk-bms_current/state
attr JK_BMS subscribeReading_current_calibration jk-bms/sensor/jk-bms_current_calibration/state
attr JK_BMS subscribeReading_debug jk-bms/debug
attr JK_BMS subscribeReading_dedicated_charger_switch jk-bms/binary_sensor/jk-bms_dedicated_charger_switch/state
attr JK_BMS subscribeReading_delta_cell_voltage jk-bms/sensor/jk-bms_delta_cell_voltage/state
attr JK_BMS subscribeReading_discharging jk-bms/switch/jk-bms_discharging/state
attr JK_BMS subscribeReading_discharging_power jk-bms/sensor/jk-bms_discharging_power/state
attr JK_BMS subscribeReading_errors jk-bms/sensor/jk-bms_errors/state
attr JK_BMS subscribeReading_max_cell_voltage jk-bms/sensor/jk-bms_max_cell_voltage/state
attr JK_BMS subscribeReading_max_voltage_cell jk-bms/sensor/jk-bms_max_voltage_cell/state
attr JK_BMS subscribeReading_min_cell_voltage jk-bms/sensor/jk-bms_min_cell_voltage/state
attr JK_BMS subscribeReading_min_voltage_cell jk-bms/sensor/jk-bms_min_voltage_cell/state
attr JK_BMS subscribeReading_online_status jk-bms/binary_sensor/jk-bms_online_status/state
attr JK_BMS subscribeReading_operation_mode jk-bms/sensor/jk-bms_operation_mode/state
attr JK_BMS subscribeReading_password jk-bms/sensor/jk-bms_password/state
attr JK_BMS subscribeReading_power jk-bms/sensor/jk-bms_power/state
attr JK_BMS subscribeReading_power_tube_temperature jk-bms/sensor/jk-bms_power_tube_temperature/state
attr JK_BMS subscribeReading_status jk-bms/status
attr JK_BMS subscribeReading_switch_charging jk-bms/switch/jk-bms_charging/state
attr JK_BMS subscribeReading_switch_discharging jk-bms/switch/jk-bms_discharging/state
attr JK_BMS subscribeReading_temperature_sensor_1 jk-bms/sensor/jk-bms_temperature_sensor_1/state
attr JK_BMS subscribeReading_temperature_sensor_2 jk-bms/sensor/jk-bms_temperature_sensor_2/state
attr JK_BMS subscribeReading_total_battery_capacity_setting jk-bms/sensor/jk-bms_total_battery_capacity_setting/state
attr JK_BMS subscribeReading_total_charging_cycle_capacity jk-bms/sensor/jk-bms_total_charging_cycle_capacity/state
attr JK_BMS subscribeReading_total_runtime jk-bms/sensor/jk-bms_total_runtime/state
attr JK_BMS subscribeReading_total_runtime_formatted jk-bms/sensor/jk-bms_total_runtime_formatted/state
attr JK_BMS subscribeReading_total_voltage jk-bms/sensor/jk-bms_total_voltage/state
attr JK_BMS userReadings Zeitstempel {substr(ReadingsTimestamp($name,'total_voltage',''),0,19)}, \
IPaddress \
{"<a href=\"http://192.168.2.63\" style=\"color: green;; text-decoration: underline;;\" target=\"_blank\" rel=\"noopener noreferrer\">http://192.168.2.63</a>"}

Falls es noch Fragen gibt, dann melde dich bitte wieder, gerne auch, wenn es keine Fragen gibt, und du es erfolgreich umgesetzt hast.

Viele Grüße Gisbert
Aktuelles FHEM | PROXMOX | Fujitsu Futro S740 | Debian 12 | UniFi | Homematic, VCCU, HMUART | ESP8266 | ATtiny85 | Wasser-, Stromzähler | tuya local | Wlan-Kamera | SIGNALduino, Flamingo Rauchmelder FA21/22RF | RHASSPY | DEYE | JK-BMS | ESPHome

holle75

Danke dir vielmals.

Ich werde hoffentlich übers Wochenende oder nächste Woche dazu kommen und werde natürlich berichten wie es läuft.