Program is reading RS232 serial port of PYTES and PYLONTECH LiFePo4 batteries.
"pwr" and "bat" commands are used. Program reads serial port with a specific frequency, parsing the data and saving a JSON file that can be used in further automation.
Configurable OPTIONS:
- record data to MariaDB
- send data via MQTT
- events monitoring - when power_events, battery_events or system faults occurred a log file is created with cells details
- cell monitoring - read cells details for all batteries in bank. Three levels of details can be selected in config file. more details/explanation can be found here
These options can be activated / deactivated in configuration file (pytes_serial.cfg)
When MQTT is activated:
-
JSON file is send as payload to the following topic: 'homeassistant/sensor/pytes/state'
-
program has build-in integration with Home Assisant where the following sensors will be automatic created for each battery:"current", "voltage", "temperature", "soc", "status". The battery number is embedded at the end of each sensor (i.e current_1, current_2...).
When cell monitoring is activated an additional device will be created in Home Assistant with suffix "_cells" with all associated sensors. The battery and cell number is embedded at the end of each sensor ( i.e. voltage_102 means voltage for battery 1 cell 2). Basic statistics is implemented too. Therefore, additional sensors will be available for min, max and delta for cells voltage and temperature. (i.e. pytes_cells_voltage_max_1 means max cells voltage for battery 1)
If more sensors will be needed, they can be added manually as per Home Assistant documentation MQTT sensor and the example in docs folder here.
You have more examples for better understanding of what program does.
Serial cable must be connected to battery 1 (master).
-
copy current repository
-
optional: a. if you want to use MariaDB:
- MariaDB database must be installed (MariaDB documentation is out of this project scope)
- use sql/pytes_mariadb.sql to import required database and tables
b. if you want to use MQTT / MQTT integration in Home Assistant:
- MQTT broker must be installed (MQTT documentation is out of this project scope)
- if you use Home Assistant, make sure that MQTT auto discovery is set true and sensors will be auto discovered when program will start
-
rename pytes_serial.cfg.example in pytes_serial.cfg and configure it as per your needs (do not remark or delete lines in sections just do the configuration)
-
make sure that all required python modules are installed see requirements
-
go to the folder where the program is located (i.e cd /home/pi/Documents/pytes)
-
execute pytes_serial.sh to have a separate terminal instance (works for Linux/Raspberry) or python3 pytes_serial.py directly from console. if you need setup an autostart of the program on reboot more info here
A lighter version written in Micropython for ESP32 is available here:pytes_esp
enjoy