MQTT API Configuration¶
Batcontrol provides an MQTT API that allows you to monitor and integrate your battery control system with other home automation platforms like Home Assistant. The MQTT interface publishes battery status, pricing information, and control states to configurable topics.
Basic Configuration¶
mqtt:
enabled: true
logger: false
broker: localhost
port: 1883
topic: house/batcontrol
username: user
password: password
Basic Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
enabled |
boolean | false |
Enable or disable the MQTT API |
logger |
boolean | false |
Enable MQTT logging for debugging |
broker |
string | localhost |
MQTT broker hostname or IP address |
port |
integer | 1883 |
MQTT broker port (1883 for unencrypted, 8883 for TLS) |
topic |
string | house/batcontrol |
Base topic for all batcontrol MQTT messages |
client_id |
string | batcontrol |
Optional unique client identifier for this instance; set it per deployment when several batcontrol instances share one broker |
username |
string | user |
MQTT broker username (if authentication required) |
password |
string | password |
MQTT broker password (if authentication required) |
Advanced Configuration¶
Connection Reliability¶
mqtt:
retry_attempts: 5 # Number of connection attempts at startup
retry_delay: 10 # Delay in seconds between attempts
| Parameter | Type | Default | Description |
|---|---|---|---|
retry_attempts |
integer | 5 |
Number of connection attempts at startup (at least 1) |
retry_delay |
integer | 10 |
Seconds to wait between attempts |
Broker not reachable at startup: batcontrol tries to connect retry_attempts times
(connection refused, timeout, DNS errors). If the broker is still not reachable, or does
not accept the connection within 30 seconds (e.g. wrong credentials or TLS settings),
batcontrol restores the inverter settings it has already changed and exits with an error
(exit code 1). It does not run without the configured broker. Let your supervisor restart
it: Docker with a restart: policy, the Home Assistant add-on with its watchdog enabled, or systemd with
Restart=on-failure. Once running, a lost connection is handled by automatic reconnects.
TLS/SSL Configuration¶
To connect to a TLS-secured MQTT broker, set tls: true and provide the path to your CA certificate. For mutual TLS, also supply a client certificate and key.
mqtt:
enabled: true
broker: mqtt.example.com
port: 8883
topic: house/batcontrol
tls: true
cafile: /etc/ssl/certs/ca-certificates.crt # required when tls: true
# certfile: /etc/ssl/certs/client.crt # only for mutual TLS
# keyfile: /etc/ssl/certs/client.key # only for mutual TLS
| Parameter | Type | Default | Description |
|---|---|---|---|
tls |
boolean | false |
Enable TLS/SSL for the broker connection |
cafile |
string | — | Path to the CA certificate file (required when tls: true) |
certfile |
string | — | Path to the client certificate (optional, for mutual TLS) |
keyfile |
string | — | Path to the client private key (optional, for mutual TLS) |
ciphers |
string | — | Optional OpenSSL cipher string (e.g. ECDHE+AESGCM); default: Python's ssl defaults |
All configured files must exist; otherwise batcontrol stops at startup with an error naming the
missing file (e.g. mqtt: certfile not found or not a file: /etc/ssl/certs/client.crt). Leave certfile and
keyfile unset unless your broker requires client certificates.
Grid Charge Lock (external HEMS/grid operator signal)¶
Some grid operators (in Germany: section 14a EnWG) or home energy management systems (HEMS) can request that controllable consumption devices stop drawing power from the grid. Batcontrol can listen to a single external MQTT topic for this signal. It mirrors evcc's External Limit convention.
mqtt:
enabled: true
grid_charge_lock_topic: hems/batcontrol/grid_charge_lock
| Parameter | Type | Default | Description |
|---|---|---|---|
grid_charge_lock_topic |
string | — | Optional. Full/absolute topic (not nested below topic) published by an external system. |
Payload semantics (case-insensitive):
1ortrue- Immediately block charging from the grid. The currentmax_charging_from_grid_limitis remembered and forced to0; an active forced grid charge (mode-1) is cancelled right away.0orfalse(default) - Restore the previously rememberedmax_charging_from_grid_limit.
The current lock state is published (retained) to house/batcontrol/grid_charge_locked.
This only blocks charging from the grid; PV charging and battery discharging are not affected.
Home Assistant Auto-Discovery¶
Batcontrol supports Home Assistant's MQTT auto-discovery feature, which automatically creates entities in Home Assistant without manual configuration.
mqtt:
auto_discover_enable: true
auto_discover_topic: homeassistant
| Parameter | Type | Default | Description |
|---|---|---|---|
auto_discover_enable |
boolean | true |
Enable Home Assistant auto-discovery |
auto_discover_topic |
string | homeassistant |
Base topic for auto-discovery messages |
When enabled, batcontrol will publish device and entity configuration messages to topics like:
- homeassistant/sensor/batcontrol/battery_soc/config
- homeassistant/sensor/batcontrol/current_price/config
- homeassistant/binary_sensor/batcontrol/charging_active/config
Published Topics¶
Batcontrol publishes data to the following topic structure (assuming base topic house/batcontrol):
System Status¶
house/batcontrol/status- System status (online/offline)house/batcontrol/last_evaluation- Timestamp of last evaluation (Unix timestamp)house/batcontrol/evaluation_intervall- Evaluation interval in seconds
Control & Mode¶
house/batcontrol/mode- Current operational mode:-1= Charge from Grid0= Avoid Discharge8= Limit Battery Charge Rate (peak shaving)10= Discharge Allowedhouse/batcontrol/charge_rate- Current charge rate in Whouse/batcontrol/limit_battery_charge_rate- Dynamic battery charge rate limit in Whouse/batcontrol/discharge_blocked- Whether discharge is blocked (true/false)house/batcontrol/api_override_active- Whether a temporary external/API override is active (true/false)house/batcontrol/control_source- Source that last selected the current control state (apioroptimizer)house/batcontrol/decision- Current mode with its value and a plain-language explanation as text, e.g.Charge from Grid 2133 W - usable energy (900 Wh) is below the 2500 Wh reserved for upcoming expensive hours, so 1600 Wh is charged from the grid(retained). The content changes on a status change only (a new mode, or a change of the charge rate / PV limit of the current mode by 25 % or more) and is republished every evaluation like the mode. Shown as the Decision sensor in Home Assistant -- see Understanding the Decision Sensor for what it means, and Decision Trace for how it is producedhouse/batcontrol/decision/attributes- JSON with the decision trace of that status change (retained):kind(modeorvalue),mode,previous_mode,value,previous_value,control_source,decided_by,why(the same explanation as the state, for the step that decided) and the evaluatedrecords, see Decision Trace for the full field reference. Used as attributes of the Decision sensorhouse/batcontrol/grid_charge_locked- Whether an external (HEMS/grid operator) request is currently blocking charging from the grid (true/false), see Grid Charge Lock
Battery Information¶
house/batcontrol/SOC- State of Charge in % (two decimal places, e.g.,69.00)house/batcontrol/max_energy_capacity- Maximum battery capacity in Wh (reduced by max SOC)house/batcontrol/gross_energy_capacity- Battery capacity in Wh without the max SOC reduction; SOC percentages refer to this valuehouse/batcontrol/stored_energy_capacity- Energy stored in battery in Whhouse/batcontrol/stored_usable_energy_capacity- Usable energy stored in battery in Wh (considering min SOC)house/batcontrol/reserved_energy_capacity- Energy reserved for discharge in Wh. This is the raw demand for upcoming expensive hours and can exceed the batteryhouse/batcontrol/reserved_energy_capacity_effective- The reserved energy in Wh capped to what the battery can hold back: between min SOC and the lower of max SOC andalways_allow_discharge_limit
Solar Surplus Information¶
See Forecast Metrics for a detailed explanation of these values and how to use them for flexible load control.
house/batcontrol/solar_surplus_wh- Expected PV overflow in Wh that cannot be stored in the batteryhouse/batcontrol/solar_active- Whether solar is currently producing (true/false)house/batcontrol/pv_start_battery_wh- Battery level in Wh at the next net-charging crossoverhouse/batcontrol/forecast_min_battery_wh- Minimum battery level in Wh over the entire forecast horizon
Configuration Limits¶
house/batcontrol/always_allow_discharge_limit- Always discharge limit (greater than 0, up to 1.0).0is never applied: the MQTT/API setter rejects it, and the evcc integration maps evcc'sbufferSoc0to0.01(1 %).house/batcontrol/always_allow_discharge_limit_percent- Always discharge limit in %house/batcontrol/always_allow_discharge_limit_capacity- Always discharge limit as stored energy in Wh: the limit times the capacity at 100% SOC, independent of the inverter'smax_soc. Only while the inverter does not report amax_soc, the capacity it reports as maximum is used instead.house/batcontrol/max_charging_from_grid_limit- Max charging from grid limit in effect (0.0-1.0)house/batcontrol/max_charging_from_grid_limit_percent- Max charging from grid limit in effect in %house/batcontrol/min_grid_charge_soc- Optional configured minimum grid-charge target (0.0-1.0)house/batcontrol/min_grid_charge_soc_percent- Optional configured minimum grid-charge target in %house/batcontrol/effective_min_grid_charge_soc- Runtime effective grid-charge target after strategy calculation (0.0-1.0)house/batcontrol/effective_min_grid_charge_soc_percent- Runtime effective grid-charge target after strategy calculation in %house/batcontrol/production_offset- Production offset multiplier (1.0= 100%,0.8= 80%, etc.)
Peak Shaving¶
See Peak Shaving for details:
house/batcontrol/peak_shaving/enabled- Whether peak shaving is enabled (true/false)house/batcontrol/peak_shaving/allow_full_battery_after- Target hour (0-23)house/batcontrol/peak_shaving/charge_limit- Current charge limit in W (-1= inactive / no limit)house/batcontrol/peak_shaving/price_limit- Price threshold in EUR/kWh
Price Information¶
house/batcontrol/min_price_difference- Minimum price difference in EUR (e.g.,0.050)house/batcontrol/min_price_difference_rel- Relative minimum price difference (e.g.,0.100)house/batcontrol/min_dynamic_price_difference- Dynamic price difference limit in EUR
Forecasts (JSON Arrays)¶
house/batcontrol/FCST/production- Forecasted solar production, Wh per interval (plus average W)house/batcontrol/FCST/consumption- Forecasted consumption, Wh per interval (plus average W)house/batcontrol/FCST/prices- Forecasted electricity prices in EURhouse/batcontrol/FCST/net_consumption- Forecasted net consumption, Wh per interval (plus average W)
Each interval is 15 or 60 minutes, depending on time_resolution_minutes -
see the Forecast Data Format section below.
Inverter-Specific Topics (per inverter, e.g., inverter 0)¶
house/batcontrol/inverters/0/SOC- Inverter SOC in %house/batcontrol/inverters/0/stored_energy- Stored energy in Whhouse/batcontrol/inverters/0/free_capacity- Free capacity in Whhouse/batcontrol/inverters/0/max_capacity- Maximum capacity in Whhouse/batcontrol/inverters/0/usable_capacity- Usable capacity in Whhouse/batcontrol/inverters/0/max_grid_charge_rate- Max grid charge rate in Whouse/batcontrol/inverters/0/max_pv_charge_rate- Max PV charge rate in Whouse/batcontrol/inverters/0/min_soc- Minimum SOC settinghouse/batcontrol/inverters/0/max_soc- Maximum SOC settinghouse/batcontrol/inverters/0/capacity- Total capacity in Whhouse/batcontrol/inverters/0/em_mode- Energy Manager mode (Fronius specific)house/batcontrol/inverters/0/em_power- Energy Manager power setting in W (Fronius specific)
Command Topics (Input API)¶
Batcontrol listens to the following /set topics for remote control:
Main Control¶
house/batcontrol/mode/set- Set operational mode (send-1,0,8, or10)house/batcontrol/charge_rate/set- Set charge rate in W (automatically sets mode to-1)house/batcontrol/limit_battery_charge_rate/set- Set dynamic battery charge rate limit in W
Configuration¶
house/batcontrol/always_allow_discharge_limit/set- Set always discharge limit (greater than 0 up to 1.0).0and values outside that range are rejected with a warning in the log, the current value stays: with0discharging would be allowed at every SoC and batcontrol would control nothing.house/batcontrol/max_charging_from_grid_limit/set- Set max charging from grid limit (0.0-1.0). The published value is the limit in effect: whilealways_allow_discharge_limitis lower than the value set here, it stays one percentage point below that limit and returns to the set value oncealways_allow_discharge_limitis raised again.house/batcontrol/min_price_difference/set- Set minimum price difference in EURhouse/batcontrol/min_price_difference_rel/set- Set relative minimum price difference (e.g.0.10for 10%)house/batcontrol/production_offset/set- Set production offset multiplier (0.0-2.0)
Peak Shaving¶
house/batcontrol/peak_shaving/enabled/set- Enable or disable peak shaving (true/false)house/batcontrol/peak_shaving/allow_full_battery_after/set- Set target hour (0-23)house/batcontrol/peak_shaving/price_limit/set- Set price threshold in EUR/kWh (-1disables the price component)
All /set changes are temporary runtime overrides and are not written back to the configuration file.
Commands are applied one at a time, in the order they arrive. A command that arrives while a control cycle is running is applied right after that cycle (usually within a second, longer only while the inverter is slow to answer), so the cycle cannot overwrite it with a decision it made before the command arrived. See Threading and Control Lock.
Inverter Control (per inverter, e.g., inverter 0)¶
house/batcontrol/inverters/0/max_grid_charge_rate/set- Set max grid charge rate in Whouse/batcontrol/inverters/0/max_pv_charge_rate/set- Set max PV charge rate in Whouse/batcontrol/inverters/0/em_mode/set- Set Energy Manager mode (Fronius: 0-2)house/batcontrol/inverters/0/em_power/set- Set Energy Manager power in W (Fronius specific)
Testdriver/Dummy Inverter (for testing)¶
house/batcontrol/inverters/0/SOC/set- Set SOC manually (0-100, testdriver only)
Forecast Data Format¶
The forecast topics (/FCST/*) publish JSON data with the following structure:
{
"data": [
{
"time_start": 1696435200,
"value": 625.1,
"power_w": 2500.5,
"time_end": 1696436100
},
{
"time_start": 1696436100,
"value": 800.0,
"power_w": 3200.0,
"time_end": 1696436999
}
]
}
Where:
- time_start - Unix timestamp for start of the interval
- time_end - Unix timestamp for end of the interval (15 or 60 minutes later,
depending on time_resolution_minutes)
- value - Forecasted value for that interval: Wh for production/consumption/net_consumption,
EUR for prices
- power_w - Only present for production/consumption/net_consumption: the same
quantity expressed as average power in W (value / interval_hours), so it
stays comparable regardless of the configured interval length
Example Configurations¶
Basic Setup (No Authentication)¶
mqtt:
enabled: true
broker: 192.168.1.100
port: 1883
topic: energy/batcontrol
With Authentication¶
mqtt:
enabled: true
broker: mqtt.example.com
port: 1883
topic: home/energy/batcontrol
username: batcontrol_user
password: secure_password_here
retry_attempts: 3
retry_delay: 5
Home Assistant Integration¶
mqtt:
enabled: true
broker: homeassistant.local
port: 1883
topic: batcontrol
username: mqtt_user
password: mqtt_password
auto_discover_enable: true
auto_discover_topic: homeassistant
Troubleshooting¶
Common Issues¶
- Connection Failed
- Check broker hostname/IP and port
- Verify network connectivity
-
Check username/password if authentication is enabled
-
Messages Not Appearing
- Verify the topic configuration
- Check broker logs for rejected messages
-
Ensure proper permissions for the MQTT user
-
Home Assistant Auto-Discovery Not Working
- Verify
auto_discover_enable: true - Check that Home Assistant MQTT integration is configured
- Ensure the discovery topic matches Home Assistant configuration
Debug Logging¶
Enable MQTT logging for troubleshooting:
mqtt:
enabled: true
logger: true # Enable debug logging
This will provide detailed information about MQTT connections, published messages, and any errors in the batcontrol log files.
Security Considerations¶
- Always use authentication (
username/password) in production - Use TLS encryption (
tls: true) when the MQTT broker is reachable over an untrusted network - Limit MQTT user permissions to only necessary topics
- Use strong, unique passwords for MQTT authentication