Skip to content

Commit

Permalink
add soh and port_voltage
Browse files Browse the repository at this point in the history
  • Loading branch information
Privatecoder committed Jan 19, 2024
1 parent b5f9477 commit 3445bee
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ ENV PYTHONUNBUFFERED 1
ENV RS485_REMOTE_IP=192.168.1.200
ENV RS485_REMOTE_PORT=4196


# Run socat in the background and then execute app.py
CMD socat pty,link=/tmp/vcom0,raw tcp:$RS485_REMOTE_IP:$RS485_REMOTE_PORT,retry,interval=.2,forever & python fetch_bms_data.py
14 changes: 13 additions & 1 deletion ha-sample/seplos_pack-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@
unit_of_measurement: 'V'
value_template: "{{ value_json.status.voltage }}"
unique_id: "seplos_pack_1_voltage"

- name: "Seplos Pack-1 Port Voltage"
state_topic: "seplos/pack-1/sensors"
unit_of_measurement: 'V'
value_template: "{{ value_json.status.port_voltage }}"
unique_id: "seplos_pack_1_port_voltage"

# Capacity Sensors
- name: "Seplos Pack-1 Capacity Rated"
Expand All @@ -178,7 +184,7 @@
value_template: "{{ value_json.status.capacity_remain }}"
unique_id: "seplos_pack_1_capacity_remain"

# SOC and Cycles Sensors
# SOC, SOH and Cycles Sensors
- name: "Seplos Pack-1 SOC"
state_topic: "seplos/pack-1/sensors"
unit_of_measurement: '%'
Expand All @@ -189,6 +195,12 @@
state_topic: "seplos/pack-1/sensors"
value_template: "{{ value_json.status.cycles }}"
unique_id: "seplos_pack_1_cycles"

- name: "Seplos Pack-1 SOH"
state_topic: "seplos/pack-1/sensors"
unit_of_measurement: '%'
value_template: "{{ value_json.status.soh }}"
unique_id: "seplos_pack_1_soh"

# Alarm Cell Voltage Sensors
- name: "Seplos Pack-1 Alarm Voltage Cell Low"
Expand Down
14 changes: 14 additions & 0 deletions src/fetch_bms_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ def __init__(self, battery_pack_address):

self.voltage = None
self.current = None
self.port_voltage = None

self.capacity_rated = None
self.capacity = None
self.capacity_remain = None
self.soc = None
self.soh = None

self.cycles = None

Expand Down Expand Up @@ -421,6 +423,8 @@ def decode_status_data(self, data):
soc_offset = 114
capacity_rated_offset = 118
cycles_offset = 122
soh_offset = 126
port_voltage_offset = 130

# fetch cell count
self.cell_count = self.int_from_1byte_hex_ascii(
Expand Down Expand Up @@ -500,15 +504,25 @@ def decode_status_data(self, data):
# fetch cycles
self.cycles = self.int_from_2byte_hex_ascii(data, cycles_offset)
status_data["cycles"] = self.cycles

# fetch soh
self.soh = self.int_from_2byte_hex_ascii(data, soh_offset) / 10
status_data["soh"] = self.soh

# fetch port voltage
self.port_voltage = self.int_from_2byte_hex_ascii(data, port_voltage_offset) / 100
status_data["port_voltage"] = self.port_voltage

logger.info("Current = {}A".format(self.current))
logger.info("Voltage = {}V".format(self.voltage))
logger.info("Port Voltage = {}V".format(self.port_voltage))

logger.info("Rated Capacity = {}Ah".format(self.capacity_rated))
logger.info("Capacity = {}Ah".format(self.capacity))
logger.info("Remaining Capacity = {}Ah".format(self.capacity_remain))

logger.info("SOC = {}%".format(self.soc))
logger.info("SOH = {}%".format(self.soh))

logger.info("Cycles = {}".format(self.cycles))

Expand Down

0 comments on commit 3445bee

Please sign in to comment.