Skip to content

s3pt1c0/Pytes_ESP32_RS232

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

42 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”Œ PYTES Battery to Home Assistant via ESPHome

ESPHome custom component for monitoring PYTES LiFePO4 battery systems πŸ”‹ via RS232 serial port. This application runs on an ESP32 board πŸ“‘, reads the battery console port and integrates automatically with Home Assistant 🏠.

Support for up to 6️⃣ individual battery modules with real-time monitoring of voltage ⚑, current πŸ”Œ, temperature 🌑️, SoC πŸ“Š, and status πŸš₯.


✨ Features

  • πŸ“Š Real-time monitoring of battery bank and individual battery metrics
  • πŸ”‹ Multi-battery support (up to 6 battery modules)
  • 🌑️ Temperature monitoring for each battery module
  • ⚑ Power flow tracking (voltage, current, power)
  • πŸ“ˆ State of Charge (SoC) percentage for bank and individual batteries
  • πŸš₯ Status monitoring (operational state, voltage status, alerts)
  • πŸ”Œ Native Home Assistant integration via ESPHome API
  • 🌐 Built-in web server for standalone monitoring
  • πŸ”„ Configurable polling interval (default 30s)
  • πŸ†” Serial number and firmware tracking for each battery
  • πŸ“ Configurable battery capacity for accurate calculations

πŸ”Œ Supported Hardware

πŸ”‹ Tested Pytes Battery Models

  • βœ… Pytes V5Β° (48V 5kWh module)
  • βœ… Pytes E-Box-48100R (48V 10kWh system)
  • βœ… Pytes E-Box-12100 (12V systems)
  • βœ… Pytes Pi-LV1 (Low voltage systems)

πŸ’‘ Note: This component should work with any Pytes battery system that supports the RS232 console protocol.

πŸ–₯️ ESP32 Development Boards

  • βœ… ESP32-DevKitC
  • βœ… ESP32-WROOM-32
  • βœ… ESP32-WROVER
  • βœ… Any ESP32 board with ESP-IDF framework support (minimum chip revision 3.1)

πŸ› οΈ Hardware Requirements

πŸ“¦ Required Components

Component Quantity Description Example/Notes
πŸ–₯️ ESP32 DevKit 1 ESP32 development board Minimum chip revision 3.1
πŸ”‹ Pytes Battery 1-6 LiFePO4 battery system With RS232 console port
πŸ”Œ RS232-to-TTL Module 1 MAX3232 or equivalent 3.3V logic level
πŸ”— Dupont Wires ~10 Jumper cables Female-to-female
πŸ”Œ USB Cable 1 For ESP32 power/programming Micro-USB or USB-C
⚑ Power Supply 1 5V power adapter Optional for standalone operation

🎁 Optional Components

  • πŸ“¦ Enclosure - To protect the ESP32 and connections
  • 🏭 DIN rail mount - For professional installation
  • πŸ’‘ Status LEDs - For visual monitoring

πŸ”Œ Wiring Diagram

πŸ“Œ Pin Connections

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   ESP32 DevKit  β”‚              β”‚  MAX3232 Module  β”‚
β”‚      πŸ–₯️         β”‚              β”‚   (RS232-TTL)    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€              β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ GPIO16 (RX)  ───┼─────────────── TX (TTL out)     β”‚
β”‚ GPIO17 (TX)  ───┼─────────────── RX (TTL in)      β”‚
β”‚ GND          ───┼─────────────── GND              β”‚
β”‚ 3.3V         ───┼─────────────── VCC (3.3V)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                          β”‚
                                          β”‚ πŸ”Œ DB9 cable
                                          β–Ό
                                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                 β”‚  Pytes Battery   β”‚
                                 β”‚  πŸ”‹ RS232 Console β”‚
                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‹ Detailed Pin Mapping

ESP32 GPIO Function MAX3232 Pin Pytes Console
πŸ“ GPIO16 UART RX TX (TTL) TX (RS232)
πŸ“ GPIO17 UART TX RX (TTL) RX (RS232)
⚫ GND Ground GND GND
πŸ”΄ 3.3V Power VCC -

