Metadata-Version: 2.4
Name: franklinwh-gateway-emulator
Version: 0.3.3
Summary: FranklinWH aGate emulator — Modbus TCP (SunSpec + extension registers), multi-gateway
Author-email: david2069 <david2069@users.noreply.github.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/david2069/franklinwh-gateway-emulator
Project-URL: Documentation, https://david2069.github.io/franklinwh-gateway-emulator/
Project-URL: Changelog, https://github.com/david2069/franklinwh-gateway-emulator/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/david2069/franklinwh-gateway-emulator/issues
Keywords: franklinwh,agate,modbus,sunspec,emulator,simulator
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pysunspec2>=1.1.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: tzdata; platform_system == "Windows"
Requires-Dist: franklinwh-direct-connect-api>=0.4.0
Provides-Extra: dc
Requires-Dist: franklinwh-direct-connect-api>=0.4.0; extra == "dc"
Provides-Extra: docs
Requires-Dist: mkdocs-material; extra == "docs"
Provides-Extra: pvlib
Requires-Dist: pvlib>=0.11; extra == "pvlib"
Provides-Extra: dev
Requires-Dist: franklinwh-direct-connect-api>=0.4.0; extra == "dev"
Requires-Dist: pvlib>=0.11; extra == "dev"
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pymodbus>=3.6; extra == "dev"
Requires-Dist: franklinwh-cloud>=0.6.5; extra == "dev"
Requires-Dist: franklinwh==2026.3.*; extra == "dev"
Requires-Dist: franklinwh-modbus==0.11.0; extra == "dev"
Dynamic: license-file

# franklinwh-gateway-emulator

[![release](https://img.shields.io/github/v/release/david2069/franklinwh-gateway-emulator)](https://github.com/david2069/franklinwh-gateway-emulator/releases/latest)
[![tests](https://github.com/david2069/franklinwh-gateway-emulator/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/david2069/franklinwh-gateway-emulator/actions/workflows/test.yml)
[![docs](https://github.com/david2069/franklinwh-gateway-emulator/actions/workflows/docs.yml/badge.svg?branch=main)](https://david2069.github.io/franklinwh-gateway-emulator/)
[![python](https://img.shields.io/badge/python-%3E%3D3.10-blue)](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/pyproject.toml)
[![license](https://img.shields.io/badge/license-MIT-green)](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/LICENSE)

An emulator of the FranklinWH **aGate** for testing without hardware. It serves the **Direct
Connect** local protocol (TCP/9000) and **Modbus TCP** (SunSpec chain plus FranklinWH
extension registers), both in front of one **closed-loop site model**, so control commands
actually move the battery and both ports always agree. It can run one gateway or a **fleet** of
them.

With `--cloud-port` it also serves the **FranklinWH Cloud API**, the REST API the official
FranklinWH app, [franklinwh-cloud](https://github.com/david2069/franklinwh-cloud) and
[homeassistant-franklinwh](https://github.com/richo/homeassistant-franklinwh) use, from the same
gateways: a cloud client, a Modbus client and a Direct Connect client all see one site. It never
contacts the real cloud. See [FranklinWH Cloud API](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/cloud-api.md) and
[Cloud API clients](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/cloud-clients.md).

**As on a real aGate, Modbus TCP starts off.** Every aGate runs a Direct Connect listener; Modbus
TCP comes on when a Direct Connect `1205` `sunsMdEn` write enables it (about 3 s later). That is
`setup: factory`, the default. A gateway that is already set up is `setup: in-service`: Modbus TCP
on from the start. `modbus_enabled: true|false` overrides either.

Built for [franklinwh-modbus](https://github.com/david2069/franklinwh-modbus) and
[franklinwh-modbus-bridge](https://github.com/david2069/franklinwh-modbus-bridge). The
unmodified `FranklinWHController` connects, scans, reads and dispatches against it
(see `tests/test_franklinwh_modbus.py`).

> **Unofficial, and an emulation: it can never be 100% accurate.** See the
> [Disclaimer](#disclaimer). It emulates documented and observed behaviour of the reference
> aGate's firmware. Where the sources disagree, the choices are in
> [What is emulated](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/emulated.md).

## Disclaimer
<!-- --8<-- [start:disclaimer] -->

> **UNOFFICIAL SOFTWARE — NOT AFFILIATED WITH OR ENDORSED BY FRANKLINWH.**
>
> This is an **emulator**, not an aGate. It imitates FranklinWH's undocumented **Direct Connect**
> local API (reverse-engineered by third parties), its **SunSpec Modbus TCP** API (with
> undocumented FranklinWH extensions) and the **FranklinWH Cloud API** (the app's REST API,
> reverse-engineered from captured app traffic), from incomplete documentation and observations
> of a few real devices. It **can never be 100% accurate**: it may behave differently from a real aGate,
> now or in the future, and may have bugs, errors or omissions a real aGate doesn't have.
> Software that works here may still fail, or do harm, on real hardware. **Verify on real
> hardware before relying on any result.**
>
> Provided **AS-IS**, without warranty of any kind. Use is entirely at your own risk; by using it
> you accept these limitations unreservedly. The authors accept no liability for any consequence,
> including anything done to real hardware by software developed or tested with it.
>
> **Do NOT contact FranklinWH support** about this emulator. Raise issues at
> <https://github.com/david2069/franklinwh-gateway-emulator/issues>.
>
> **MIT License**, with the additional notices in [LICENSE](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/LICENSE).

### Compliance & anti-circumvention

> The emulator doesn't connect to a real aGate, but what you build with it may. Keep your gateway
> and battery settings, controls and operation compliant with the configuration set through the
> official FranklinWH mobile app and the installer/support portal. FranklinWH-managed settings
> may exist to protect the battery and gateway, apply software updates, enforce your local grid
> profile and import/export limits, and enforce incentive, subsidy or VPP/grid-programme
> restrictions. Bypassing or overriding any of them, deliberately or inadvertently, is entirely
> at your own risk, and is neither condoned nor encouraged by the authors.
<!-- --8<-- [end:disclaimer] -->

## Quick start

From PyPI (Python 3.10 or later), with one of the example fleets:

```bash
python3 -m venv .venv && .venv/bin/pip install franklinwh-gateway-emulator
curl -O https://raw.githubusercontent.com/david2069/franklinwh-gateway-emulator/main/examples/fleet.yaml
.venv/bin/franklinwh-emulator ui fleet.yaml               # web UI: open http://127.0.0.1:8502/
```

From a clone, for the examples, the tests and development:

```bash
git clone https://github.com/david2069/franklinwh-gateway-emulator.git
cd franklinwh-gateway-emulator
python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"   # Python 3.10 or later
.venv/bin/franklinwh-emulator ui examples/fleet.yaml      # web UI: open http://127.0.0.1:8502/
.venv/bin/franklinwh-emulator ui examples/fleet.yaml --cloud-port 8503   # plus the Cloud API
.venv/bin/franklinwh-emulator serve --port 5020 --dc-port 9000 --setup in-service   # one gateway
.venv/bin/python -m pytest
```

![The emulator's web UI](https://raw.githubusercontent.com/david2069/franklinwh-gateway-emulator/main/docs/assets/ui/overview.png)

## Documentation

**The full docs:** <https://david2069.github.io/franklinwh-gateway-emulator/>. They are built
from [`docs/`](https://github.com/david2069/franklinwh-gateway-emulator/tree/main/docs/), so these links also work on GitHub:

| | |
|---|---|
| [Getting started](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/getting-started.md) | install, run one gateway or a fleet, use it from Python |
| [Model baseline](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/model-baseline.md) | the hardware, and how location, weather, placement and controls drive the model, with a diagram |
| [Configuration](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/configuration.md) | describe each site: aGate, aPowers, PV, grid, accessories, location; where it's saved |
| [Web UI](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/ui.md) | the optional web page, with screenshots |
| [What is emulated](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/emulated.md) | protocols, profiles and the choices where sources disagree |
| [Grid, grid codes, export limits and phases](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/grid.md) | outages, trips, CSIP-AUS, phases |
| [The site model](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/site-model.md) | TOU, energy, location and time, weather, loads, generator |
| [Control API and `ctl`](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/control-api.md) | drive the emulator from scripts and tests |
| [FranklinWH Cloud API](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/cloud-api.md) · [Cloud API clients](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/cloud-clients.md) | the cloud's REST API from the same gateways; pointing franklinwh-cloud, homeassistant-franklinwh or the official app at it |
| [Scenarios](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/SCENARIOS.md) · [Replay](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/replay.md) | timed, checked test runs; recorded data |
| [Direct Connect](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/DIRECT_CONNECT.md) · [Design](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/DESIGN.md) · [Calibration](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/CALIBRATION.md) · [Findings](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/docs/FINDINGS.md) | reference |
| [Changelog](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/CHANGELOG.md) · [Backlog](https://github.com/david2069/franklinwh-gateway-emulator/blob/main/BACKLOG.md) | |

Local preview: `pip install mkdocs-material && mkdocs serve` (live reload at http://127.0.0.1:8000/).
