Appearance
06 — Home Assistant over MQTT
This scenario proves the MQTT path end to end: the broker is configured and reported, a broker that fails costs the device nothing else, Home Assistant discovers every entity with no YAML, the controls are unavailable while the device is in local control, commands feed the watchdog and garbage does not, and — a hard rule — Home Assistant may write no OpenTherm frame.
You need: the device on the network; a broker (Mosquitto) you can stop and start; Home Assistant with the MQTT integration pointed at the same broker; mosquitto_sub/mosquitto_pub. Below, <broker> is the broker address, <prefix> the device's topic prefix (opentherm/<twelve hex of the MAC> unless changed) and <id> those twelve hex digits. Keep one terminal on the traffic for the whole walk:
sh
mosquitto_sub -h <broker> -v -t '<prefix>/#' -t 'homeassistant/+/<id>/#'Have the curl harness and the bus monitor from 00-setup-and-safety.md running — the bus must keep turning through every broker failure below. POST /api/config {…} below is shorthand for curl -sS -u ":$OTPASS" -H 'Content-Type: application/json' -d '{…}' http://$OT/api/config.
No host suite compiles the MQTT client task or its glue; what they do on a network is proven only here.
1. Setting the broker, and the status block
- [ ] Before any broker,
GET /api/status'smqttmember reads"configured":false,"connected":false, every counter 0, and the log carriesmqtt: no broker configured; MQTT stays off. - [ ]
POST /api/config {"mqtt_host":"<broker>","mqtt_user":"<user>","mqtt_password":"<pw>"}→200at once. Within ~2 s the log readsmqtt: broker …, prefix <prefix>, discovery onthenmqtt: broker connected, with no user or password in any log line;/api/statusreads"configured":true,"connected":true,"reconnects":1. - [ ]
mosquitto_subshows<prefix>/status online(retained),<prefix>/control/owner offline(local, retained),<prefix>/control_state/attributeswithreason/cause, and one<prefix>/<key>/stateper entity — spelled asGET /api/statespells them. Never an empty payload. - [ ]
GET /api/configreturns the sentinel formqtt_password; grep the whole capture for the password — it is absent.
2. Home Assistant mode needs a broker
- [ ]
POST /api/config {"control_mode":1}with nomqtt_hostset →422, fieldmode-needs-broker. A device cannot be handed to Home Assistant with nowhere to hear it.
3. A broker that fails costs nothing else
Nothing reboots because a peer is absent, and ot_bus never pauses. Watch ID 0's age_ms:
sh
while sleep 2; do
otget http://$OT/api/ot/raw \
| python3 -c 'import json,sys; d=json.load(sys.stdin); print(d["uptime_ms"], d["cycles"], [e["age_ms"] for e in d["ids"] if e["id"]==0])'
done- [ ] Stop the broker for 10 minutes. The log reads
mqtt: broker lost; retrying every 10 s, nothing else changesonce, thenmqtt: broker unreachable; N attempts so far …at most hourly — and nomqtt_client/esp-tlsinternals. ID 0'sage_msstays under ~2000,uptime_msgrows (no reboot), the boiler keeps doing what/api/controlsays, and the web answers throughout. - [ ] Start it: within ~10 s
mqtt: broker connected,reconnects+1, andmosquitto_subseesstatus online, every state and every discovery document again. - [ ] Flap it (stop 20 s / start 20 s for 5 minutes): no reboot, ID 0
age_msunder ~2000,reconnectscounts the flaps, one "lost"/one "connected" per flap. - [ ] Wrong password:
/api/statusshows"last_connack":5(or 4) with a reason, the log says the broker refused the connection once then hourly, no reboot; the right password back →connected,last_connack0. - [ ] A black-hole host keeps the web responsive;
POST /api/config {"mqtt_host":""}answers at once and within ~15 s (one connect timeout) the log readsno broker configured; MQTT stays off. Putmqtt_hostback before §4. - [ ] WiFi off 10 minutes: on return MQTT reconnects by itself, no reboot.
- [ ] The will, and the clean offline. With the broker up, pull the device's power at the wall. Within ~90 s (60 s keepalive + grace)
mosquitto_subprints<prefix>/status offlineretained (the broker published the will) and Home Assistant shows every entity unavailable. Power back on →status online, entities back.
4. Discovery — Home Assistant finds every entity, no YAML
- [ ] In HA → Settings → Devices there is one device named
device_name, modelopentherm-thermostat, with a firmware version, a Visit link tohttp://<device>/, and the MAC under connections — no YAML anywhere. - [ ] Every boiler reading appears (sensors / binary sensors), plus
control_modeandcontrol_state(enum sensors),ch_setpoint_effective,ch_enable_effective,failsafe_count,last_failsafe_duration_s, aheating_seasonbinary sensor, aRoom temperaturesensor and aRoom sourceenum, and five controls:ch_enable/dhw_enableswitches,ch_setpoint/dhw_setpointnumbers, and the season off button. - [ ] The HA log (filter "mqtt") carries no "Invalid discovery" / "not a valid" line for this device.
- [ ] Unsupported IDs never appear: no
max_ch_setpoint(ID 57), and after five minutesmosquitto_sub -t 'homeassistant/+/<id>/max_ch_setpoint/config'shows nothing retained. - [ ]
ch_setpoint's range in HA equalsflow_min_dc..flow_max_dc/ 10; changeflow_max_dcviaPOST /api/configand HA's max follows within ~2 s.dhw_setpoint's range is the boiler's ID 48 (or 30..80). - [ ] Restart Home Assistant: its birth message makes the device re-publish discovery, and
publishedin/api/statusjumps by ~the entity count within ~10 s. - [ ]
POST /api/config {"ha_discovery":false}clears every entity (empty retained configs);truebrings them back under the same ids. - [ ] Rename the device (
device_name): the HA device name changes with no duplicate entities. Changetopic_prefix: within ~2 s the old prefix'sstatusreadsofflineand everything reappears under the new prefix. The old prefix's other retained topics are left behind (clear them withmosquitto_sub --remove-retained). Put the prefix back.
5. In local mode the controls are unavailable
- [ ] In local mode
<prefix>/control/ownerisoffline; in HA the five controls are unavailable (not a stale writable value), whileheating_season,control_state, the*_effectivemirrors and every reading stay available. - [ ]
mosquitto_pub -h <broker> -t '<prefix>/ch_enable/set' -m 1→ the log readsmqtt: command refused: owned by the thermostat: control_mode is local …,rejected+1,/api/controlunchanged. - [ ]
POST /api/config {"control_mode":1}→ within ~2 s the owner topic readsonlineand the controls become available — never before the executorstateleaveslocal. Back to local → ownerofflinewithin ~2 s and the controls grey out.
6. Commands, and what feeds the watchdog
In HA mode, season on, watchdog_s 120. A refusal is logged at most once a minute — read rejected, not the log-line count.
- [ ] HA
ch_enableon →stateha_waiting→ha; the CH bit rises once the held ID 1 has gone out (the invariant,05-asking-for-heat.md);commands+1. The burner lights and the flow climbs — the whole heat path proven through Home Assistant. - [ ] HA
ch_setpointto 55 →held_setpoint_dc550 within ~1 s,ch_setpoint_effective55 within ~10 s. - [ ] A retained command does not feed the watchdog. Stop every HA automation writing this device, then:
POST /api/config {"mqtt_port":1884}(nothing listens; the subscription is gone);mosquitto_pub -h <broker> -r -t '<prefix>/ch_enable/set' -m 1(the broker only stores it);POST /api/config {"mqtt_port":1883}(reconnect, the broker replays with RETAIN=1). The log readsmqtt: command refused: a retained command is ignored;rejected+1,commandsdoes not move, and/api/controlreachesfailsafe~120 s after the last fresh command. Clean up:mosquitto_pub -h <broker> -r -n -t '<prefix>/ch_enable/set'. - [ ] A fresh
ch_enableevery 60 s keepsstatehafor 10 minutes. A freshdhw_enableevery 30 s alone does not:failsafeafter 120 s — DHW does not feed the watchdog. - [ ] The season button in HA turns
heating_seasonoff (stateseason_off, CH down);mosquitto_pub -t '<prefix>/heating_season/set' -m 1→ refusedonly the thermostat may turn the heating season on. - [ ]
mosquitto_pub -t '<prefix>/ch_setpoint/set' -m hello→ refusedthe payload is not a number(the log line does not containhello);-m 80(aboveflow_max) → refusedvalue out of range; neither feeds the watchdog. 100 garbage messages in 10 s →rejected+100 with at most one log line per minute. - [ ] HA
dhw_setpoint/dhw_enablework in HA mode. If the boiler answersUNKNOWN-DATAIDto ID 56 twice, thedhw_setpointentity disappears from HA until a reboot and every DHW write is refused — note it if it happens.
7. Home Assistant may write no OpenTherm frame
- [ ]
mosquitto_pub -h <broker>to<prefix>/room_setpoint/set -m 21.5,<prefix>/room_temperature/set -m 20and<prefix>/max_relative_modulation/set -m 50— each refusedmqtt: command refused: this entity is not Home Assistant's to write,rejected+3, and/api/ot/rawshows no write of ID 16/24/14 (theircount/age_msdo not move). The refusal is made at the one command entry point, not on the HTTP surface. - [ ]
<prefix>/max_ch_setpoint/set -m 60is refused too, but on this unit withboiler does not support this data-id: what is wrong with the request whoever sends it (ID 57 is unsupported here) is judged before who sent it. No ID 57 write appears either. - [ ] The same frame entity over REST still works — the rule is about who is writing, not the entity:
curl -sS -u ":$OTPASS" -H 'Content-Type: application/json' -d '{"value":20}' http://$OT/api/entities/room_setpoint→202 {"queued":{"data_id":16,"raw":5120}}, and ID 16'scountin/api/ot/rawmoves.
8. What the owner reads
- [ ] After a day with the broker off (or §3 extended),
GET /api/logholds at most ~24mqttlines beyond the transitions. - [ ] A broker ACL that lets the device publish but denies it the command subscription →
mqtt: the broker refused the command subscription: check its ACL, while states still publish.
Notes
- The failsafe seen from Home Assistant —
fs_disarmedvsfs_blind, the reboot-blind case, and the room-steered failsafe — is07-watchdog-and-failsafe.md. - The room-temperature source that Home Assistant can feed is
08-room-sources.md.