modbus: - name: JKBMS1 type: serial method: rtu port: /dev/ttyACM2 baudrate: 115200 stopbits: 1 bytesize: 8 parity: N message_wait_milliseconds: 30 sensors: - name: "Battery 1 charge enable" unique_id: "battery_1_charge_enable" slave: 0 address: 0x1070 input_type: holding data_type: uint32 scan_interval: 5 - name: "Battery 1 discharge enable" unique_id: "battery_1_discharge_enable" slave: 0 address: 0x1074 input_type: holding data_type: uint32 scan_interval: 5 - name: "Battery 1 balance enable" unique_id: "battery_1_balance_enable" slave: 0 address: 0x1078 input_type: holding data_type: uint32 scan_interval: 5 - name: "Battery 1 flags" unique_id: "battery_1_flags" slave: 0 address: 0x1114 input_type: holding data_type: uint16 scan_interval: 5 - name: "Battery 1 cell voltages" unique_id: "battery_1_cell_voltages" slave: 0 address: 0x1200 input_type: holding data_type: custom count: 16 structure: ">16H" scan_interval: 15 - name: "Battery 1 cell average voltage" unique_id: "battery_1_cell_average_voltage" slave: 0 address: 0x1244 input_type: holding data_type: uint16 state_class: measurement device_class: voltage unit_of_measurement: V scale: 0.001 precision: 3 scan_interval: 5 - name: "Battery 1 cell differential voltage" unique_id: "battery_1_cell_differential_voltage" slave: 0 address: 0x1246 input_type: holding data_type: uint16 state_class: measurement device_class: voltage unit_of_measurement: mV scale: 1 precision: 0 scan_interval: 5 - name: "Battery 1 cell index" unique_id: "battery_1_cell_index" slave: 0 address: 0x1248 input_type: holding data_type: uint16 scan_interval: 5 - name: "Battery 1 MOSFET temperature" unique_id: "battery_1_mosfet_temperature" slave: 0 address: 0x128A input_type: holding data_type: int16 state_class: measurement device_class: temperature unit_of_measurement: "°C" scale: 0.1 precision: 1 scan_interval: 5 - name: "Battery 1 voltage" unique_id: "battery_1_voltage" slave: 0 address: 0x1290 input_type: holding data_type: uint32 state_class: measurement device_class: voltage unit_of_measurement: V scale: 0.001 precision: 2 scan_interval: 5 - name: "Battery 1 current" unique_id: "battery_1_current" slave: 0 address: 0x1298 input_type: holding data_type: int32 state_class: measurement device_class: current unit_of_measurement: A scale: -0.001 precision: 2 scan_interval: 5 - name: "Battery 1 temperature T1" unique_id: "battery_1_temperature_t1" slave: 0 address: 0x129C input_type: holding data_type: int16 state_class: measurement device_class: temperature unit_of_measurement: "°C" scale: 0.1 precision: 1 scan_interval: 5 - name: "Battery 1 temperature T2" unique_id: "battery_1_temperature_t2" slave: 0 address: 0x129E input_type: holding data_type: int16 state_class: measurement device_class: temperature unit_of_measurement: "°C" scale: 0.1 precision: 1 scan_interval: 5 - name: "Battery 1 fault code" unique_id: "battery_1_fault_code" slave: 0 address: 0x12A0 input_type: holding data_type: uint32 scan_interval: 5 - name: "Battery 1 balance current" unique_id: "battery_1_balance_current" slave: 0 address: 0x12A4 input_type: holding data_type: int16 state_class: measurement device_class: current unit_of_measurement: A scale: 0.001 precision: 3 scan_interval: 5 - name: "Battery 1 0x12A6" unique_id: "battery_1_0x12A6" slave: 0 address: 0x12A6 data_type: uint16 scan_interval: 5 - name: "Battery 1 remaining capacity" unique_id: "battery_1_remaining_capacity" slave: 0 address: 0x12A8 input_type: holding data_type: int32 state_class: measurement unit_of_measurement: Ah scale: 0.001 precision: 1 scan_interval: 5 - name: "Battery 1 capacity" unique_id: "battery_1_capacity" slave: 0 address: 0x12AC input_type: holding data_type: uint32 state_class: measurement unit_of_measurement: Ah scale: 0.001 precision: 1 scan_interval: 5 - name: "Battery 1 cycle count" unique_id: "battery_1_cycle_count" slave: 0 address: 0x12B0 input_type: holding data_type: uint32 state_class: measurement scan_interval: 5 - name: "Battery 1 total cycle capacity" unique_id: "battery_1_total_cycle_capacity" slave: 0 address: 0x12B4 input_type: holding data_type: uint32 state_class: measurement unit_of_measurement: Ah scale: 0.001 precision: 1 scan_interval: 5 - name: "Battery 1 0x12C0" unique_id: "battery_1_0x12C0" slave: 0 address: 0x12C0 input_type: holding data_type: uint16 scan_interval: 5 - name: "Battery 1 temperature T3" unique_id: "battery_1_temperature_t3" slave: 0 address: 0x12F8 input_type: holding data_type: int16 state_class: measurement device_class: temperature unit_of_measurement: "°C" scale: 0.1 precision: 1 scan_interval: 5 - name: "Battery 1 temperature T4" unique_id: "battery_1_temperature_t4" slave: 0 address: 0x12FA input_type: holding data_type: int16 state_class: measurement device_class: temperature unit_of_measurement: "°C" scale: 0.1 precision: 1 scan_interval: 5 - name: "Battery 1 temperature T5" unique_id: "battery_1_temperature_t5" slave: 0 address: 0x12FC input_type: holding data_type: int16 state_class: measurement device_class: temperature unit_of_measurement: "°C" scale: 0.1 precision: 1 scan_interval: 5 - name: "Battery 1 modell" unique_id: "battery_1_modell" slave: 0 address: 0x1400 input_type: holding data_type: string count: 8 scan_interval: 3600 - name: "Battery 1 hardware version" unique_id: "battery_1_hardware_version" slave: 0 address: 0x1410 input_type: holding data_type: string count: 4 scan_interval: 3600 - name: "Battery 1 software version" unique_id: "battery_1_software_version" slave: 0 address: 0x1418 input_type: holding data_type: string count: 4 scan_interval: 3600 - name: "Battery 1 password" unique_id: "battery_1_password" slave: 0 address: 0x1436 input_type: holding data_type: string count: 8 scan_interval: 3600 - name: "Battery 1 serial number" unique_id: "battery_1_serial_number" slave: 0 address: 0x144E input_type: holding data_type: string count: 7 scan_interval: 3600 input_boolean: battery_1_show_more: name: "Battery 1 show more" switch: - platform: template switches: battery_1_charge_enable: friendly_name: "Battery 1 charge enable" unique_id: "battery_1_charge_enable" value_template: "{{ int(states('sensor.battery_1_charge_enable'), 0) == 1 }}" # icon_template: >- # {% if int(states('sensor.battery_1_charge_enable'), 0) == 1 %} # mdi:toggle-switch-off-outline # {% else %} # mdi:toggle-switch-outline # {% endif %} turn_on: service: modbus.write_register data_template: hub: "JKBMS1" slave: 0 address: 0x1070 value: [0, 1] turn_off: service: modbus.write_register data_template: hub: "JKBMS1" slave: 0 address: 0x1070 value: [0, 0] battery_1_discharge_enable: friendly_name: "Battery 1 discharge enable" unique_id: "battery_1_discharge_enable" value_template: "{{ int(states('sensor.battery_1_discharge_enable'), 0) == 1 }}" # icon_template: >- # {% if int(states('sensor.battery_1_discharge_enable'), 0) == 1 %} # mdi:toggle-switch-off-outline # {% else %} # mdi:toggle-switch-outline # {% endif %} turn_on: service: modbus.write_register data_template: hub: "JKBMS1" slave: 0 address: 0x1074 value: [0, 1] turn_off: service: modbus.write_register data_template: hub: "JKBMS1" slave: 0 address: 0x1074 value: [0, 0] battery_1_balance_enable: friendly_name: "Battery 1 balance enable" unique_id: "battery_1_balance_enable" value_template: "{{ int(states('sensor.battery_1_balance_enable'), 0) == 1 }}" # icon_template: >- # {% if int(states('sensor.battery_1_balance_enable'), 0) == 1 %} # mdi:toggle-switch-off-outline # {% else %} # mdi:toggle-switch-outline # {% endif %} turn_on: service: modbus.write_register data_template: hub: "JKBMS1" slave: 0 address: 0x1078 value: [0, 1] turn_off: service: modbus.write_register data_template: hub: "JKBMS1" slave: 0 address: 0x1078 value: [0, 0] battery_1_float_mode_enable: friendly_name: "Battery 1 float mode enable" unique_id: "battery_1_float_mode_enable" value_template: "{{ int(states('sensor.battery_1_flags'), 0) | int | bitwise_and(512) != 0}}" # icon_template: >- # {% if int(states('sensor.battery_1_flags'), 0) | int | bitwise_and(512) != 0 %} # mdi:toggle-switch-off-outline # {% else %} # mdi:toggle-switch-outline # {% endif %} turn_on: service: modbus.write_register data_template: hub: "JKBMS1" slave: 0 address: 0x1114 value: [ "{{ int(states('sensor.battery_1_flags'), 0) | bitwise_or(512) }}", ] turn_off: service: modbus.write_register data_template: hub: "JKBMS1" slave: 0 address: 0x1114 value: [ "{{ int(states('sensor.battery_1_flags'), 0) | bitwise_and(0xfdff) }}", ] sensor: - platform: integration source: sensor.battery_1_charge_current name: "Battery 1 charge Ah" unique_id: "battery_1_charge_ah" unit_time: h method: left round: 2 max_sub_interval: minutes: 1 - platform: integration source: sensor.battery_1_discharge_current name: "Battery 1 discharge Ah" unique_id: "battery_1_discharge_ah" unit_time: h method: left round: 2 max_sub_interval: minutes: 1 - platform: integration source: sensor.battery_1_charge_power name: "Battery 1 charge energy total" unique_id: "battery_1_charge_energy_total" unit_prefix: k unit_time: h method: left round: 2 max_sub_interval: seconds: 5 - platform: integration source: sensor.battery_1_discharge_power name: "Battery 1 discharge energy total" unique_id: "battery_1_discharge_energy_total" unit_prefix: k unit_time: h method: left round: 2 max_sub_interval: seconds: 5 utility_meter: battery_1_charge_energy_today: name: "Battery 1 charge energy today" unique_id: "battery_1_charge_energy_today" source: sensor.battery_1_charge_energy_total cycle: daily battery_1_discharge_energy_today: name: "Battery 1 discharge energy today" unique_id: "battery_1_discharge_energy_today" source: sensor.battery_1_discharge_energy_total cycle: daily template: - sensor: - name: "Battery 1 power" unique_id: "battery_1_power" unit_of_measurement: W device_class: power state_class: measurement state: >- {% set voltage = states('sensor.battery_1_voltage') %} {% set current = states('sensor.battery_1_current') %} {% if (voltage | is_number) and (current | is_number) %} {{ (float(voltage) * float(current)) | round(0) }} {% endif %} - name: "Battery 1 charge power" unique_id: "battery_1_charge_power" unit_of_measurement: W device_class: power state_class: measurement state: >- {% set power = states('sensor.battery_1_power') %} {% if (power | is_number) and (float(power) < 0) %} {{ -float(power) | round(2) }} {% else %} 0 {% endif %} - name: "Battery 1 discharge power" unique_id: "battery_1_discharge_power" unit_of_measurement: W device_class: power state_class: measurement state: >- {% set power = states('sensor.battery_1_power') %} {% if (power | is_number) and (float(power) > 0) %} {{ float(power) | round(2) }} {% else %} 0 {% endif %} - name: "Battery 1 charge current" unique_id: "battery_1_charge_current" unit_of_measurement: A device_class: current state_class: measurement state: >- {% set current = states('sensor.battery_1_current') %} {% if (current | is_number) and (float(current) < 0) %} {{ -float(current) | round(2) }} {% else %} 0 {% endif %} - name: "Battery 1 discharge current" unique_id: "battery_1_discharge_current" unit_of_measurement: A device_class: current state_class: measurement state: >- {% set current = states('sensor.battery_1_current') %} {% if (current | is_number) and (float(current) > 0) %} {{ float(current) | round(2) }} {% else %} 0 {% endif %} - name: "Battery 1 SOC" unique_id: "battery_1_soc" unit_of_measurement: "%" device_class: battery state_class: measurement state: >- {% set capacity = states('sensor.battery_1_capacity') %} {% set remaining = states('sensor.battery_1_remaining_capacity') %} {% if (capacity | is_number) and (remaining | is_number) %} {{ (float(remaining) / float(capacity) * 100.0) | round(1) }} {% endif %} - name: "Battery 1 balance state" unique_id: "battery_1_balance_state" state: "{{ (int(states('sensor.battery_1_0x12A6'), 0) | int / 256) | int }}" - name: "Battery 1 cell min index" unique_id: "battery_1_cell_min_index" state: "{{ (int(states('sensor.battery_1_cell_index'), 0) | int % 256) | int +1 }}" - name: "Battery 1 cell max index" unique_id: "battery_1_cell_max_index" state: "{{ (int(states('sensor.battery_1_cell_index'), 0) | int / 256) | int +1 }}" - name: "Battery 1 cell 01 voltage" unique_id: "battery_1_cell_01_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[0], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 1 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 1 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 02 voltage" unique_id: "battery_1_cell_02_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[1], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 2 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 2 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 03 voltage" unique_id: "battery_1_cell_03_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[2], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 3 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 3 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 04 voltage" unique_id: "battery_1_cell_04_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[3], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 4 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 4 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 05 voltage" unique_id: "battery_1_cell_05_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[4], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 5 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 5 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 06 voltage" unique_id: "battery_1_cell_06_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[5], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 6 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 6 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 07 voltage" unique_id: "battery_1_cell_07_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[6], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 7 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 7 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 08 voltage" unique_id: "battery_1_cell_08_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[7], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 8 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 8 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 09 voltage" unique_id: "battery_1_cell_09_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[8], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 9 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 9 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 10 voltage" unique_id: "battery_1_cell_10_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[9], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 10 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 10 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 11 voltage" unique_id: "battery_1_cell_11_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[10], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 11 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 11 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 12 voltage" unique_id: "battery_1_cell_12_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[11], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 12 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 12 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 13 voltage" unique_id: "battery_1_cell_13_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[12], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 13 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 13 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 14 voltage" unique_id: "battery_1_cell_14_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[13], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 14 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 14 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 15 voltage" unique_id: "battery_1_cell_15_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[14], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 15 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 15 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - name: "Battery 1 cell 16 voltage" unique_id: "battery_1_cell_16_voltage" unit_of_measurement: V device_class: voltage state_class: measurement state: "{{ (float(states('sensor.battery_1_cell_voltages').split(',')[15], 0) * 0.001) | round(3) }}" attributes: color: > {% if int(states('sensor.battery_1_cell_min_index'), 0) == 16 -%} cyan {%- else -%} {% if int(states('sensor.battery_1_cell_max_index'), 0) == 16 -%} red {%- else -%} inherit {%- endif %} {%- endif %} - binary_sensor: - name: "Battery 1 discharge state" unique_id: "battery_1_discharge_state" state: "{{ (int(states('sensor.battery_1_0x12C0'), 0) | int % 256) | int }}" - name: "Battery 1 charge state" unique_id: "battery_1_charge_state" state: "{{ (int(states('sensor.battery_1_0x12C0'), 0) | int / 256) | int }}" recorder: exclude: entities: - sensor.battery_1_flags - sensor.battery_1_cell_voltages - sensor.battery_1_cell_index - sensor.battery_1_fault_code - sensor.battery_1_balance_current - sensor.battery_1_0x12A6 - sensor.battery_1_capacity - sensor.battery_1_0x12C0 - sensor.battery_1_modell - sensor.battery_1_hardware_version - sensor.battery_1_software_version - sensor.battery_1_password - sensor.battery_1_serial_number - sensor.battery_1_charge_power - sensor.battery_1_discharge_power - sensor.battery_1_charge_current - sensor.battery_1_discharge_current - sensor.battery_1_balance_state - sensor.battery_1_cell_min_index - sensor.battery_1_cell_max_index - input_boolean.battery_1_show_more - binary_sensor.battery_1_charge_state - binary_sensor.battery_1_discharge_state - sensor.battery_1_cell_01_voltage - sensor.battery_1_cell_02_voltage - sensor.battery_1_cell_03_voltage - sensor.battery_1_cell_04_voltage - sensor.battery_1_cell_05_voltage - sensor.battery_1_cell_06_voltage - sensor.battery_1_cell_07_voltage - sensor.battery_1_cell_08_voltage - sensor.battery_1_cell_09_voltage - sensor.battery_1_cell_10_voltage - sensor.battery_1_cell_11_voltage - sensor.battery_1_cell_12_voltage - sensor.battery_1_cell_13_voltage - sensor.battery_1_cell_14_voltage - sensor.battery_1_cell_15_voltage - sensor.battery_1_cell_16_voltage