βš™οΈ UART Configuration

  • ⚑ Baud Rate: 115200
  • πŸ“Š Data Bits: 8
  • ❌ Parity: None
  • πŸ›‘ Stop Bits: 1
  • πŸ”€ Flow Control: None

πŸ“₯ Installation

🌐 Method 1: Using GitHub (Recommended)

Add this to your ESPHome YAML configuration:

external_components:
  - source:
      type: git
      url: https://github.com/s3pt1c0/Pytes_ESP32_RS232
      ref: main
    components: [ pytes_rs232 ]
    refresh: 1d

πŸ’Ύ Method 2: Local Installation

1️⃣ Clone or download this repository 2️⃣ Copy the Components/pytes_rs232 folder to your ESPHome configuration directory:

mkdir -p /config/esphome/components
cp -r Pytes_ESP32_RS232/Components/pytes_rs232 /config/esphome/components/

3️⃣ Reference in your YAML:

external_components:
  - source:
      type: local
      path: components

βš™οΈ Configuration

πŸš€ Basic Configuration

Create a file pytes-esp32.yaml:

substitutions:
  device_name: pytes-esp32
  friendly_name: πŸ”‹Pytes Battery MonitorπŸ”‹
  poll_s: "30"              # ⏱️ Polling interval in seconds
  capacity_ah: "100"        # πŸ”‹ Battery capacity in Ah
  num_batts: "6"            # πŸ”’ Number of battery modules

esphome:
  name: ${device_name}
  friendly_name: ${friendly_name}
  comment: "Pytes Battery Monitoring via RS232"

esp32:
  board: esp32dev
  framework:
    type: esp-idf
    advanced: 
      minimum_chip_revision: "3.1"

# πŸ“ Enable logging
logger:
  level: INFO

# 🌐 Enable Web Server (optional)
web_server:
  port: 80

# 🏠 Enable Home Assistant API
api:
  encryption:
    key: "YOUR_ENCRYPTION_KEY_HERE"

# πŸ”„ Enable OTA updates
ota:
  - platform: esphome
    password: "YOUR_OTA_PASSWORD_HERE"

# πŸ“‘ WiFi configuration
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
  # πŸ†˜ Enable fallback hotspot (optional)
  ap:
    ssid: "${device_name} Fallback"
    password: "fallback12345"

# πŸ”Œ UART Configuration for Pytes RS232
uart:
  id: uart_pytes
  tx_pin: GPIO17
  rx_pin: GPIO16
  baud_rate: 115200
  data_bits: 8
  parity: NONE
  stop_bits: 1

# πŸ”‹ Pytes RS232 Component Configuration
pytes_rs232:
  uart_id: uart_pytes
  num_batteries: ${num_batts}
  update_interval: ${poll_s}s
  capacity_ah: ${capacity_ah}
  
  # πŸ“Š Summary sensors (entire battery bank)
  summary:
    voltage: sys_voltage
    current: sys_current
    temperature: sys_temp_f
    coulomb: sys_coulomb
    basic_status: sys_basic_status
  
  # πŸ”‹ Individual battery sensors (repeat for each battery)
  batteries:
    - voltage: b1_voltage
      current: b1_current
      temperature: b1_temp_f
      coulomb: b1_coulomb
      barcode: b1_barcode
      devtype: b1_devtype
      firm_version: b1_firmver
      basic_status: b1_basic_status
      volt_status: b1_volt_status
    # ... repeat for batteries 2-6

πŸ” Secrets Configuration

Create or edit secrets.yaml:

wifi_ssid: "YourWiFiSSID"
wifi_password: "YourWiFiPassword"

πŸ“Š Available Sensors

πŸ“ˆ Summary (Bank-Level) Sensors

Sensor Name Type Unit Description
⚑ Bank Voltage ⚠️ Number V Total battery bank voltage
πŸ”Œ Bank Current⚑ Number A Total bank current (+ charging, - discharging)
🌑️ Bank Temp🌑️ Number °F Average bank temperature
πŸ“Š Bank SoCπŸ“ˆ Number % State of Charge (0-100%)
πŸš₯ Bank StatusπŸš₯ Text - Operational status

