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 |
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 retry attempts
retry_delay: 10 # Delay in seconds between retry attempts
| Parameter | Type | Default | Description |
|---|---|---|---|
retry_attempts |
integer | 5 |
Number of times to retry connection on failure |
retry_delay |
integer | 10 |
Seconds to wait between retry attempts |
TLS/SSL Configuration¶
⚠️ Note: TLS/SSL support is currently untested and known to be non-functional: the implementation expects the certificate options nested below
tls, while the enable check expects a boolean — these requirements contradict each other. Track progress or report your use case in the project issues before relying on TLS.
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)
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 Whhouse/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
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 (0.0-1.0)house/batcontrol/always_allow_discharge_limit_percent- Always discharge limit in %house/batcontrol/always_allow_discharge_limit_capacity- Always discharge limit in Whhouse/batcontrol/max_charging_from_grid_limit- Max charging from grid limit (0.0-1.0)house/batcontrol/max_charging_from_grid_limit_percent- Max charging from grid limit in %house/batcontrol/min_grid_charge_soc- Optional minimum grid-charge target (0.0-1.0)house/batcontrol/min_grid_charge_soc_percent- Optional minimum grid-charge target 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/mode- Active mode (time,price, orcombined)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 in Whouse/batcontrol/FCST/consumption- Forecasted consumption in Whouse/batcontrol/FCST/prices- Forecasted electricity prices in EURhouse/batcontrol/FCST/net_consumption- Forecasted net consumption in W
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 (0.0-1.0)house/batcontrol/max_charging_from_grid_limit/set- Set max charging from grid limit (0.0-1.0)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/mode/set- Set mode (time,price, orcombined)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.
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": 2500.5,
"time_end": 1696438800
},
{
"time_start": 1696438800,
"value": 3200.0,
"time_end": 1696442400
}
]
}
Where:
- time_start - Unix timestamp for start of hour
- time_end - Unix timestamp for end of hour
- value - Forecasted value (W for production/consumption, EUR for prices)
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 - TLS encryption is currently not functional (see above) — keep MQTT traffic on a trusted local network
- Limit MQTT user permissions to only necessary topics
- Use strong, unique passwords for MQTT authentication