Maintained in tjorim/ha-mygrid-modbus · revision 3e92c5b6bc89. Updates are reviewed before publication.
MyGrid ModuleTwo for Home Assistant
Documentation
Read the complete ModuleTwo setup guide on the MyGrid documentation website, alongside the other device guides.
This README is the authoritative source for this integration’s installation,
configuration, entities, Energy dashboard setup, automation examples and
troubleshooting. Edit those instructions here; the website publishes a reviewed,
commit-pinned snapshot, so it may lag this branch. Integration acceptance and
release instructions belong in this repository’s docs/ directory.
Python usage, device prerequisites and protocol details belong in
python-mygrid-modbus. Link to that
source rather than copying its reference tables. Contributor guidance lives in
CONTRIBUTING.md.
Local monitoring and explicit power control for MyGrid ModuleTwo batteries over Modbus TCP. No cloud service or account is used by the integration.
Requires Home Assistant 2026.10.2 or newer (Python 3.14.2+). Version 0.1.0 targets the supplied ModuleTwo register map version 2. The integration uses the independent mygrid-modbus device library from PyPI, which Home Assistant installs automatically. The integration borrows a shared connection from Home Assistant’s Modbus integration, using modbus-connection and its tmodbus backend. Tests use the Home Assistant version resolved in uv.lock and its exact transport dependency versions. CI compares the test pins with that version’s Modbus manifest; update the pins and lockfile together when changing the Home Assistant test baseline. Physical Home Assistant setup, polling, diagnostics and small charge/discharge tests passed limited checks on 2026-11-09 with Home Assistant 2026.11.0 and map 2. Full hardware acceptance remains pending; see the acceptance record and checklist.
This is a community custom integration, engineered against applicable Home Assistant Platinum requirements. It has not received an official Home Assistant quality rating. See quality tracking.
Before installation
Enable Modbus in the MyGrid app. Select Home Assistant as the control source to open Modbus TCP on port 502. On the original development battery, port 502 remained closed despite that selection, and MyGrid support was contacted. On its replacement, the owner reported on 2026-11-09 that the battery began updating after account linking; selecting Home Assistant control again then made Modbus TCP available. Read-only library tests passed with owner-reported Software 31.6 and observed register map 2. This does not establish a general activation procedure or physical Home Assistant integration acceptance. Activation persistence and operation without cloud access remain unverified. If port 502 still refuses connections after checking the control source and competing clients, contact MyGrid support with the battery’s hostname and MAC address. See the acceptance record and tracking issue.
- In the MyGrid app, set the battery’s control source to Home Assistant. This option must already be configured for your battery. The MyGrid control source leaves the Modbus port closed.
- Put Home Assistant and the battery on the same LAN/Wi-Fi; reserve the battery’s IP address in your router.
- For a cluster, use the Auto leader, never a Follow unit. Setpoints and live limits on the leader represent household totals.
- Disconnect Modbus test programs. The battery serves one TCP client at a time.
- Choose one power controller. Other Home Assistant integrations, app controls and Modbus writers can overwrite this integration’s setpoint; the last write wins.
The protocol has no TLS or authentication. Keep it on your trusted LAN; do not forward port 502 to the internet.
Installation
On Home Assistant 2026.11 or newer, open Settings → Marketplace and add
https://github.com/tjorim/ha-mygrid-modbus as a custom repository of type
Integration. Install MyGrid ModuleTwo and follow any restart prompt.
Catalog listing is separate from custom-repository installation.
On Home Assistant 2026.10.2 or newer in the 2026.10 series, use HACS → Custom repositories, add the same URL as an Integration, download it and restart Home Assistant.
Open this repository in the Marketplace.
For manual installation, copy the entire custom_components/mygrid_modbus
directory into <config>/custom_components/mygrid_modbus and restart Home Assistant.
Home Assistant installs the Python library from PyPI; network access is required
for its first installation.
See release instructions for manual-install ZIPs and publishing.
Configuration
Open Settings → Devices & services → Add integration → MyGrid ModuleTwo. Enter:
| Field | Meaning | Default |
|---|---|---|
| Host | Battery hostname or IP address, without a URL scheme | Required |
| Port | Modbus TCP port | 502 |
Unit ID is fixed to the documented value 1. Setup reads the device and verifies its register map before creating the entry. No commands are sent during setup.
After installation, start setup in Home Assistant.
Entities
| Entity | Unit / behavior |
|---|---|
| State of charge | % |
| Battery power | W; positive charging, negative discharging |
| Charging power / Discharging power | W; separate nonnegative values |
| Maximum charge / discharge power | W; live limits, both positive |
| Power setpoint | W; positive charges, negative discharges; 100 W increments |
| Status | normal, fault, telemetry_stale |
| Stored energy | Wh, current measurement |
| Total capacity | Wh, current measurement |
| Lifetime charged / discharged energy | Wh, cumulative total_increasing counters |
| Problem | On for status fault or any set fault bit |
| Fault flags | Raw 32-bit value with active_faults names; disabled by default |
| Map version | Diagnostic; disabled by default |
| Individual fault indicators | All 22 documented bits; disabled by default |
| Restart | Diagnostic button; disabled by default |
Enable optional entities on the device’s entity list. Fault names are described in the register reference. Bit 0 can mean a battery communication fault or a battery-system error. Unknown bits remain visible in the raw flags and trigger Problem.
When status is telemetry_stale, state of charge, measured/derived power, and fault indicators become unknown. Other valid registers remain available. A connection failure makes live measurements unavailable. Lifetime energy counters retain their last confirmed native values and restore saved values across entity restarts. The integration reports failures on transitions and recovers automatically as polling resumes.
Power commands
Change Power setpoint, or call Home Assistant’s standard number.set_value action. A command reads fresh limits, validates a multiple of 100 W, writes once, then reads back what the battery kept. The number shows that confirmed value, including any device-side clamp if limits changed. Limits are also bounded by the register’s signed 16-bit representation.
Commands are explicit only: setup, polling, reconnect, option changes, and unloading never write power. The integration does not restore old commands, run a charging strategy, or enforce a desired setpoint. The firmware applies a setpoint about once a second; readback confirms acceptance, not actual power delivery. Check measured power and status afterward.
The manual does not specify a command watchdog or loss-of-connection fallback. Do not assume the battery stops when Home Assistant stops. Write zero explicitly to request idle. A failed write/readback means the command may have been applied: check current readings before deciding whether to send another command. Automatic write retries are disabled.
Restart sends 1 to register 9 once, makes cached telemetry unavailable, and resumes reads on the normal polling schedule. A battery that restarts before acknowledging may report an uncertain command; it is never automatically resent.
Energy dashboard
Under Settings → Dashboards → Energy, add battery storage with Lifetime charged energy for energy into the battery and Lifetime discharged energy for energy out. Stored energy and Total capacity are snapshots and must not be used as cumulative energy flow.
For live power, choose Use an inverted entity and select Battery power. Home Assistant’s dashboard expects positive values while discharging, but Battery power is positive while charging, so the standard option would show charging as discharging. Do not pick Use two entities with Charging power and Discharging power unless you want that: Home Assistant then creates an extra helper sensor named “Battery Power” (entity ID ending in _net_power) next to the integration’s own Battery power sensor, which looks like a duplicate. The inverted option also creates a helper, but it is named “Battery power Inverted”.
The manual explicitly documents cluster-wide SOC, limits and setpoints. It does not establish the aggregation scope of every energy register. Confirm those totals on your cluster before relying on whole-house statistics. The protocol exposes no follower list or serial numbers; one configured leader produces one device, not invented follower devices.
Options, updates and reconfiguration
Use the integration’s Configure option to change polling from 5 seconds to an integer between 2 and 300 seconds. One function-03 request reads all 18 registers per poll. Explicit commands add fresh-limit and readback requests. Configuration changes reload the connection without writing power.
Use Reconfigure to change the host/port while keeping the entry’s device, entities and history. Reconfiguration releases this entry’s old connection hold before probing and restores the old settings if probing fails. The manager closes a physical connection only after its last consumer releases it. Because there is no hardware identity register, aliases cannot be reliably deduplicated and replacement hardware cannot be detected. Use one address per physical endpoint; delete and recreate the entry when replacing the battery, to avoid combining histories.
Home Assistant manages one Modbus connection per canonical endpoint and serializes requests across integrations. MyGrid shares this connection; setup probes use temporary holds and entry unload releases only its own hold. Restart and command failures never explicitly disconnect another consumer. This does not allow a separate test program to share the battery’s TCP connection, and it does not arbitrate multiple writers.
No discovery, authentication, firmware updates, serial/RTU connection, or cloud API is provided by this protocol.
Example automations
Entity IDs depend on your installation; replace the IDs below with those on your device. Positive power charges; zero requests idle. These examples run only when explicitly triggered and do not compete with another controller.
alias: MyGrid charge at a scheduled time
triggers:
- trigger: time
at: "01:00:00"
conditions:
- condition: numeric_state
entity_id: sensor.mygrid_moduletwo_state_of_charge
below: 80
- condition: numeric_state
entity_id: sensor.mygrid_moduletwo_maximum_charge_power
above: 499
actions:
- action: number.set_value
target:
entity_id: number.mygrid_moduletwo_power_setpoint
data:
value: 500
alias: MyGrid idle at end of charge window
triggers:
- trigger: time
at: "05:00:00"
actions:
- action: number.set_value
target:
entity_id: number.mygrid_moduletwo_power_setpoint
data:
value: 0
Fault alerts can use the Problem entity as a state trigger. Status telemetry_stale and unknown/unavailable entities should be handled separately from a confirmed healthy battery.
Troubleshooting and diagnostics
| Symptom | Check |
|---|---|
| Cannot connect | Correct LAN/IP/port, Home Assistant control source enabled in the app, Auto leader, no competing Modbus client. If all of these are right and port 502 still refuses connections, Modbus is probably not enabled on your battery: contact MyGrid support (see the enablement guidance above) |
| Incompatible Modbus settings | Another consumer holds this endpoint with conflicting connection parameters; align those settings |
| Unsupported map | Only map version 2 is implemented; obtain the matching firmware manual before extending it |
| Command rejected | Multiple of 100 W, within fresh charge/discharge limits; negative for discharge |
| Power changes unexpectedly | Another integration, app or automation may be writing the same shared setpoint |
| Unknown measurements | Status 2 means firmware telemetry is stale; wait for status 0 or 1 |
| Unavailable | Device or network is offline; polling will reconnect without replaying commands |
| Restart command not confirmed | Firmware may have restarted before replying; check availability before retrying manually |
Download diagnostics from the integration menu. Diagnostics include decoded telemetry, update-report status and a fresh, replayable raw-register dump, with network addresses and entry identifiers omitted from the integration
payload. The complete Home Assistant download can also contain wrapper data,
other integrations and setup-time entry IDs: review the entire file before sharing. An offline device reports the failure type without exposing raw exception text; an unloaded entry reports NotLoaded. The dump may reveal household energy usage. Diagnostic reads never issue commands.
Remove the integration under Devices & services to stop polling and release its connection hold. Home Assistant closes the physical connection when its last consumer releases it. Removal does not send a zero setpoint. On Home Assistant 2026.11 or newer, open this repository under Settings → Marketplace, select ⋮ → Uninstall, and follow any restart prompt. On Home Assistant 2026.10.2–2026.10.x, remove the HACS download and restart. For a manual installation, remove the local directory and restart. Existing recorder history follows Home Assistant’s normal retention settings.
Development
This is the community-testing integration for the ModuleTwo. HACS allows one integration per repository, so each MyGrid device has its own HACS repository. This repository is the source of truth for its integration code and tests; the device library is a separate PyPI package.
| Repository | Role |
|---|---|
python-mygrid-modbus |
Standalone component-based ModuleTwo library (PyPI package mygrid-modbus), supplied mock-backend tests, query helper and PyPI release workflow |
ha-mygrid-modbus |
This HACS integration: domain mygrid_modbus, depending on the PyPI library |
ha-mygrid-voltbridge |
The matching HACS integration for the VoltBridge P1 meter (domain mygrid_voltbridge), which is a separate integration |
ha-mygrid-core |
Dormant umbrella integration (domain mygrid) kept for a possible Home Assistant core contribution; not used or maintained for the HACS packages |
A checkout of this repository is self-contained for tests and installation:
uv sync --frozen
uv run ruff check .
uv run ruff format --check .
uv run mypy
uv run pytest
uv run python scripts/validate_metadata.py
uv run python scripts/build_release.py
CI runs ruff, mypy and the tests, validates the manifest against pyproject.toml, builds the manual-install ZIP, and runs HACS and hassfest validation. The integration ships the community project’s green lightning icon; HACS checks branding without exemptions. No official quality rating is claimed.
Change integration code and tests here. Change device or protocol behavior in the sibling python-mygrid-modbus repository, publish a release to PyPI, then bump the mygrid-modbus== pin in custom_components/mygrid_modbus/manifest.json and in the dev dependency group of pyproject.toml (run uv lock). scripts/validate_metadata.py fails if the two pins differ. This integration and the core overlay use different domains, so entries do not migrate between them.
The library tests models with the supplied mock fixtures and both actual transport backends. This package tests the integration wiring, shared sockets, energy-counter restoration and raw diagnostics. Neither controls real hardware. See architecture, hardware testing, and release instructions.
To try the integration in a real Home Assistant, run scripts/develop: it starts Home Assistant with the component importable from this checkout and a configuration in config/ (ignored by git). The first start installs the default integrations’ requirements and needs network access; then open http://localhost:8123.