πŸ”‹ Individual Battery Sensors (B1-B6)

Sensor Name Type Unit Description
⚑ B[X] Volt⚠️ Number V Individual battery voltage
πŸ”Œ B[X] Current⚑ Number A Individual battery current
🌑️ B[X] Temp🌑️ Number °F Individual battery temperature
πŸ“Š B[X] SoCπŸ“ˆ Number % Individual State of Charge
πŸ”’ B[X] Serial#️⃣ Text - Battery serial/barcode
πŸ†” B[X] ModelπŸ†” Text - Battery model/type
βš™οΈ B[X] Firmwareβš™οΈ Text - Firmware version
πŸš₯ B[X] StatusπŸš₯ Text - Operational status
πŸ“Š B[X] Volt StatusπŸ“Š Text - Voltage status details

πŸ“ Sensor Template Definitions

All sensors are defined as templates in your YAML:

sensor:
  # πŸ“Š Summary sensors
  - platform: template
    name: "Bank Voltage ⚠️"
    id: sys_voltage
    unit_of_measurement: "V"
    accuracy_decimals: 2

  - platform: template
    name: "Bank Current⚑"
    id: sys_current
    unit_of_measurement: "A"
    accuracy_decimals: 2

  # πŸ”‹ Battery 1 sensors
  - platform: template
    name: "B1 Volt⚠️"
    id: b1_voltage
    unit_of_measurement: "V"
    accuracy_decimals: 2

  # ... additional sensors

text_sensor:
  # πŸš₯ Summary status
  - platform: template
    name: "Bank StatusπŸš₯"
    id: sys_basic_status

  # πŸ”‹ Battery 1 info
  - platform: template
    name: "B1 Serial#️⃣"
    id: b1_barcode

  # ... additional text sensors

🏠 Home Assistant Integration

πŸ” Automatic Discovery

Once deployed, the device will automatically appear in Home Assistant under:

βš™οΈ Settings β†’ πŸ”Œ Devices & Services β†’ 🏠 ESPHome

πŸ“± Creating Dashboard Cards

πŸ”‹ Battery Overview Card

type: entities
title: πŸ”‹ Pytes Battery Bank
entities:
  - entity: sensor.pytes_esp32_bank_voltage
    name: ⚑ Voltage
  - entity: sensor.pytes_esp32_bank_current
    name: πŸ”Œ Current
  - entity: sensor.pytes_esp32_bank_soc
    name: πŸ“Š State of Charge
  - entity: sensor.pytes_esp32_bank_temp
    name: 🌑️ Temperature
  - entity: sensor.pytes_esp32_bank_status
    name: πŸš₯ Status

πŸ”‹ Individual Battery Card

type: glance
title: πŸ”‹ Individual Battery Status
entities:
  - entity: sensor.pytes_esp32_b1_soc
    name: Battery 1️⃣
  - entity: sensor.pytes_esp32_b2_soc
    name: Battery 2️⃣
  - entity: sensor.pytes_esp32_b3_soc
    name: Battery 3️⃣
  - entity: sensor.pytes_esp32_b4_soc
    name: Battery 4️⃣
  - entity: sensor.pytes_esp32_b5_soc
    name: Battery 5️⃣
  - entity: sensor.pytes_esp32_b6_soc
    name: Battery 6️⃣

⚑ Power Calculation Helper

Create a template sensor in Home Assistant for power calculation:

template:
  - sensor:
      - name: "Pytes Battery Power"
        unique_id: pytes_battery_power
        unit_of_measurement: "W"
        device_class: power
        state: >
          {% set v = states('sensor.pytes_esp32_bank_voltage')|float(0) %}
          {% set a = states('sensor.pytes_esp32_bank_current')|float(0) %}
          {{ (v * a) | round(1) }}

πŸ“Š Energy Dashboard Integration

To add battery data to the Energy Dashboard:

1️⃣ Go to βš™οΈ Settings β†’ πŸ“Š Dashboards β†’ ⚑ Energy 2️⃣ Click βž• Add Battery System 3️⃣ Select your power sensor (created above) 4️⃣ Configure charge/discharge sensors if available


πŸ”§ Troubleshooting

❌ No Data from Batteries

πŸ”΄ Symptom: All sensors show β€œunavailable” or β€œunknown”

βœ… Solutions:

  1. βœ… Check physical wiring connections (TX/RX crossed)
  2. βœ… Verify RS232-TTL module power (3.3V not 5V)
  3. βœ… Confirm baud rate is 115200
  4. βœ… Check ESPHome logs for UART errors
  5. βœ… Verify Pytes console port is active (some models require activation)

⚠️ Wrong Data or Garbled Output

πŸ”΄ Symptom: Sensors show incorrect values or random characters

βœ… Solutions:

  1. βœ… Double-check TX/RX wiring (may be swapped)
  2. βœ… Ensure ground connection between ESP32 and RS232 module
  3. βœ… Verify 8N1 UART configuration
  4. βœ… Check for loose connections
  5. βœ… Try reducing update interval (increase poll_s)

πŸ“‘ Device Disconnects from WiFi

πŸ”΄ Symptom: ESP32 goes offline periodically

βœ… Solutions:

  1. βœ… Move ESP32 closer to WiFi router
  2. βœ… Use stronger WiFi antenna
  3. βœ… Set static IP in router
  4. βœ… Enable AP fallback mode
  5. βœ… Check power supply (use quality 5V 2A adapter)

πŸ”‹ Only Bank Sensors Work, Individual Batteries Don’t

πŸ”΄ Symptom: Summary sensors update but B1-B6 sensors remain unavailable

βœ… Solutions:

  1. βœ… Verify num_batteries matches actual battery count
  2. βœ… Check that all battery IDs are defined in configuration
  3. βœ… Ensure batteries are properly connected in series
  4. βœ… Review ESPHome logs for parsing errors

🌑️ High Temperature Readings

πŸ”΄ Symptom: Temperature sensors show unusually high values

βœ… Solutions:

  1. βœ… Check if temperature is in Fahrenheit (default) or Celsius
  2. βœ… Verify battery ventilation
  3. βœ… Confirm sensor calibration
  4. βœ… Check for actual overheating condition

πŸ’» Compilation Errors

πŸ”΄ Symptom: ESPHome fails to compile the configuration

βœ… Solutions:

  1. βœ… Update ESPHome to version 2025.1 or newer
  2. βœ… Verify ESP-IDF framework is selected (not Arduino)
  3. βœ… Check minimum chip revision setting (3.1)
  4. βœ… Ensure all required IDs are defined in sensor templates
  5. βœ… Review YAML syntax for errors

πŸ“ Viewing Logs

To troubleshoot issues, view real-time logs:

# πŸ–₯️ From ESPHome dashboard
esphome logs pytes-esp32.yaml

# πŸ“‘ Or via network
esphome logs pytes-esp32.yaml --device pytes-esp32.local

🎨 Advanced Configuration

🌑️ Adding BME280 Temperature Sensor (Optional)

To monitor ambient temperature near the batteries:

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true
  id: bus_a

sensor:
  # ... existing sensors ...
  
  # 🌑️ BME280 sensors
  - platform: bme280
    temperature:
      name: "🌑️ Ambient Temperature"
      id: ambient_temp
      oversampling: 16x
    pressure:
      name: "πŸŒ€ Ambient Pressure"
      id: ambient_pressure
    humidity:
      name: "πŸ’§ Ambient Humidity"
      id: ambient_humidity
    address: 0x76  # or 0x77
    update_interval: 60s

⏱️ Custom Update Intervals per Sensor

pytes_rs232:
  # ... existing config ...
  
  # ⚑ Fast update for critical sensors
  update_interval: 10s
  
# 🐌 Slower update for less critical info
text_sensor:
  - platform: template
    name: "B1 Serial#️⃣"
    id: b1_barcode
    update_interval: 300s  # Update every 5 minutes

πŸ”” Alerts and Notifications

Create automations in Home Assistant:

automation:
  - alias: "⚠️ Battery Low SoC Alert"
    trigger:
      - platform: numeric_state
        entity_id: sensor.pytes_esp32_bank_soc
        below: 20
    action:
      - service: notify.mobile_app
        data:
          title: "⚠️ Battery Low"
          message: "Battery SoC is below 20%"

  - alias: "πŸ”₯ Battery High Temperature Alert"
    trigger:
      - platform: numeric_state
        entity_id: sensor.pytes_esp32_bank_temp
        above: 113  # 45Β°C in Fahrenheit
    action:
      - service: notify.mobile_app
        data:
          title: "πŸ”₯ Battery Overheating"
          message: "Battery temperature exceeds safe limits!"

πŸ—οΈ Repository Structure

Pytes_ESP32_RS232/
β”œβ”€β”€ πŸ“ Components/
β”‚   └── πŸ“ pytes_rs232/
β”‚       β”œβ”€β”€ πŸ“„ __init__.py
β”‚       β”œβ”€β”€ πŸ“„ pytes_rs232.cpp
β”‚       β”œβ”€β”€ πŸ“„ pytes_rs232.h
β”‚       β”œβ”€β”€ πŸ“„ sensor.py
β”‚       └── πŸ“„ text_sensor.py
β”œβ”€β”€ πŸ“ examples/
β”‚   β”œβ”€β”€ πŸ“„ basic-config.yaml
β”‚   β”œβ”€β”€ πŸ“„ 6-battery-system.yaml
β”‚   └── πŸ“„ with-bme280.yaml
β”œβ”€β”€ πŸ“ docs/
β”‚   β”œβ”€β”€ πŸ–ΌοΈ wiring-diagram.png
β”‚   β”œβ”€β”€ πŸ“„ installation-guide.md
β”‚   └── πŸ“„ troubleshooting.md
β”œβ”€β”€ πŸ“„ LICENSE
└── πŸ“„ README.md

🀝 Contributing

Contributions are welcome! Here’s how you can help:

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch (git checkout -b feature/amazing-feature)
  3. ✍️ Commit your changes (git commit -m 'Add amazing feature')
  4. πŸ“€ Push to the branch (git push origin feature/amazing-feature)
  5. πŸ”€ Open a Pull Request

πŸ’‘ Areas for Improvement

  • πŸ“– Additional documentation and examples
  • πŸ› Bug fixes and testing
  • ✨ New features (Celsius support, additional sensors)
  • 🌍 Multi-language support
  • 🎨 Dashboard templates

πŸ“œ License

This project is licensed under the MIT License - see the file for details.


πŸ™ Acknowledgments

  • πŸ”‹ Pytes - For manufacturing quality LiFePO4 battery systems
  • 🏠 ESPHome - For the excellent home automation framework
  • 🏑 Home Assistant - For the best home automation platform
  • πŸ–₯️ ESP32 Community - For extensive documentation and support
  • πŸ‘¨β€πŸ’» chinezbrun - For inspiration from pytes_esp

πŸ“ž Support


⚠️ Disclaimer

This is an independent project and is not officially affiliated with or endorsed by Pytes. Use at your own risk. Always follow proper safety procedures when working with battery systems.


πŸ”„ Changelog

Version 1.0.0 (2026-01-31)

  • βœ… Initial release
  • βœ… Support for up to 6 battery modules
  • βœ… RS232 communication via UART
  • βœ… Home Assistant integration
  • βœ… Web server interface
  • βœ… OTA updates

Made with ❀️ for the Home Assistant and Solar/Battery community

πŸŽ‰ Enjoy! πŸŽ‰

How does this software work?

ESPHome component reads the RS232 serial port with configurable frequency (default 30s), parses the battery data and sends it to Home Assistant via the ESPHome API. Home Assistant autodiscovery is built-in, so all sensors will show up automatically.

