Digital Twin

Building Digital Twin for Facilities Management

How to create a building digital twin that links BIM geometry with live HVAC, occupancy and energy data streamed over MQTT, with topic design, code and a rollout checklist.

Building digital twin showing a BIM model of an office floor with rooms colored by live temperature and occupancy data
Run this on your own MQTT brokerGet a private, managed MQTT broker on the Free plan and start from ready-made code samples.
Try it free Code samples No card required

A building digital twin connects the static design model of a facility, usually a BIM file, with live data from HVAC, occupancy sensors and energy meters. This guide shows facilities teams how to link the two, how to structure building data on an MQTT broker, and how to roll out a twin that actually changes how the building is operated.

Why Facilities Teams Build a Building Digital Twin

Facilities management has always had a data problem. The building automation system (BAS) knows supply air temperatures, the access control system knows badge swipes, the energy meters know consumption, and the BIM model knows where everything physically sits. They rarely talk to each other. When a tenant complains that meeting room 3.14 is too warm, someone opens three systems and a floor plan PDF to investigate.

A building digital twin puts these views into one spatial model. Click room 3.14 and you see its temperature, setpoint, the VAV box that serves it, the air handler upstream, current occupancy and how much energy the zone has consumed today. The twin does not replace the BAS; it sits above it and makes the data usable across teams.

Typical goals are:

  • Faster fault diagnosis by showing equipment relationships spatially
  • Comfort management by comparing room conditions against occupancy
  • Energy reduction by finding zones conditioned while empty
  • Space planning based on real utilization rather than booking data
  • Better handover from construction to operations, since the BIM model stays useful

For the general concepts behind all of this, start with the digital twin technology guide.

BIM Plus Live Data: The Core Idea

BIM models (often exchanged as IFC files) contain geometry and metadata: spaces, walls, equipment, and the relationships between them. Every element has a GlobalId. The trick of a building twin is a mapping table that ties each BIM element to the live data stream that describes it.

BIM element Example GlobalId Live MQTT topic Signals
Space: Meeting Room 3.14 2O2Fr$t4X7Zf8NOew3FLOH connectmq/hq/floor3/room314/env temperature, humidity, CO2
Space: Meeting Room 3.14 2O2Fr$t4X7Zf8NOew3FLOH connectmq/hq/floor3/room314/occupancy people count, presence
VAV box VAV-3-07 1kTvXnbbzCWw8lcMd1dR4o connectmq/hq/floor3/vav307/state damper %, airflow, setpoint
Air handler AHU-2 0BTBFw6f90Nfh9rP1dlXr2 connectmq/hq/plant/ahu2/telemetry supply temp, fan speed, filter dP
Sub-meter Floor 3 3cUkl32yn9qRSPvBJVyWYp connectmq/hq/floor3/meter/energy kW, kWh

Keep this mapping in a small database or a versioned JSON file, not hardcoded in the viewer. Buildings change: rooms get split, sensors move, meters are replaced. When the mapping is data, a facilities engineer can update it without a code release.

Getting Building Data onto MQTT

Most building systems do not speak MQTT natively, so the twin needs a gateway layer.

  1. BACnet and Modbus equipment. A gateway reads points from the BAS (BACnet/IP) or meters (Modbus TCP/RTU) and publishes them as MQTT messages. Node-RED with BACnet and Modbus nodes is a common, low-cost choice; many commercial BAS gateways also publish MQTT directly.
  2. Wireless IoT sensors. Occupancy, CO2 and temperature sensors on LoRaWAN or Wi-Fi typically reach MQTT through their network server or directly from the device.
  3. Access control and booking systems. These usually expose an API. A small script polls or receives their events and republishes them to MQTT so the twin has one interface.

Once everything lands on a broker, the twin only needs one integration: MQTT subscriptions. That is the main architectural win. A hosted MQTT broker suits buildings well because facilities teams rarely want to run and patch broker servers themselves, and gateways in different buildings can all reach one TLS endpoint.

Topic Design for a Building Digital Twin

Mirror the physical hierarchy of the portfolio in the topic tree:

connectmq/<site>/<floor-or-plant>/<space-or-equipment>/<data-type>

connectmq/hq/floor3/room314/env
connectmq/hq/floor3/room314/occupancy
connectmq/hq/plant/ahu2/telemetry
connectmq/hq/plant/chiller1/state

This structure gives you useful wildcard subscriptions for free. A floor view subscribes to connectmq/hq/floor3/#. A portfolio comfort dashboard subscribes to connectmq/+/+/+/env. ConnectMQ shows such hierarchical topics in its live topic explorer and ISA-95 devices view, which helps when you are checking whether every gateway publishes where the mapping table expects. The digital twin MQTT article covers general topic and payload patterns.

