# BACnet/IP

Read, watch and command BACnet/IP building devices

- Category: Industrial
- Capabilities: trellis, Streams, Commands, Operations, Entities
- Runs on: Linux x64, Linux ARM64, macOS Apple silicon, macOS Intel, Windows x64

Read, watch and command a building's equipment — air handlers, VAV boxes,
chillers, boilers, meters, lighting and room controllers — over **BACnet/IP**.
The connector finds the devices on your network, reads their objects, and keeps
every value current: by **change of value** where a device offers it, and by
polling where it does not.

## What you get

- **Every device found for you.** The connector asks the network who is there
  (a BACnet **Who-Is**) and reads each device's object list. Nothing to type in
  for a flat network.
- **One channel per object** at `/bacnet/<device>/<object>`, for example
  `/bacnet/1001/ai3` (analog input 3 of device 1001) or `/bacnet/1001/bo1`.
  Analog values carry the device's own units (°C, %, kPa, m³/h, kWh, …).
  Binary objects are shown as states named by the device (`Off`/`On`,
  `Closed`/`Open`); multi-state objects carry their state names.
- **Values as they change.** Where a device supports change-of-value
  subscriptions, each value arrives the moment the device reports it — no
  polling load on the device, and no waiting for the next poll.
- **Commands with BACnet priorities.** Objects you list as writable can be set
  from **Trellis** with `ch.write(path, value)`. Writes go in at the priority
  you choose, and every write is read back. **Relinquish** hands the object back
  to whatever controls it at lower priority (a schedule, the relinquish
  default) — the safe state.
- **Routed networks and remote subnets.** Devices behind BACnet routers are
  reached through the router; a remote subnet is reached by registering with
  its **BBMD**.

## Before you start

- This computer must be on the BACnet/IP network (or able to reach a BBMD on
  it). BACnet/IP uses **UDP port 47808**; a firewall between this computer and
  the devices must let it through in both directions.
- Only one program on a computer can hold port 47808 at a time. If another
  BACnet tool runs on this computer, close it, or set a different **Local UDP
  port** (devices that answer by broadcast are then only heard through a BBMD).

## Set up

1. In **Inputs**, choose **Add input** and pick **bacnet**.
2. **Devices** — leave empty to use every device on the network. Or list what
   you want, separated by commas: device instance numbers (`1001`), ranges
   (`2000-2099`), or addresses (`192.168.1.20`, `192.168.1.20:47808`) for a
   device that does not answer broadcasts.
3. **Updates** — **On change, where the device offers it** (recommended), or
   **Poll every value**.
4. **Poll rate (Hz)** — how often polled values are read (default 1).
5. **Objects** — leave empty for every object that holds a reading (analog,
   binary and multi-state inputs, outputs and values, and the like). Or narrow
   it: object types (`ai, bv`), single objects (`ai3`), or one device's object
   (`1001/ao3`).
6. **Writable objects** — the objects Trellis may command, e.g. `1001/ao3,
   1001/bo1`. Empty means nothing is commanded.
7. For a **remote subnet**, open **More settings** and enter its **BBMD**
   address.
8. Press **Test connection**. It sends a Who-Is and lists every device that
   answered — instance, name, vendor, model and address.

## Reference

### Channels

