name: mqtt-debug description: "MQTT/Homie/Home Assistant Discovery debugging for the pool-controller. Use when asked to debug MQTT communication, verify HA Discovery payloads, test Homie convention compliance, or troubleshoot publish/subscribe issues. π©πͺ Deutsche Trigger: MQTT Debug, Homie Konvention, Home Assistant Discovery, Nachrichten verfolgen, mosquitto, Publisher/Subscriber, MQTT Verbindung." keywords: - mqtt debug - mqtt fehlersuche - homie konvention - homie convention - home assistant discovery - ha discovery - mosquitto - mqtt verbindung - mqtt connection - publish subscribe - mqtt topics - last will testament - lwt
MQTT Debugging β Pool Controller
Debugging MQTT integration for the pool-controller. Supports Homie 3.0 and Home Assistant MQTT Discovery protocols.
π Code Search: Use
semble search "publishDiscovery"orsemble search "MQTT protocol"to trace MQTT code paths. SeeAgents.mdΒ§7 for fullsembleusage.
Architecture Overview
Pool Controller ββWiFiβββ
βΌ
ββββββββββββ
β MQTT β
β Broker β
ββββββ¬ββββββ
β
βββββββββββΌββββββββββ
βΌ βΌ βΌ
βββββββββββ βββββββββββ βββββββββββ
β openHAB β β HA β β Other β
β (Homie) β β(Discoveryβ β MQTT β
βββββββββββ β + Homie)β β Clients β
βββββββββββ βββββββββββ
Protocol Selection
Configured via ConfigManager::getMqtt().protocol in MQTTConfig.hpp:
MQTTProtocol::HOME_ASSISTANT(default) β Home Assistant MQTT DiscoveryMQTTProtocol::HOMIEβ Homie 3.0 convention
Runtime setting: mqtt-protocol in device web portal or config.
Home Assistant MQTT Discovery
Publisher: MqttPublisher.hpp/cpp
Key methods:
MqttPublisher::publishDiscovery()β publishes all discovery configsMqttPublisher::publishStates()β updates sensor/switch statesMqttPublisher::handleMqttMessage()β processes incoming HA commands
Discovery Topics
Base topic format: homeassistant/<component>/pool-controller/<object-id>/config
The controller publishes these discovery configs:
Sensors (temperature):
| Object ID | Name | Device Class | Unit | Icon |
|---|---|---|---|---|
pool-temp |
Pool Temperature | temperature |
Β°C |
mdi:pool |
solar-temp |
Solar Temperature | temperature |
Β°C |
mdi:solar-power |
controller-temp |
Controller Temperature | temperature |
Β°C |
mdi:thermometer |
Sensors (diagnostics):
| Object ID | Name | Device Class | Unit | Icon |
|---|---|---|---|---|
heap |
Free Heap Space | β | B |
mdi:memory |
max-alloc |
Max Alloc Block | β | B |
mdi:memory |
rssi |
WiFi Signal Strength | β | dBm |
mdi:wifi |
uptime |
System Uptime | β | s |
mdi:clock-outline |
Switches:
| Object ID | Name | Icon |
|---|---|---|
pool-pump |
Pool Pump | mdi:pump |
solar-pump |
Solar Pump | mdi:solar-panel |
Select:
| Object ID | Name | Options | Icon |
|---|---|---|---|
mode |
Operation Mode | auto, manu, boost, timer |
mdi:sync |
Numbers (parameters):
| Object ID | Name | Min | Max | Step | Unit | Icon |
|---|---|---|---|---|---|---|
pool-max-temp |
Max. Pool Temp | 0 | 40 | 0.1 | Β°C |
mdi:thermometer-chevron-up |
solar-min-temp |
Min. Solar Temp | 0 | 100 | 0.1 | Β°C |
mdi:thermometer-chevron-down |
hysteresis |
Temperature Hysteresis | 0 | 10 | 0.1 | K |
mdi:delta |
timer-start-h |
Timer Start Hour | 0 | 23 | 1 | h |
mdi:clock-start |
timer-start-min |
Timer Start Minute | 0 | 59 | 1 | min |
mdi:clock-start |
timer-end-h |
Timer End Hour | 0 | 23 | 1 | h |
mdi:clock-end |
timer-end-min |
Timer End Minute | 0 | 59 | 1 | min |
mdi:clock-end |
timezone |
Timezone Index | 0 | 9 | 1 | β | mdi:map-clock |
Debugging HA Discovery
Common issues:
- Truncated JSON payload β The serialization buffer must be β₯25% larger than the actual JSON output. If HA doesn't show entities, check buffer sizes in
MqttPublisher.cpp. SeeAgents.mdΒ§21 and thecpp-memory-optskill. - Device ID mismatch β
deviceId_is generated once. Verify it's consistent across reboots. - Discovery retained flag β HA Discovery messages should be published with
retained=true. device_class: 'measurement'/expected SensorDeviceClasserrors β These come from stale retained MQTT messages of the old Homie framework (VorgΓ€nger-Firmware). The old Homie auto-discovery published sensor entities withdevice_class: "measurement", which is not a validSensorDeviceClassin newer Home Assistant versions. The current firmware uses correct component types (numberfor parameters,sensoronly for actual sensors) and valid device classes (temperatureor none). Fix: delete retained messages or delete the old device entry in HA (β device registry).- Device disappears after cleanup / no new entities appear β Discovery messages are only published on boot / MQTT connect. After deleting the old MQTT device in HA, a reboot of the ESP32 is required to re-publish discovery. Use
pio run --target uploador power-cycle the device.
Manual verification:
# Subscribe to all HA discovery topics
mosquitto_sub -h <broker> -t "homeassistant/+/pool-controller/+/config"
# Subscribe to state updates
mosquitto_sub -h <broker> -t "homeassistant/+/pool-controller/+/state"
# Publish a command (e.g., set operation mode to "boost")
mosquitto_pub -h <broker> -t "homeassistant/select/pool-controller/mode/set" -m "boost"
Homie 3.0 Convention
The Homie convention uses device-topic structure:
homie/<device-id>/
βββ $homie β "3.0"
βββ $name β "Smart Pool Controller"
βββ $nodes β "pool-temp,solar-temp,..."
βββ $implementation β "esp32"
βββ pool-temp/
β βββ $name β "Pool Temperature"
β βββ $type β "temperature"
β βββ $unit β "Β°C"
β βββ temperature β "25.5"
βββ ...
Homie β HA Discovery Migration
The old Homie-based firmware auto-generated Home Assistant discovery from Homie properties. This created topics in the format:
homeassistant/sensor/<mac>_<node>_<property>/config
with device_class: "measurement" β which is invalid in newer HA versions (expected SensorDeviceClass enum).
The current firmware (MqttPublisher.cpp) uses native HA MQTT Discovery with correct component types:
- Temperatures β
sensorwithdevice_class: "temperature" - Diagnostics β
sensorwithoutdevice_class - Pump relays β
switch - Operation mode β
select - Parameters (hysteresis, timer, etc.) β
number(notsensor) - Device block:
manufacturer: "smart-swimmingpool",name: "Pool Controller"
Cleaning Up Stale Homie Retained Messages
After migrating to the new firmware, old Homie discovery messages may remain on the MQTT broker as retained messages, causing errors like:
Error 'expected SensorDeviceClass or one of 'date', 'enum', 'timestamp', ...'
when processing MQTT discovery message topic: 'homeassistant/sensor/<mac>_.../config'
Fix options:
Delete old device entry in HA β Einstellungen β GerΓ€te & Dienste β MQTT β GerΓ€t lΓΆschen, dann ESP32 neu starten (Discovery wird nur beim Boot/MQTT-Connect gepublisht)
Manually clear retained topics via mosquitto_pub:
mosquitto_pub -h <broker> -t "homeassistant/sensor/<mac>_#" -n -rHA MQTT-Konfiguration aktualisieren β SchaltflΓ€che "Konfiguration aktualisieren" in der MQTT-Integration
MQTT Connection Flow
From NetworkManager.hpp:
- WiFi connects (retry every
kWiFiRetryIntervalMs= 5000ms) - MQTT connects (retry every
kMqttRetryIntervalMs= 5000ms) - On MQTT connect β publish Discovery + States
- Periodically publish States every
loopIntervalseconds (default 10)
Debugging Tools
# Monitor all MQTT traffic from the controller
mosquitto_sub -v -h <broker> -t "#" | grep "pool-controller"
# Watch HA discovery specifically
mosquitto_sub -v -h <broker> -t 'homeassistant/+/pool-controller/+/config'
# Watch HA state updates
mosquitto_sub -v -h <broker> -t 'homeassistant/+/pool-controller/+/state'
# Check Homie base topic (old firmware, still useful for legacy)
mosquitto_sub -v -h <broker> -t 'homie/5ccf7fb97572/#'
# List all retained Homie discovery (stale cleanup)
mosquitto_sub -v -h <broker> -t 'homeassistant/sensor/5ccf7fb97572_#' --retained-only
# Delete stale retained Homie discovery
mosquitto_pub -h <broker> -t "homeassistant/sensor/5ccf7fb97572_#" -n -r
# Publish test commands (current firmware)
mosquitto_pub -t "homeassistant/switch/pool-controller/pool-pump/set" -m "ON"
mosquitto_pub -t "homeassistant/select/pool-controller/mode/set" -m "auto"
mosquitto_pub -t "homeassistant/number/pool-controller/hysteresis/set" -m "2.0"
Serial Debug Output for MQTT
When monitoring the ESP32 serial output:
β Network initialized
β MQTT connected
β Discovery published
Published states: ...
If MQTT connection fails, check:
- WiFi credentials are correct (WiFi config in web portal)
- Broker address and port are reachable
- Credentials (if broker requires auth)
- TLS settings match broker