Publish slow-changing state such as setpoints and equipment modes as retained messages, so a viewer opened at 7 a.m. immediately shows the full building rather than empty rooms.

Hands-On: Simulate a Room and Watch It Live

Try the pattern on broker.connectmq.com, the free public test broker. Use simulated values only, because anyone can read the public area. This Node.js script uses MQTT.js v5 to publish environment and occupancy data for one room:

const mqtt = require("mqtt");
const crypto = require("crypto");

const id = crypto.randomBytes(4).toString("hex");
const base = `connectmq/demo/${id}/hq/floor3/room314`;

const client = mqtt.connect("mqtts://broker.connectmq.com:8883", {
  clientId: `room-sim-${id}`,
  protocolVersion: 5,
});

let people = 0;

client.on("connect", () => {
  console.log(`Connected. Publishing under ${base}`);
  setInterval(() => {
    people = Math.max(0, Math.min(10, people + Math.round(Math.random() * 4 - 2)));
    const env = {
      temperatureC: +(21 + people * 0.25 + Math.random() * 0.3).toFixed(2),
      humidityPct: +(40 + Math.random() * 5).toFixed(1),
      co2Ppm: Math.round(450 + people * 70 + Math.random() * 30),
      ts: Date.now(),
    };
    client.publish(`${base}/env`, JSON.stringify(env), { qos: 0 });
    client.publish(`${base}/occupancy`, JSON.stringify({ people, ts: Date.now() }), {
      qos: 1,
      retain: true,
    });
  }, 5000);
});

client.on("error", (err) => console.error("MQTT error:", err.message));

Subscribe to it from the command line, using the prefix printed by the script:

mosquitto_sub -h broker.connectmq.com -p 1883 -i bldg-viewer-7731 -t "connectmq/demo/1a2b3c4d/hq/#" -v

In a browser twin, connect to wss://broker.connectmq.com:8084/mqtt, look up the BIM GlobalId for each incoming topic in your mapping table, and recolor the matching space by temperature or CO2. Open-source IFC viewers built on three.js make this straightforward; see web-based 3D digital twin for the viewer side.

Rollout Checklist

  1. Pick one floor and one problem. For example, comfort complaints on floor 3.
  2. Inventory points in the BAS and meters for that floor, and confirm they can be read.
  3. Clean the BIM model: spaces named consistently, equipment present, GlobalIds stable between model revisions.
  4. Define the topic hierarchy and mapping table before connecting gateways.
  5. Deploy gateways publishing over TLS (port 8883) with one credential per gateway.
  6. Store history with a separate subscriber writing to a time-series database; the broker handles live delivery.
  7. Set alert thresholds for obvious problems. ConnectMQ's portal supports threshold alert rules with an alerts log, which is handy for early checks such as CO2 above a limit.
  8. Review with the facilities team after a few weeks and expand to the next floor.

Pitfalls Specific to Buildings

  • BIM models built for construction, not operations. They often lack space names that match signage or contain hundreds of irrelevant elements. Budget time to simplify.
  • Privacy in occupancy data. Publish counts, not identities. Keep anything personal off public brokers and out of the twin entirely if it is not needed.
  • Slow BAS polling. Many BACnet gateways poll every minute or more. That is fine for comfort, but do not promise second-level updates you cannot deliver.
  • Unit confusion. Mixed Fahrenheit and Celsius or W and kW across vendors cause misleading colors. Normalize units in the gateway and include units in the topic documentation.

Related industrial patterns appear in the HVAC digital twin and energy digital twin articles.

Run Your Building Digital Twin on ConnectMQ

ConnectMQ gives your gateways and twin viewers one secure MQTT endpoint with TCP, TLS and WebSocket access. Create a free Serverless broker at app.connectmq.com, no credit card required, connect one floor's gateway, and watch the data in the live topic explorer before wiring up your BIM viewer.

Frequently Asked Questions

What is the difference between BIM and a building digital twin?

BIM is a static information model of the building's geometry and components. A building digital twin adds live operational data and keeps it synchronized, so the model reflects current conditions.

Can a building digital twin work with an existing BMS?

Yes. A gateway reads points from the BMS over BACnet or Modbus and publishes them to MQTT. The twin reads from the broker, so the BMS keeps controlling the building unchanged.

How often should building data be updated in the twin?

For comfort and occupancy, updates every 30 seconds to a few minutes are usually enough. Equipment alarms and state changes should be published as soon as they happen.

Is MQTT secure enough for building data?

Yes, when you use TLS, unique credentials per gateway and a private broker. Use the public test broker only for simulated data.

Related articles

All articles →

Your private MQTT broker is a few clicks away

Create an account, get your broker credentials and connect your first device — no servers to install, patch or scale.