A signal converter from RS232 to TTL is needed between Pytes serial console port and ESP32 UART pins.

Program creates the following sensors for each battery:

  • Bank level: voltage, current, temperature, SoC, status
  • Individual batteries (1-6): voltage, current, temperature, SoC, serial#, model, firmware, status, volt_status

Hardware used:

ESP32 board –––––––––––––– tested on ESP32 WROOM 38 pins / ESP32 DevKitC

RS232 to TTL converter —————– tested on MAX3232 module

RJ45 to RS232 DB9(male) cable –––– tested on standard console cable

Simple connection flow:

ESP32 [UART pins GPIO16/17] -> TTL to RS232 converter -> DB09 to RJ45 cable -> Pytes RJ45 console port

Connection with RS232 to TTL converter using RJ45 to RS232 DB9(male) cable - TESTED:

ESP32 Pin: 16 RXD2 ------ RX converter  RX  DB9 Female ------ DB9 Male console cable RJ45 Pin: 3 TXD 
ESP32 Pin: 17 TXD2 ------ TX converter  TX  DB9 Female ------ DB9 Male console cable RJ45 Pin: 6 RXD 
ESP32 PIN:     GND ------ GND converter GND DB9 Female ------ DB9 Male console cable RJ45 Pin: 4 GND 
ESP32 PIN:    3.3V ------ VCC converter     DB9 Female ------ DB9 Male console cable RJ45

UART Configuration:

  • Baud Rate: 115200
  • Data Bits: 8
  • Parity: NONE
  • Stop Bits: 1

Important: Both connection types work, but respect the PYTES console port pinout. Main source of issues is incorrect TX/RX connection. If something goes wrong, swap RXD and TXD on one side.

Installation and Execution

Method 1: Using GitHub external component (Recommended)

Add to your ESPHome YAML configuration:

external_components:
  - source:
      type: git
      url: https://github.com/s3pt1c0/Pytes_ESP32_RS232
      ref: main
    components: [ pytes_rs232 ]
    refresh: 1d

Method 2: Local component

  1. Clone or download this repository:
git clone https://github.com/s3pt1c0/Pytes_ESP32_RS232.git
  1. Copy Components/pytes_rs232 folder to your ESPHome config directory:
mkdir -p /config/esphome/components
cp -r Pytes_ESP32_RS232/Components/pytes_rs232 /config/esphome/components/
  1. Reference in your YAML:
external_components:
  - source:
      type: local
      path: components

Basic Configuration Example

Create pytes-esp32.yaml file:

substitutions:
  device_name: pytes-esp32
  friendly_name: πŸ”‹Pytes Battery MonitorπŸ”‹
  poll_s: "30"              # Polling interval in seconds
  capacity_ah: "100"        # Battery capacity in Ah
  num_batts: "6"            # Number of battery modules (1-6)

esphome:
  name: ${device_name}
  friendly_name: ${friendly_name}

esp32:
  board: esp32dev
  framework:
    type: esp-idf
    advanced: 
      minimum_chip_revision: "3.1"

logger:
  level: INFO

web_server:
  port: 80

api:
  encryption:
    key: "YOUR_ENCRYPTION_KEY"

ota:
  - platform: esphome
    password: "YOUR_OTA_PASSWORD"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

# UART for Pytes RS232
uart:
  id: uart_pytes
  tx_pin: GPIO17
  rx_pin: GPIO16
  baud_rate: 115200
  data_bits: 8
  parity: NONE
  stop_bits: 1

# Pytes Component
pytes_rs232:
  uart_id: uart_pytes
  num_batteries: ${num_batts}
  update_interval: ${poll_s}s
  capacity_ah: ${capacity_ah}
  
  summary:
    voltage: sys_voltage
    current: sys_current
    temperature: sys_temp_f
    coulomb: sys_coulomb
    basic_status: sys_basic_status
  
  batteries:
    - voltage: b1_voltage
      current: b1_current
      temperature: b1_temp_f
      coulomb: b1_coulomb
      barcode: b1_barcode
      devtype: b1_devtype
      firm_version: b1_firmver
      basic_status: b1_basic_status
      volt_status: b1_volt_status
    # Repeat for batteries 2-6...

