High-performance ESPHome configuration for Marstek Venus E battery integration via Modbus RS485
Monitor and control your Marstek Venus E plug-in battery (5.12 kWh) using ESPHome and the LilyGO T-CAN485 board. This configuration provides real-time battery metrics, runtime estimates, energy efficiency tracking, and full control over charging/discharging modes.
- Features
- Performance
- Screenshots
- Hardware Requirements
- Quick Start
- Installation
- Home Assistant Integration
- Sensors & Entities
- Credits & Resources
- License
- Real-time Battery Metrics: SOC, voltage, current, power, temperature with cell-level monitoring
- Runtime Estimation: Dynamic time-to-full/empty calculation based on power flow
- Energy Tracking: Daily, monthly, and lifetime charge/discharge statistics
- Work Mode Control: Manual, Anti-feed, AI modes with forcible charge/discharge
- Power Management: Adjustable limits (0-2500W), SOC targets (12-100%), backup function
- 24 Warning Sensors: Real-time alerts for grid, battery, temperature, and communication issues
- Built-in Web Server: Access battery data directly via browser (no Home Assistant required)
- OTA Updates: Wireless firmware updates via ESPHome dashboard or web interface
- Status LED Feedback: Visual system state via onboard WS2812 LED
- System Diagnostics: WiFi/BT/Cloud status, software versions, connection monitoring
- Automatic Discovery: Zero-config integration via ESPHome API
- Complete Dashboard: Ready-to-use Lovelace YAML with battery metrics and controls
- Efficiency Templates: Custom sensors for monthly/total efficiency and round-trip loss tracking
- Energy Dashboard Compatible: Integrates with HA energy management
- Event-driven Architecture: 3-second response times for critical sensors
- Modbus Optimization: 57% less bus traffic through register batching
- Network Efficiency: 56% fewer API calls, 35-40% reduced traffic
- Memory Optimized: 22-25 KB less RAM usage, 20 KB smaller firmware
| Performance Metric | Original Config | This Config | Improvement |
|---|---|---|---|
| API Updates | ~250/min | ~110/min | -56% โก |
| Battery Power Response | 15 seconds | 1 second | 93% faster โก |
| Modbus Bus Requests | ~35 per cycle | ~15 per cycle | -57% โก |
| Battery Capacity Update | 120s polling | 3s event-driven | 40x faster โก |
| RAM Usage | Baseline | -22 to -25 KB | Optimized ๐พ |
| Network Traffic | 100% | 60-65% | -35 to -40% ๐ก |
| Firmware Size | Baseline | -20 KB | Smaller ๐ฟ |
| WiFi Throughput | Standard | +20-30% faster | Enhanced ๐ถ |
| Boot Time | 2-3 seconds | 1.5-2 seconds | Faster ๐ |
| Network Latency | Baseline | -15 to -25ms | Lower โก |
๐ง Modbus Efficiency
- Register batching reduces 7 blocks from 24 requests to 7 requests
- Smart polling with skip_updates for slow-changing values
- Event-driven updates instead of fixed intervals
๐พ Memory & Performance
- 22-25 KB less RAM usage through optimizations
- 20 KB smaller firmware size
- Faster boot times and reduced CPU load
๐ก Network Optimization
- 56% fewer API calls through intelligent batching
- 35-40% less network traffic via throttling
- 20-30% WiFi throughput increase with AMPDU
โก Response Times
- Battery Power: 15s โ 1s (instant response)
- Battery Capacity: 120s โ 3s (event-based)
- Sensor updates: Real-time with throttling
Result: A highly optimized configuration that's faster, more efficient, and more reliable than the original while maintaining full functionality.
Cell information, AC/DC metrics, and energy statistics
Network status and control settings
System diagnostics and warning sensors
Complete Lovelace dashboard with battery metrics, controls, and energy flow
| Component | Model | Where to Buy |
|---|---|---|
| ESP32 Board | LilyGO T-CAN485 | LilyGO Official Store |
| Battery | Marstek Venus E (5.12 kWh) | Marstek |
| Cable | RS485 cable (2-wire) | Included with Marstek (Weipu SP17 connector) or use standard Modbus cable |
The Marstek Venus E battery includes a Weipu SP17 5-pin connector with RS485 terminals. You can:
- Use the included cable directly
- Create a custom cable with Weipu SP17 male connector
- Use any standard RS485 cable with A+/B- terminals
See INSTALL ESPhome on LilyGo.md for detailed flashing instructions.
Download the latest configuration from the releases page:
Click on Marstek-Lilygo-ESPHome-Config.yaml under Assets to download.
Generate a secure encryption key using OpenSSL:
openssl rand -base64 32
Or use the ESPHome dashboard to generate one automatically:
- Visit ESPHome API Documentation
- Scroll down to "Encryption Key" section
- Click the generate button
Create a secrets.yaml file:
# WiFi Credentials
wifi_ssid: "YourSSID"
wifi_password: "YourPassword"
# API Encryption Key (generated above)
api_encryption_key: "your-32-char-base64-key-here"
# OTA Password (choose your own)
ota_password: "your-secure-ota-password"
First, compile and validate the configuration:
esphome compile Marstek-Lilygo-ESPHome-Config.yaml
If compilation succeeds, flash the device:
esphome run Marstek-Lilygo-ESPHome-Config.yaml
Install with pip (Recommended)
pip3 install esphome --upgrade
Verify Installation
esphome version
For step-by-step flashing instructions including USB drivers, bootloader mode, and troubleshooting, see:
This guide includes:
- Driver installation for Windows/Mac/Linux
- Entering bootloader mode on LilyGO T-CAN485
- First-time USB flashing
- Common flashing errors and solutions
-
Download Configuration
Visit Releases and download
Marstek-Lilygo-ESPHome-Config.yaml -
Generate API Key
openssl rand -base64 32 -
Create Secrets File
Create
secrets.yamlin the same folder with your WiFi credentials and generated API key. -
Compile Configuration
esphome compile Marstek-Lilygo-ESPHome-Config.yaml -
Initial Flash (USB)
esphome run Marstek-Lilygo-ESPHome-Config.yaml
ESPHome devices are automatically discovered in Home Assistant via the ESPHome integration.
Steps:
- Home Assistant will show a notification: "New device discovered"
- Click "Configure"
- Enter your
api_encryption_keyfromsecrets.yaml - Device is ready to use!
If auto-discovery doesn't work:
- Navigate to Settings โ Devices & Services
- Click + Add Integration
- Search for ESPHome
- Enter:
- Host:
192.168.178.160(or your configured IP) - Encryption Key: Your
api_encryption_keyfromsecrets.yaml
- Host:
Import the included dashboard for a complete UI:
File: Home Assistant Marstek Dashboard.yaml
- Copy the YAML content
- In Home Assistant: Settings โ Dashboards โ Edit Dashboard
- Click โฎ (three dots) โ Raw configuration editor
- Paste the YAML content
- Save
Dashboard Features:
- Real-time battery metrics and status
- Runtime estimation display
- Charge/discharge controls
- Warning indicators with color coding
- Energy statistics (daily, monthly, total)
- Work mode selection
- Power limit adjusters
The included Home Assistant Template adds advanced efficiency tracking:
File: Home Assistant Template.yaml
Add to your configuration.yaml:
template: !include_dir_merge_list templates/
Create templates/marstek_efficiency.yaml and paste the template content.
New Sensors:
- Monthly Efficiency (%):
(Monthly Discharge / Monthly Charge) ร 100 - Total Efficiency (%):
(Total Discharge / Total Charge) ร 100 - Shows energy lost during charge/discharge cycles
- Useful for battery health monitoring
- Voltage, Current, Power, State of Charge (%)
- Remaining Capacity (kWh), Total Energy (kWh)
- Max/Min Cell Voltage, Cell Voltage Difference
- Runtime Estimate - "Full in: 2h 30min" / "Empty in: 1h 45min" / "Standby"
- Inverter State - Sleep/Standby/Charge/Discharge/Fault/Idle
- AC Voltage, Current, Power
- Total Charging/Discharging Energy (kWh)
- Daily Charging/Discharging (kWh)
- Monthly Charging/Discharging (kWh)
- Internal Temperature, MOS1/MOS2 Temperature
- Max/Min Cell Temperature
- Software/Firmware/BMS Version
- ESPHome Version, IP Address, SSID
- WiFi Signal Strength
- RS485 Control Mode, Work Mode Selection
- Forcible Charge/Discharge with Power Limits
- Backup Function, SOC Charge Target
- Max Charge/Discharge Power Settings
- Charging/Discharging Cutoff Capacity
Comprehensive monitoring for grid issues, battery protection, temperature alerts, and communication status.
๐ก @Superduper1969 - Original MarstekVenus-LilygoRS485 implementation
https://github.com/Superduper1969/MarstekVenus-LilygoRS485/tree/main
๐งฐ @scruysberghs - ha-marstek-venus integration
https://github.com/scruysberghs/ha-marstek-venus
๐ Modbus Register Documentation - Marstek Venus C/E Protocol
https://duravolt.nl/wp-content/uploads/Duravolt-Plug-in-Battery-Modbus.pdf
๐ LilyGo T-CAN485 Documentation - Hardware specs and pinout
https://github.com/Xinyuan-LilyGO/T-CAN485
๐ Modbus Register Spreadsheet - Complete register overview
Google Spreadsheet - Modbus Registers
๐ฌ Tweakers Forum - Dutch community discussions
See the complete changelog and download the latest version:
This project is licensed under the MIT License - see the LICENSE file for details.