ESPHome temperature over MQTT
This guide connects an ESPHome temperature sensor to PHOS through an existing MQTT broker. It uses the implemented MQTT observation provider and supported MQTT Discovery subset; it does not use the separate supported ESPHome Native API integration. For the task-oriented Web Admin steps, see the ESPHome Native API user guide.
Before you begin
- Install PHOS with its optional MQTT dependency:
pip install '.[mqtt]'. - Run an independently administered MQTT broker and grant PHOS read access to the configured discovery, state, and availability topics.
- Give every MQTT client a distinct client ID. Ordinary MQTT subscribers can independently receive the same topic.
- Keep broker credentials in PHOS secrets, never in YAML or this example.
The normal PHOS installer installs .[all], which includes MQTT. A manual or
minimal installation must opt in to .[mqtt]. PHOS is an MQTT client and
observation consumer, not a broker or a Home Assistant replacement.
ESPHome example
Configure MQTT for the device according to ESPHome’s own MQTT documentation.
The following illustrative sensor publishes a scalar temperature to
phos-example/esp32/temperature; use your real broker configuration and
credentials outside the committed configuration.
mqtt:
broker: mqtt.example.invalid
topic_prefix: phos-example/esp32
sensor:
- platform: dallas_temp
address: 0x0000000000000001
name: "PHOS Example Temperature"
state_topic: phos-example/esp32/temperature
unit_of_measurement: "°C"
An illustrative eligible state payload is 22.0. Enable the ESPHome MQTT
discovery announcement only when its metadata is within PHOS’s supported
temperature-sensor subset. Home Assistant is not required. PHOS does not claim
full Home Assistant Discovery or ESPHome compatibility.
Configure and approve in PHOS
- In Web Admin, open Connectivity → MQTT and add or edit the broker. Set a unique Client Identifier, secure secret references, TLS settings where required, and enable discovery with the correct prefix.
- Use Test Connection, then Apply MQTT configuration. The live lifecycle reconciles affected broker connections; a temporary reconnect may occur for that broker.
- Open Connectivity → MQTT Discovery. Expand the inactive candidate, verify its identity, quantity, unit, state topic, availability, and freshness policy, then save a complete review and approve it.
- Wait for a new, eligible non-retained temperature measurement. Approval and activation alone do not create an observation.
- Call
phos_get_physical_contextthrough a permitted MCP client. The result lists the current source inexternal_observations, separate from nativeenvironmentdata.
For manual mappings, configure the exact state topic, temperature_c, scalar
format, unit c, availability topic/payloads when used, and an appropriate
stale_after_seconds value in Connectivity → MQTT. The complete mapping,
Discovery, and Topic Explorer contract is in MQTT observations.
Read it through MCP
Ask a compatible agent: “What is the temperature reported by the external
office sensor?” The agent should call phos_get_physical_context and report the
returned value together with source and freshness, rather than infer meaning
from MQTT topics. For example, an authorized fresh observation has
quantity: "temperature_c", value: 22.0, unit: "c", and MQTT provenance.
If no item is present, check approval, activation, availability, freshness, and whether a new accepted measurement was received. A retained measurement is withheld by policy. Revoking approval removes the source from MCP without a PHOS restart; reapproval cannot disclose an observation from the prior authorization lifecycle.
Limits
External observations are bounded, in-memory latest values. They are not added to native measurement history, do not establish cross-provider physical-device equivalence, and are not fused or spatially interpreted. Topic Explorer uses a separate diagnostic connection and never feeds its samples into physical context.