|
| 1 | +# Growatt Inverter Emulator |
| 2 | + |
| 3 | +A realistic Modbus TCP emulator for testing Growatt inverter integrations without physical hardware. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **10 Inverter Models** - Supports all major Growatt series (MIC, MIN, TL-XH, MID, SPH, SPH-TL3, MOD) |
| 8 | +- **Realistic Simulation** - Day/night cycles, solar generation, battery charging/discharging |
| 9 | +- **Live Terminal UI** - Real-time display of all inverter parameters |
| 10 | +- **Interactive Controls** - Adjust solar irradiance, cloud cover, house load, battery behavior, and time speed |
| 11 | +- **Full Modbus TCP** - Implements complete register maps for each model |
| 12 | +- **Battery Simulation** - Automatic charging from PV excess, discharging to cover loads |
| 13 | +- **Grid Interaction** - Calculates import/export based on generation and consumption |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +### Requirements |
| 18 | + |
| 19 | +- Python 3.7 or higher |
| 20 | +- pip package manager |
| 21 | + |
| 22 | +### Install Dependencies |
| 23 | + |
| 24 | +```bash |
| 25 | +pip3 install -r requirements_emulator.txt |
| 26 | +``` |
| 27 | + |
| 28 | +Or manually: |
| 29 | + |
| 30 | +```bash |
| 31 | +pip3 install pymodbus rich |
| 32 | +``` |
| 33 | + |
| 34 | +## Usage |
| 35 | + |
| 36 | +### Quick Start |
| 37 | + |
| 38 | +Run the emulator with interactive model selection: |
| 39 | + |
| 40 | +```bash |
| 41 | +python3 growatt_emulator.py |
| 42 | +``` |
| 43 | + |
| 44 | +### Specify Model and Port |
| 45 | + |
| 46 | +```bash |
| 47 | +python3 growatt_emulator.py --model sph_3000_6000 --port 5020 |
| 48 | +``` |
| 49 | + |
| 50 | +### List Available Models |
| 51 | + |
| 52 | +```bash |
| 53 | +python3 growatt_emulator.py --list-models |
| 54 | +``` |
| 55 | + |
| 56 | +### Available Models |
| 57 | + |
| 58 | +| Model Key | Name | Type | Battery | Phases | PV Strings | Power | |
| 59 | +|-----------|------|------|---------|--------|------------|-------| |
| 60 | +| `mic_600_3300tl_x` | MIC 600-3300TL-X | Micro | No | 1 | 2 | 3.3kW | |
| 61 | +| `min_3000_6000_tl_x` | MIN 3000-6000TL-X | String | No | 1 | 2 | 6.0kW | |
| 62 | +| `min_7000_10000_tl_x` | MIN 7000-10000TL-X | String | No | 1 | 3 | 10.0kW | |
| 63 | +| `tl_xh_3000_10000` | TL-XH 3000-10000 | Hybrid | Yes | 1 | 3 | 10.0kW | |
| 64 | +| `tl_xh_us_3000_10000` | TL-XH US 3000-10000 | Hybrid (US) | Yes | 1 | 3 | 10.0kW | |
| 65 | +| `mid_15000_25000tl3_x` | MID 15000-25000TL3-X | Commercial | No | 3 | 2 | 25.0kW | |
| 66 | +| `sph_3000_6000` | SPH 3000-6000 | Hybrid Storage | Yes | 1 | 2 | 6.0kW | |
| 67 | +| `sph_7000_10000` | SPH 7000-10000 | Hybrid Storage | Yes | 1 | 2 | 10.0kW | |
| 68 | +| `sph_tl3_3000_10000` | SPH-TL3 3000-10000 | Hybrid 3-Phase | Yes | 3 | 2 | 10.0kW | |
| 69 | +| `mod_6000_15000tl3_xh` | MOD 6000-15000TL3-XH | Modular Hybrid | Yes | 3 | 3 | 15.0kW | |
| 70 | + |
| 71 | +## Keyboard Controls |
| 72 | + |
| 73 | +While the emulator is running, you can use these keys: |
| 74 | + |
| 75 | +- **[I]** - Adjust solar irradiance (0-1000 W/m²) |
| 76 | +- **[C]** - Adjust cloud cover (0-100%) |
| 77 | +- **[L]** - Adjust house load (Watts) |
| 78 | +- **[T]** - Adjust time speed multiplier (0.1-100x) |
| 79 | +- **[B]** - Battery control (Auto/Manual charge/discharge) - Only for models with battery |
| 80 | +- **[R]** - Reset daily energy totals |
| 81 | +- **[Q]** - Quit emulator |
| 82 | + |
| 83 | +## Display Panels |
| 84 | + |
| 85 | +The terminal UI shows: |
| 86 | + |
| 87 | +1. **Header** - Model name, time, status, port |
| 88 | +2. **PV Generation** - Voltage, current, and power for each string |
| 89 | +3. **AC Output** - Voltage, current, frequency, power |
| 90 | +4. **Battery** (if equipped) - SOC, voltage, current, charging status |
| 91 | +5. **Grid & Load** - Import/export status, house consumption |
| 92 | +6. **Energy Totals** - Today and lifetime energy statistics |
| 93 | +7. **Temperatures** - Inverter, IPM, and boost converter temps |
| 94 | + |
| 95 | +## Connecting to the Emulator |
| 96 | + |
| 97 | +### From Home Assistant |
| 98 | + |
| 99 | +Add a Modbus TCP integration pointing to: |
| 100 | +- Host: `localhost` (or IP of machine running emulator) |
| 101 | +- Port: `502` (or custom port specified) |
| 102 | + |
| 103 | +### From Python |
| 104 | + |
| 105 | +```python |
| 106 | +from pymodbus.client import ModbusTcpClient |
| 107 | + |
| 108 | +client = ModbusTcpClient('localhost', port=502) |
| 109 | +client.connect() |
| 110 | + |
| 111 | +# Read input registers (e.g., PV1 voltage at register 3) |
| 112 | +result = client.read_input_registers(3, 1, slave=1) |
| 113 | +if not result.isError(): |
| 114 | + pv1_voltage = result.registers[0] * 0.1 # Apply scale |
| 115 | + print(f"PV1 Voltage: {pv1_voltage}V") |
| 116 | + |
| 117 | +client.close() |
| 118 | +``` |
| 119 | + |
| 120 | +## Simulation Details |
| 121 | + |
| 122 | +### Solar Generation |
| 123 | + |
| 124 | +- Follows realistic day/night cycle (sunrise ~6:00, sunset ~18:00) |
| 125 | +- Peak generation at solar noon (~13:00) |
| 126 | +- Affected by: |
| 127 | + - Time of day (sine wave sun elevation) |
| 128 | + - Solar irradiance setting (0-1000 W/m²) |
| 129 | + - Cloud cover (0-100%) |
| 130 | + - Random variations to simulate real conditions |
| 131 | + |
| 132 | +### Battery Behavior |
| 133 | + |
| 134 | +For models with batteries: |
| 135 | + |
| 136 | +- **Auto Mode** (default): |
| 137 | + - Charges from excess PV generation |
| 138 | + - Discharges to cover shortfall when PV < load |
| 139 | + - Stops charging above 95% SOC |
| 140 | + - Stops discharging below 10% SOC |
| 141 | + - Trickle charge/discharge near limits |
| 142 | + |
| 143 | +- **Manual Mode**: |
| 144 | + - Force specific charge/discharge rate |
| 145 | + - Override automatic behavior for testing |
| 146 | + |
| 147 | +### Grid Interaction |
| 148 | + |
| 149 | +- **Export**: When PV generation exceeds house load |
| 150 | +- **Import**: When PV generation cannot meet house load |
| 151 | +- Properly accounts for battery charging/discharging |
| 152 | + |
| 153 | +### Temperature Simulation |
| 154 | + |
| 155 | +- Ambient: 25°C |
| 156 | +- Rises with inverter load (up to +30°C at full power) |
| 157 | +- IPM runs ~5°C hotter than inverter |
| 158 | +- Boost converter ~3°C hotter than inverter |
| 159 | + |
| 160 | +## Port Selection |
| 161 | + |
| 162 | +- **Port 502** (default Modbus): Requires sudo/root on Linux |
| 163 | +- **Port >= 1024**: No special privileges required |
| 164 | + |
| 165 | +Example with custom port: |
| 166 | +```bash |
| 167 | +python3 growatt_emulator.py --model sph_3000_6000 --port 5020 |
| 168 | +``` |
| 169 | + |
| 170 | +## Testing Your Integration |
| 171 | + |
| 172 | +1. Start the emulator with your target model |
| 173 | +2. Connect your integration (Home Assistant, script, etc.) |
| 174 | +3. Use keyboard controls to simulate different conditions: |
| 175 | + - High sun: `[I]` → 1000 W/m² |
| 176 | + - Cloudy day: `[C]` → 70% |
| 177 | + - Heavy load: `[L]` → 5000W |
| 178 | + - Fast time: `[T]` → 10x (see full day in minutes) |
| 179 | +4. Verify your integration correctly: |
| 180 | + - Reads all sensor values |
| 181 | + - Handles zero values at night |
| 182 | + - Processes battery data (if applicable) |
| 183 | + - Calculates derived values correctly |
| 184 | + - Updates energy totals |
| 185 | + |
| 186 | +## Troubleshooting |
| 187 | + |
| 188 | +### Permission Denied on Port 502 |
| 189 | + |
| 190 | +Use a higher port or run with sudo: |
| 191 | +```bash |
| 192 | +sudo python3 growatt_emulator.py --model sph_3000_6000 |
| 193 | +# OR |
| 194 | +python3 growatt_emulator.py --model sph_3000_6000 --port 5020 |
| 195 | +``` |
| 196 | + |
| 197 | +### Module Not Found Errors |
| 198 | + |
| 199 | +Install dependencies: |
| 200 | +```bash |
| 201 | +pip3 install pymodbus rich |
| 202 | +``` |
| 203 | + |
| 204 | +### Terminal Display Issues |
| 205 | + |
| 206 | +The emulator uses the `rich` library for terminal UI. Ensure your terminal supports: |
| 207 | +- ANSI colors |
| 208 | +- Unicode characters |
| 209 | +- Terminal size at least 80x24 |
| 210 | + |
| 211 | +## Architecture |
| 212 | + |
| 213 | +``` |
| 214 | +emulator/ |
| 215 | +├── __init__.py - Package initialization |
| 216 | +├── models.py - Inverter model definitions |
| 217 | +├── simulator.py - Simulation engine (solar, battery, grid) |
| 218 | +├── modbus_server.py - Modbus TCP server |
| 219 | +├── display.py - Terminal UI with rich |
| 220 | +└── controls.py - Keyboard input handler |
| 221 | +
|
| 222 | +growatt_emulator.py - Main entry point |
| 223 | +``` |
| 224 | + |
| 225 | +## Development |
| 226 | + |
| 227 | +### Adding New Models |
| 228 | + |
| 229 | +1. Add profile to `custom_components/growatt_modbus/device_profiles.py` |
| 230 | +2. Add register map to appropriate profile file in `custom_components/growatt_modbus/profiles/` |
| 231 | +3. Emulator will automatically detect and support the new model |
| 232 | + |
| 233 | +### Extending Simulation |
| 234 | + |
| 235 | +Edit `emulator/simulator.py` to: |
| 236 | +- Add new calculated values |
| 237 | +- Modify generation curves |
| 238 | +- Implement different battery algorithms |
| 239 | +- Add weather effects |
| 240 | + |
| 241 | +## License |
| 242 | + |
| 243 | +This emulator is part of the Growatt ModbusTCP integration project. |
| 244 | +See the main LICENSE file for details. |
0 commit comments