| object | channel | value |
|---|---|---|
| analog input / output / value (`ai`, `ao`, `av`) | `/bacnet/1001/ai3` | number, in the object's units |
| binary input / output / value (`bi`, `bo`, `bv`) | `/bacnet/1001/bi2` | state (off/on, with the device's own names) |
| multi-state input / output / value (`msi`, `mso`, `msv`) | `/bacnet/1001/msv4` | state number (1, 2, 3, …); the state names are on the channel |
| integer, positive-integer, large-analog, accumulator, pulse-converter, loop | `/bacnet/1001/iv1` … | number |
| characterstring value (`csv`) | `/bacnet/1001/csv1` | text |

The object's **name** on the device is shown beside each channel in the
channel list.

### Timing

Readings are stamped by this computer: a polled value at the middle of its
request and answer, a change-of-value notification when it arrives. BACnet
values carry no time of their own.

A value on change-of-value only arrives when it changes; a quiet channel is not
a stalled one. To prove a subscription is still alive, the connector also reads
each subscribed value directly every sixty poll periods (between 1 second and 5 minutes; once a minute at the default rate).
If a device has silently forgotten its subscriptions — most often after a
restart — the connector says so in the input's log and subscribes again.
Subscriptions are renewed at half their lifetime (**Subscription lifetime**,
default 300 s).

### Writing, priorities and relinquish

A BACnet output or commandable value has 16 priority levels; the highest
non-empty level wins. The connector writes at **Write priority** (default 8,
"manual operator"; 1 is highest, 16 lowest; level 6 is reserved by BACnet and
refused).

- Write a number (analog), `true`/`false` (binary) or a state number
  (multi-state) to the object's channel path.
- **Relinquish**: write `true` to `<path>/relinquish`, or write an empty value
  (`null`) to the object's path. The connector's level is emptied and the
  object falls back to the next level or its relinquish default.
- Each write is read back; Trellis sees the value the device now holds.
- An object that is not in **Writable objects** is refused before anything is
  sent.

### When things go wrong

| what happens | what you see |
|---|---|
| A device stops answering | Its channels show a gap from the last reading, the log says which device and address; the connector retries with back-off and resumes, subscribing again, when it answers |
| A device restarts | It announces itself; the connector subscribes again |
| A device refuses change-of-value | Said once in the log; its objects are polled |
| A device cannot answer a large request | The connector asks in smaller pieces |
| A poll takes longer than the poll period | The skipped polls are shown as a gap on each channel; requests never pile up behind a slow device |
| The BBMD refuses registration | **Test connection** fails and says so |

### Limits measured with simulated devices

One input, on a 16-core Linux machine, with simulated devices behind a BBMD:

| | measured |
|---|---|
| Devices × objects, all on change of value | 100 × 1,000 (100,000 channels) |
| Time from start to every channel streaming | under 3 seconds |
| Change-of-value notifications over an hour | 1,800 a second, none lost |
| Notification reaching the connector, median / 99th percentile / worst in an hour | under 1 ms / 1 ms / 91 ms |
| CPU | about 3 % of one core |
| Memory at that size | about 95 MB, reached in the first four minutes; within 1 % of that an hour later |
| Memory over an hour with devices restarting, going silent and dropping their subscriptions | flat |

## Troubleshooting

- **Test connection finds no devices** — check that this computer is on the
  devices' subnet (or that a BBMD is entered), that UDP 47808 is open in both
  directions, and that no other BACnet program holds the port.
- **A device is found but some objects are missing** — check **Objects**; only
  objects whose present value is a reading become channels.
- **A write is refused with "write access denied"** — the device does not allow
  that object to be written (an input usually needs to be out of service first).

## What has not been proven

| | status |
|---|---|
| Physical BACnet devices from a range of vendors | not yet run against real hardware; tested against simulated devices built from the standard and against an open-source reference device implementation |
| BACnet routers (devices on another network number) | addressed per the standard; not yet run through a physical router |
| Segmented answers from real devices | tested against simulated segmenting devices only |
| BACnet/SC, MS/TP | not supported |

## Supports

- Any BACnet/IP device: controllers, VAV boxes, chillers, boilers, air handlers, meters
- Devices behind a BACnet router (routed networks), and remote subnets through a BBMD

## Connection fields

| Field | Type | Required | Notes |
|---|---|---|---|
| Devices | Text | No |  |
| Updates | One of | No |  |
| Poll rate (Hz) | Number | No |  |
| Objects | Text | No |  |
| Writable objects | Text | No |  |
| Write priority (1 highest – 16 lowest) | Number | No |  |
| BBMD (remote subnet) | Text | No |  |
| BBMD registration (s) | Number | No |  |
| Local UDP port | Number | No |  |
| Network interface (IPv4 address) | Text | No |  |
| Broadcast address | Text | No |  |
| Subscription lifetime (s) | Number | No |  |
| Answer timeout (ms) | Number | No |  |
| Retries | Number | No |  |
