Use the Azure IoT Hub device twin to represent device state: the service side writes desired properties to configure the device; the device side writes reported properties to reflect actual state.
From a backend service, retrieve the full twin document using the GetTwin REST API or SDK method; parse tags, desired, and reported sections separately.
Query the twin store for fleet-wide state with the SQL-like IoT Hub query: SELECT * FROM devices WHERE properties.reported.temperature > 80 to find devices in alarm.
For physical-world modelling beyond simple key-value state, pair IoT Hub twins with Azure Digital Twins (ADT) using an event-driven pipeline: IoT Hub routes telemetry to an Event Hub, a Function updates the ADT model via the ADT SDK.
Define DTDL (Digital Twins Definition Language) models in ADT for each device class; instances inherit the model schema and allow graph-based relationship queries.
Use the ADT query API to traverse relationships, e.g., finding all sensors in a building floor, and update twin properties as telemetry arrives.
Known gotchas
IoT Hub device twins and Azure Digital Twins are separate services with different APIs; IoT Hub twins are per-device state stores while ADT supports complex graph relationships and inheritance.
Azure IoT Hub twin desired properties are capped at 32 KB and reported properties at 32 KB; store large configuration blobs in Blob Storage and reference them by URL in the twin.
ADT does not automatically sync with IoT Hub; the data pipeline (Event Hub + Function or IoT Hub message routing) must be built and maintained explicitly.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp