Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JK-PB bms compatibility. Target: 1 ESP in a "listening mode" connected to RS485 network. #464

Open
wants to merge 133 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
43c4b32
script to sniffing traffic from the RS485 network
txubelaxu Feb 25, 2024
9fa2529
some data got from [JK-PB2A16S-20P v14]
txubelaxu Feb 26, 2024
aa69361
JK BMS internal RS485 network compatibility (?)
txubelaxu Mar 3, 2024
de66167
Added multidevice example at esp32-example-rs485.yaml
txubelaxu Mar 4, 2024
dfdd217
Back some changes
txubelaxu Mar 4, 2024
5fa5e43
Some modifications to jk_rs485
txubelaxu Mar 5, 2024
513c461
Some modifications to jk_rs485
txubelaxu Mar 5, 2024
dc9d15f
First working RS485 for JK-PB. Sensors config working in progress
txubelaxu Mar 11, 2024
8ba7e4e
Create README.md for jk-pb
txubelaxu Mar 11, 2024
0796982
Update README.md
txubelaxu Mar 11, 2024
b68b5e1
Added more sensors
txubelaxu Mar 11, 2024
cbb4270
changed config .yaml for second bms
txubelaxu Mar 11, 2024
5806353
Merge pull request #1 from syssi/main
txubelaxu Mar 11, 2024
1bf6f67
Related to issue #390: some parameters added to BLE code
txubelaxu Mar 11, 2024
35d326d
corrected a small bug in my previous commit
txubelaxu Mar 11, 2024
c8574ee
updated 5 params for BLE. Example added: esp32-example-jkpb-example.yaml
txubelaxu Mar 12, 2024
93f9729
error corrected and example MAC changed to: XX:XX:XX:XX:XX:XX # <--- …
txubelaxu Mar 12, 2024
8f2219d
Update README.md
txubelaxu Mar 12, 2024
4372d9c
Update README.md
txubelaxu Mar 12, 2024
90347f5
+4 temperature sensor info added
txubelaxu Mar 13, 2024
09a3c37
changed example device name to: esp-rs485-gw
txubelaxu Mar 13, 2024
c8fd40c
+capacity remainint units corrected
txubelaxu Mar 13, 2024
8eb06c7
Update README.md
txubelaxu Mar 13, 2024
aa34b04
added Home Assistant Dashboards
txubelaxu Mar 13, 2024
c3b0fe7
Merge branch 'main' of github.com:txubelaxu/esphome-jk-bms
txubelaxu Mar 13, 2024
813fc82
added 2 examples of 1maste/6slaves and 1master/1slave
txubelaxu Mar 13, 2024
07b3a9e
Published README.md in jk_rs485_sniffer as well
txubelaxu Mar 14, 2024
47ff69e
changed scheme a bit
txubelaxu Mar 14, 2024
95e79a9
changed scheme a bit
txubelaxu Mar 14, 2024
20c62d6
Update README.md
txubelaxu Mar 14, 2024
a0d70af
Update README.md
txubelaxu Mar 14, 2024
0914ae5
Update README.md
txubelaxu Mar 14, 2024
c3f0766
Update README.md
txubelaxu Mar 14, 2024
c440d64
A bug corrected. Buffer management changed. jk_bms_ble returned to or…
txubelaxu Mar 17, 2024
35f2810
Merge branch 'main' of github.com:txubelaxu/esphome-jk-bms
txubelaxu Mar 17, 2024
c8e9fd3
Update README.md with new schematics (by @denveronly)
txubelaxu Mar 17, 2024
38a212a
Actualizar README.md
txubelaxu Mar 17, 2024
0f19110
More parameters and home assitant dashboard changed as well to includ…
txubelaxu Mar 18, 2024
f46a326
this file changed as well
txubelaxu Mar 18, 2024
7fec2e9
changed examples to external_components_source: github://txubelaxu/…
txubelaxu Mar 18, 2024
70fbc6c
removed some debug info
txubelaxu Mar 18, 2024
4f51502
Update README.md
txubelaxu Mar 18, 2024
c6135ff
Update README.md
txubelaxu Mar 18, 2024
59b0d26
Update README.md
txubelaxu Mar 19, 2024
d8fae98
esp32-ble-battery_number_001.yaml example created and working
txubelaxu Mar 19, 2024
70acca8
Added smart_sleep_voltage parameter to rs485 and BLE components
txubelaxu Mar 19, 2024
2d69367
New params: SOC100 and SOC0 Voltage added to BLE component
txubelaxu Mar 19, 2024
3d65500
added RCV RFV to BLE component
txubelaxu Mar 19, 2024
92b4b3b
Display always on "switch" icon changed in BLE component
txubelaxu Mar 19, 2024
381bbf0
More parameters for BLE component: Temp3 & Temp4
txubelaxu Mar 19, 2024
547c4be
precharging, charging, discharging, balancing status (working status,…
txubelaxu Mar 19, 2024
84db259
a bug corrected (charging/discharging status)
txubelaxu Mar 19, 2024
592bcd1
balancing_sensor_ created. Binary_Sensor says if is working, and Sens…
txubelaxu Mar 19, 2024
dfa9234
charging float mode switch available in BLE and RS485 components
txubelaxu Mar 19, 2024
afac449
bug in a bit detected
txubelaxu Mar 19, 2024
00528b1
CFM charging float mode available in BLE and RS485 components
txubelaxu Mar 19, 2024
2ffd6a9
All switches available for BLE now.
txubelaxu Mar 19, 2024
857b01c
Created "home assistant dashboards" folder inside jk_bms_ble.
txubelaxu Mar 19, 2024
45e61de
All switches available (read only) in RS-485 component
txubelaxu Mar 20, 2024
b495a23
Some inprovements for rs485, new sensors: OVP, SLEEP VOLTAGE, OVPR, R…
txubelaxu Mar 20, 2024
a961110
+ ota on_begin disable ESP bluetooth
txubelaxu Mar 20, 2024
12e4606
rs485 new parameters:
txubelaxu Mar 20, 2024
2c6ff12
external_components changed to source
txubelaxu Mar 20, 2024
dae52fa
name change:
txubelaxu Mar 20, 2024
a56fb60
Update README.md
txubelaxu Mar 20, 2024
180e1be
text correction
txubelaxu Mar 20, 2024
3a49ac0
Added multiple alarm boolean sensors: BATTempSensor1Absent, BATTempSe…
txubelaxu Mar 21, 2024
28ec98f
Update README.md
txubelaxu Mar 21, 2024
0482fca
state vs value
txubelaxu Mar 21, 2024
b9ffafc
heating_current_sensor and heating_status_binary_sensor changed to an…
txubelaxu Mar 21, 2024
5b4bc6b
Merge branch 'main' of github.com:txubelaxu/esphome-jk-bms
txubelaxu Mar 21, 2024
4164fb9
new parames in config files
txubelaxu Mar 21, 2024
c7204b9
Added:
txubelaxu Mar 21, 2024
d36770a
a small bug, anyway cell rcv time, and cell rfv time are read correct…
txubelaxu Mar 21, 2024
e5d945d
debugging... is frame type >02 present in rs485 network sometimes?
txubelaxu Mar 21, 2024
538a9e8
debug
txubelaxu Mar 21, 2024
aaf79a6
Actualizar README.md
txubelaxu Mar 21, 2024
059ed06
BLE "cell RCV Time" & "cell RFV Time" bug corrected. Missing register…
txubelaxu Mar 21, 2024
d5ffc5d
Merge branch 'main' of github.com:txubelaxu/esphome-jk-bms
txubelaxu Mar 21, 2024
dba8fc3
+ balancing --> balancing_direction (charging,idle,discharging)
txubelaxu Mar 22, 2024
1fd4536
Attention: To avoid misinterpretations. It is a parameter that refers…
txubelaxu Mar 22, 2024
db977dd
commented "device info" from update
txubelaxu Mar 22, 2024
6d4b647
* Renaming (avoiding risky missunderstanding between cell or battery …
txubelaxu Mar 22, 2024
4b8d273
Update README.md
txubelaxu Mar 22, 2024
d1d3844
rs485 changes
txubelaxu Mar 22, 2024
961897d
Merge branch 'main' of github.com:txubelaxu/esphome-jk-bms
txubelaxu Mar 22, 2024
805de5d
label changed
txubelaxu Mar 22, 2024
fe45b4c
rs485 examples updated
txubelaxu Mar 22, 2024
9dd8ada
rs485 bug corrected obtaining status values
txubelaxu Mar 22, 2024
ed12ac0
LOGI to LOGV two lines
txubelaxu Mar 22, 2024
f8a2a37
Multiple params added to rs-485 component:
txubelaxu Mar 23, 2024
3d71cea
New params added to rs-485 bms component:
txubelaxu Mar 24, 2024
821f0dd
More params added to rs-485 component:
txubelaxu Mar 24, 2024
d86ae10
rs-485 some bugs corrected
txubelaxu Mar 24, 2024
8e42218
new dashboards for home assistant
txubelaxu Mar 27, 2024
62f111d
Update README.md
txubelaxu Mar 27, 2024
485fd36
Update README.md
txubelaxu Mar 27, 2024
7e426a3
reordered two params
txubelaxu Mar 27, 2024
c0eb1a8
corrected example config
txubelaxu Mar 27, 2024
5312c7a
BLE status of balancing corrected? (some new params added as well)
txubelaxu Mar 27, 2024
f050939
status_balancing possible firmware bug at address 169? (decode_jk02_c…
txubelaxu Mar 27, 2024
998fb3e
rs485 status_balancing possible firmware bug at address 169? (decode_…
txubelaxu Mar 27, 2024
ab876f8
Precharge working status posible bug corrected
txubelaxu Mar 27, 2024
1a20c5f
rs485 crc bug corrected
txubelaxu Mar 29, 2024
eb53d9b
crc bug corrected
txubelaxu Mar 29, 2024
66c5afe
* BLE:
txubelaxu Mar 31, 2024
fee91d0
HA dashboard updated
txubelaxu Mar 31, 2024
8a95a6c
trying to correct binary_output.h bug
txubelaxu Apr 1, 2024
df78dd9
output folder
txubelaxu Apr 1, 2024
67745fc
binary_output.h bug corrected
txubelaxu Apr 1, 2024
3dc9c6a
Changes to master mode (optional) and more dashboards
txubelaxu Apr 9, 2024
209e597
Actualizar README.md
txubelaxu Apr 9, 2024
7d3596d
Actualizar README.md
txubelaxu Apr 9, 2024
eb4a486
Actualizar README.md
txubelaxu Apr 9, 2024
92b792d
Actualizar README.md
txubelaxu Apr 9, 2024
0a23a43
Update README.md
txubelaxu Apr 9, 2024
9df7f4c
esp32-example-jkpb-rs485_1master_6slaves example updated
txubelaxu Apr 9, 2024
6d88e7c
Added SOH (State of Health). Dashboards updated as well.
txubelaxu Apr 10, 2024
6aa064f
minimal change to dashboard
txubelaxu Apr 10, 2024
95e8e17
small bug corrected in the dashboard
txubelaxu Apr 10, 2024
c51c3f4
dashboard changed again (minimal change)
txubelaxu Apr 10, 2024
402aeed
global info updated (number of online BMS vs number of total BMSs)
txubelaxu Apr 10, 2024
aa57785
+Corrected a temperature bug
txubelaxu Apr 10, 2024
0dd8914
HASS dashboard updated here
txubelaxu Apr 10, 2024
6a4af40
+SHORT_CIRCUIT_PROTECTION_RECOVERY_DELAY
txubelaxu Apr 12, 2024
891ee14
Update README.md
txubelaxu Jun 10, 2024
53f136b
Update README.md
txubelaxu Jun 11, 2024
2325770
moved talk_pin namespace from binary_output to talk_pin
txubelaxu Jun 12, 2024
a416ea8
DEVICE PWD (setup passcode) is gathered as well.
txubelaxu Jun 13, 2024
a6e7831
Checking another settings parameter
txubelaxu Jun 14, 2024
ad1c9f2
changed update_intervale to 180s
txubelaxu Jun 15, 2024
d640e6a
Bug corrected: converting from uint32 to float. Sometimes esp32 reboo…
txubelaxu Jun 16, 2024
1a93af6
more convertions corrected (int32 to float & int16 to float)
txubelaxu Jun 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 27 additions & 10 deletions components/jk_bms_ble/jk_bms_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,11 @@ void JkBmsBle::decode_jk04_cell_info_(const std::vector<uint8_t> &data) {
this->publish_state_(this->total_runtime_sensor_, (float) jk_get_32bit(286));
this->publish_state_(this->total_runtime_formatted_text_sensor_, format_total_runtime_(jk_get_32bit(286)));

// 290 4 0x00 0x00 0x00 0x00 Unknown290
// 290 1 0x00 Unknown290
// 291 1 0x00 ** [JK-PB2A16S-20P v14] CHARGE IS WORKING
// 292 1 0x00 ** [JK-PB2A16S-20P v14] DISCHARGE IS WORKING
// 293 1 0x00 ** [JK-PB2A16S-20P v14] PREDISCHARGE IS WORKING (?)
// 294 1 0x00 ** [JK-PB2A16S-20P v14] BALANCE IS WORKING (?)
ESP_LOGD(TAG, "Unknown290: 0x%02X 0x%02X 0x%02X 0x%02X (always 0x00 0x00 0x00 0x00?)", data[290], data[291],
data[292], data[293]);

Expand Down Expand Up @@ -794,13 +798,13 @@ void JkBmsBle::decode_jk02_settings_(const std::vector<uint8_t> &data) {
// 0 4 0x55 0xAA 0xEB 0x90 Header
// 4 1 0x01 Frame type
// 5 1 0x4F Frame counter
// 6 4 0x58 0x02 0x00 0x00 Unknown6
// 6 4 0x58 0x02 0x00 0x00 ** [JK-PB2A16S-20P v14] VOLTAGE SMART SLEEP
ESP_LOGD(TAG, " Unknown6: %f", (float) jk_get_32bit(6) * 0.001f);
// 10 4 0x54 0x0B 0x00 0x00 Cell UVP
ESP_LOGI(TAG, " Cell UVP: %f V", (float) jk_get_32bit(10) * 0.001f);
this->publish_state_(this->cell_voltage_undervoltage_protection_number_, (float) jk_get_32bit(10) * 0.001f);

// 14 4 0x80 0x0C 0x00 0x00 Cell OVP Recovery
// 14 4 0x80 0x0C 0x00 0x00 Cell UVP Recovery
ESP_LOGI(TAG, " Cell UVPR: %f V", (float) jk_get_32bit(14) * 0.001f);
this->publish_state_(this->cell_voltage_undervoltage_recovery_number_, (float) jk_get_32bit(14) * 0.001f);

Expand All @@ -816,10 +820,10 @@ void JkBmsBle::decode_jk02_settings_(const std::vector<uint8_t> &data) {
ESP_LOGI(TAG, " Balance trigger voltage: %f V", (float) jk_get_32bit(26) * 0.001f);
this->publish_state_(this->balance_trigger_voltage_number_, (float) jk_get_32bit(26) * 0.001f);

// 30 4 0x00 0x00 0x00 0x00 Unknown30
// 34 4 0x00 0x00 0x00 0x00 Unknown34
// 38 4 0x00 0x00 0x00 0x00 Unknown38
// 42 4 0x00 0x00 0x00 0x00 Unknown42
// 30 4 0x00 0x00 0x00 0x00 ** [JK-PB2A16S-20P v14] SOC-100% VOLTAGE
// 34 4 0x00 0x00 0x00 0x00 ** [JK-PB2A16S-20P v14] SOC-0% VOLTAGE
// 38 4 0x00 0x00 0x00 0x00 ** [JK-PB2A16S-20P v14] VOLTAGE CELL REQUEST CHARGE VOLTAGE
// 42 4 0x00 0x00 0x00 0x00 ** [JK-PB2A16S-20P v14] VOLTAGE CELL REQUEST FLOAT VOLTAGE
// 46 4 0xF0 0x0A 0x00 0x00 Power off voltage
ESP_LOGI(TAG, " Power off voltage: %f V", (float) jk_get_32bit(46) * 0.001f);
this->publish_state_(this->power_off_voltage_number_, (float) jk_get_32bit(46) * 0.001f);
Expand All @@ -830,15 +834,15 @@ void JkBmsBle::decode_jk02_settings_(const std::vector<uint8_t> &data) {

// 54 4 0x1E 0x00 0x00 0x00 Charge OCP delay
ESP_LOGI(TAG, " Charge OCP delay: %f s", (float) jk_get_32bit(54));
// 58 4 0x3C 0x00 0x00 0x00 Charge OCP recovery delay
// 58 4 0x3C 0x00 0x00 0x00 Charge OCP recovery time
ESP_LOGI(TAG, " Charge OCP recovery delay: %f s", (float) jk_get_32bit(58));
// 62 4 0xF0 0x49 0x02 0x00 Max. discharge current
ESP_LOGI(TAG, " Max. discharge current: %f A", (float) jk_get_32bit(62) * 0.001f);
this->publish_state_(this->max_discharge_current_number_, (float) jk_get_32bit(62) * 0.001f);

// 66 4 0x2C 0x01 0x00 0x00 Discharge OCP delay
ESP_LOGI(TAG, " Discharge OCP recovery delay: %f s", (float) jk_get_32bit(66));
// 70 4 0x3C 0x00 0x00 0x00 Discharge OCP recovery delay
// 70 4 0x3C 0x00 0x00 0x00 Discharge OCP recovery time
ESP_LOGI(TAG, " Discharge OCP recovery delay: %f s", (float) jk_get_32bit(70));
// 74 4 0x3C 0x00 0x00 0x00 SCPR time
ESP_LOGI(TAG, " SCP recovery time: %f s", (float) jk_get_32bit(74));
Expand Down Expand Up @@ -929,13 +933,26 @@ void JkBmsBle::decode_jk02_settings_(const std::vector<uint8_t> &data) {
// 274 4 0x00 0x00 0x00 0x00
// 278 4 0x00 0x00 0x00 0x00
// 282 1 0x00 New controls bitmask
// ** [JK-PB2A16S-20P v14]
// bit0: HEATING_SWITCH_ENABLED
// bit1: DISABLE_TEMP_SENSOR_SWITCH_ENABLED
// bit2: ?
// bit3: ?
// bit4: DISPLAY_ALWAYS_ON_SWITCH_ENABLED
// bit5: ?
// bit6: SMART_SLEEP_ON_SWITCH_ENABLED
// bit7: DISABLE_PCL_MODULE_SWITCH_ENABLED
this->publish_state_(this->heating_switch_, check_bit_(data[282], 1));
ESP_LOGI(TAG, " heating switch: %s", ((bool) check_bit_(data[282], 1)) ? "on" : "off");
this->publish_state_(this->disable_temperature_sensors_switch_, check_bit_(data[282], 2));
this->publish_state_(this->display_always_on_switch_, check_bit_(data[282], 16));
ESP_LOGI(TAG, " Port switch: %s", check_bit_(data[282], 8) ? "RS485" : "CAN");

// 283 3 0x00 0x00 0x00
// 283 1 0x00
// ** [JK-PB2A16S-20P v14]
// bit0: TIME_STORED_DATA_SWITCH_ENABLED
// bit1: CHARGING_FLOAT_MODE_SWITCH_ENABLED
// 284 2 0X00 0X00
// 286 4 0x00 0x00 0x00 0x00
// 290 4 0x00 0x00 0x00 0x00
// 294 4 0x00 0x00 0x00 0x00
Expand Down
75 changes: 75 additions & 0 deletions components/jk_rs485/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import uart
from esphome.const import CONF_ADDRESS, CONF_ID

CODEOWNERS = ["@syssi"]
AUTO_LOAD = ["binary_sensor", "button", "number", "sensor", "switch", "text_sensor"]

DEPENDENCIES = ["uart"]
MULTI_CONF = True

CONF_PROTOCOL_VERSION = "protocol_version"
CONF_JK_RS485_ID = "jk_rs485_id"
CONF_RX_TIMEOUT = "rx_timeout"
CONF_ADDRESS = "address"

jk_rs485_ns = cg.esphome_ns.namespace("jk_rs485")
JkRS485 = jk_rs485_ns.class_("JkRS485", cg.Component, uart.UARTDevice)
JkRS485Device = jk_rs485_ns.class_("JkRS485Device")

ProtocolVersion = jk_rs485_ns.enum("ProtocolVersion")
PROTOCOL_VERSION_OPTIONS = {
"JK04": ProtocolVersion.PROTOCOL_VERSION_JK04,
"JK02_24S": ProtocolVersion.PROTOCOL_VERSION_JK02_24S,
"JK02_32S": ProtocolVersion.PROTOCOL_VERSION_JK02_32S,
}

CONFIG_SCHEMA = (
cv.Schema(
{
cv.GenerateID(): cv.declare_id(JkRS485),
cv.Optional(
CONF_RX_TIMEOUT, default="50ms"
): cv.positive_time_period_milliseconds,
cv.Required(CONF_PROTOCOL_VERSION): cv.enum(
PROTOCOL_VERSION_OPTIONS, upper=True
),
cv.Required(CONF_ADDRESS): cv.All(cv.uint8_t, cv.Range(min=0,max=15)),
}
)
.extend(cv.COMPONENT_SCHEMA)
.extend(uart.UART_DEVICE_SCHEMA)
)


async def to_code(config):
cg.add_global(jk_rs485_ns.using)
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)

await uart.register_uart_device(var, config)

cg.add(var.set_rx_timeout(config[CONF_RX_TIMEOUT]))
# cg.add(var.set.address(config[CONF_ADDRESS]))
# cg.add(var.set.protocol_version(config[CONF_PROTOCOL_VERSION]))


def jk_rs485_device_schema(default_address):
schema = {
cv.GenerateID(CONF_JK_RS485_ID): cv.use_id(JkRS485),
}
if default_address is None:
schema[cv.Required(CONF_ADDRESS)] = cv.hex_uint8_t
else:
schema[cv.Optional(CONF_ADDRESS, default=default_address)] = cv.hex_uint8_t
return cv.Schema(schema)


async def register_jk_rs485_device(var, config):
parent = await cg.get_variable(config[CONF_JK_RS485_ID])
cg.add(var.set_parent(parent))
cg.add(var.set_address(config[CONF_ADDRESS]))
cg.add(var.set_protocol_version(config[CONF_PROTOCOL_VERSION]))
cg.add(var.set_rx_timeout(config[CONF_RX_TIMEOUT]))
cg.add(parent.register_device(var))
60 changes: 60 additions & 0 deletions components/jk_rs485/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import esphome.codegen as cg
from esphome.components import binary_sensor
import esphome.config_validation as cv
from esphome.const import CONF_ID, DEVICE_CLASS_CONNECTIVITY, ENTITY_CATEGORY_DIAGNOSTIC

from . import CONF_JK_RS485_ID, JkRS485
from .const import CONF_CHARGING, CONF_DISCHARGING, CONF_HEATING

#DEPENDENCIES = ["jk_bms_modbus"]
DEPENDENCIES = ["jk_rs485"]

CODEOWNERS = ["@syssi"]

CONF_BALANCING = "balancing"
CONF_ONLINE_STATUS = "online_status"

ICON_CHARGING = "mdi:battery-charging"
ICON_DISCHARGING = "mdi:power-plug"
ICON_BALANCING = "mdi:battery-heart-variant"
ICON_HEATING = "mdi:radiator"

BINARY_SENSORS = [
CONF_CHARGING,
CONF_DISCHARGING,
CONF_BALANCING,
CONF_ONLINE_STATUS,
CONF_HEATING,
]

CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(CONF_JK_RS485_ID): cv.use_id(JkRS485),
cv.Optional(CONF_CHARGING): binary_sensor.binary_sensor_schema(
icon=ICON_CHARGING
),
cv.Optional(CONF_DISCHARGING): binary_sensor.binary_sensor_schema(
icon=ICON_DISCHARGING
),
cv.Optional(CONF_BALANCING): binary_sensor.binary_sensor_schema(
icon=ICON_BALANCING
),
cv.Optional(CONF_HEATING): binary_sensor.binary_sensor_schema(
icon=ICON_HEATING
),
cv.Optional(CONF_ONLINE_STATUS): binary_sensor.binary_sensor_schema(
device_class=DEVICE_CLASS_CONNECTIVITY,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
}
)


async def to_code(config):
hub = await cg.get_variable(config[CONF_JK_RS485_ID])
for key in BINARY_SENSORS:
if key in config:
conf = config[key]
sens = cg.new_Pvariable(conf[CONF_ID])
await binary_sensor.register_binary_sensor(sens, conf)
cg.add(getattr(hub, f"set_{key}_binary_sensor")(sens))
6 changes: 6 additions & 0 deletions components/jk_rs485/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Constants for the jk bms ble component."""

CONF_BALANCER = "balancer"
CONF_CHARGING = "charging"
CONF_DISCHARGING = "discharging"
CONF_HEATING = "heating"