# Define template sensors
sensor:
  - platform: template
    name: "Bank Voltage ⚠️"
    id: sys_voltage
    unit_of_measurement: "V"
    accuracy_decimals: 2
  
  - platform: template
    name: "Bank Current⚑"
    id: sys_current
    unit_of_measurement: "A"
    accuracy_decimals: 2
  # ... more sensors

text_sensor:
  - platform: template
    name: "Bank StatusπŸš₯"
    id: sys_basic_status
  # ... more text sensors

Complete example with all sensors defined can be found in examples/ folder.

Normal Operation

When ESP32 is powered and configured:

  1. Device connects to WiFi
  2. Establishes UART communication with Pytes battery
  3. Reads serial data at configured interval (default 30s)
  4. Automatically creates device and sensors in Home Assistant
  5. Updates sensor values continuously

After firmware updates it is recommended to delete previous devices in Home Assistant and let them be recreated at next boot.

Available Sensors

Bank Level (Summary):

  • Bank Voltage (V)
  • Bank Current (A)
  • Bank Temperature (Β°F)
  • Bank SoC (%)
  • Bank Status

Individual Batteries (B1-B6):

  • Voltage (V)
  • Current (A)
  • Temperature (Β°F)
  • SoC (%)
  • Serial Number
  • Model/Device Type
  • Firmware Version
  • Basic Status
  • Voltage Status

Home Assistant Integration

Device will automatically appear in Home Assistant under Settings β†’ Devices & Services β†’ ESPHome after first connection.

Example dashboard card:

type: entities
title: πŸ”‹ Pytes Battery
entities:
  - entity: sensor.pytes_esp32_bank_voltage
  - entity: sensor.pytes_esp32_bank_current
  - entity: sensor.pytes_esp32_bank_soc
  - entity: sensor.pytes_esp32_bank_temp
  - entity: sensor.pytes_esp32_bank_status

Troubleshooting

No data from batteries / All sensors β€œunavailable”

  • βœ… Check TX/RX wiring (may need to be swapped)
  • βœ… Verify RS232-TTL module power (3.3V not 5V)
  • βœ… Confirm baud rate is 115200
  • βœ… Check ESPHome logs for errors
  • βœ… Verify Pytes console port is enabled

Wrong data or garbled output

  • βœ… Swap TX/RX connections on one side
  • βœ… Ensure ground connection between ESP32 and converter
  • βœ… Check for loose connections
  • βœ… Try increasing polling interval

WiFi disconnections

  • βœ… Move ESP32 closer to router
  • βœ… Use quality 5V 2A power supply
  • βœ… Set static IP in router

Viewing logs

esphome logs pytes-esp32.yaml

πŸ—οΈ Repository Structure

Pytes_ESP32_RS232/
β”œβ”€β”€ Components/
β”‚   └── pytes_rs232/
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ pytes_rs232.cpp
β”‚       β”œβ”€β”€ pytes_rs232.h
β”‚       β”œβ”€β”€ sensor.py
β”‚       └── text_sensor.py
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ basic-config.yaml
β”‚   └── 6-battery-system.yaml
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ wiring-diagram.png
β”‚   └── installation-guide.md
β”œβ”€β”€ LICENSE
└── README.md

πŸ“œ License

This project is licensed under the MIT License - see the file for details.


πŸ“ž Support & Community


πŸ™ Acknowledgments

  • Pytes - For manufacturing quality LiFePO4 battery systems
  • ESPHome - For the excellent home automation framework
  • Home Assistant - For the best home automation platform
  • ESP32 Community - For extensive documentation and support
  • chinezbrun - For inspiration from pytes_esp

⚠️ Disclaimer

This is an independent project and is not officially affiliated with or endorsed by Pytes. Use at your own risk. Always follow proper safety procedures when working with battery systems.


Made with ❀️ for the Home Assistant and Solar/Battery community

enjoy

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors