# Room Occupancy

**Room occupancy** refers to the number of people detected in a specific [**room**](https://docs.butlr.io/asset-management/graphql-api-overview/rooms) at a given time. There are two ways to measure **room occupancy**: [**traffic-based**](https://docs.butlr.io/spatial-metrics#traffic-mode) or [**presence-based**](https://docs.butlr.io/spatial-metrics#presence-mode). Each method uses a different approach depending on the available sensor data and the type of insights required.

<figure><img src="https://3289302098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe3YixUK5tCcflJxye0bT%2Fuploads%2Fgit-blob-0812ebd4287d8cf28da7773b1f22ea2a5b7ec8ef%2Froom%20table.png?alt=media" alt=""><figcaption></figcaption></figure>

Below are sample queries for retrieving room-level occupancy data to analyze **peak**, and **average** within a selected time range.

{% hint style="success" %}
**Recommended Practices**

1. **Recommended Aggregation by Query Interval:**\
   To ensure accurate interpretation of occupancy data, we recommend different aggregation methods based on the query interval:
   1. **1-Minute Interval (we recommend query for <24h time ranges only due to performance)**

      Use `median` : this smooths out short-term fluctuations (e.g. quick in-and-outs) and best reflects actual occupancy minute-to-minute.
   2. **Larger Intervals (e.g. hourly, daily)**
      1. Use `mean` for average occupancy over the interval to help identify overall usage patterns.
      2. Use `max` for peak occupancy within the interval to understand the busiest times or capacity thresholds.
2. **Avoid Relative Time Queries:** Do not use relative time functionality (e.g., `-5m`) as it may result in missing data depending on query timing. Always specify absolute ***start*** and ***stop*** times.
3. **Timezone Configuration:** Always provide a **timezone** when querying traffic-based occupancy
4. **To mitigate traffic drift** due to miscounts, we recommend adding the filter: `"calibrated": "true"`
5. **Include Zero Values in Output:** To ensure zero values are included in the results, add the filter:

```json
"window": { "create_empty": true }
"filter": { "value": { "gte": 0 } }
```

{% endhint %}

### Traffic-based Room Occupancy

If traffic sensors are installed at the room entrance(s), you can use the sample queries below to retrieve the estimated room occupancy counts.

<div align="left"><figure><img src="https://3289302098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe3YixUK5tCcflJxye0bT%2Fuploads%2Fgit-blob-746a92f53c57249620d5b889327d3edacb75d792%2Ftraffic%20mode_room.png?alt=media" alt="" width="375"><figcaption></figcaption></figure></div>

Query the **peak hourly occupancy** of a room with [traffic](#traffic-mode) sensor installed:

{% hint style="info" %}
Use measurement: <mark style="color:purple;">**`traffic_room_occupancy`**</mark>

Use function: <mark style="color:purple;">**`max`**</mark>

Use `"calibrated": "true"`
{% endhint %}

<details>

<summary>Request</summary>

```json
// POST https://api.butlr.io/api/v3/reporting
{
    "window": {
        "every": "1h",
        "function": "max",
        "timezone": "Europe/Amsterdam" 
    },
    "filter": {
        "start": "2024-01-01T04:00:00Z",
        "stop": "2024-01-02T04:00:00Z",
        "measurements": ["traffic_room_occupancy"],
        "calibrated": "true",
        "rooms": {
            "eq": ["room_2qfew7oRPTDPQ0f7X9ZotfoiI3w"]
        }
    }
}
```

</details>

<details>

<summary>Response</summary>

```json
{
    "data": [
        {
            "field": "aggregator_occupancy",
            "measurement": "aggregator_headcount",
            "time": "2025-07-23T07:00:00Z",
            "value": 2,
            "space_id": "space_2SPA7GQmRtS7IcXpulHYhTZdQX",
            "space_name": "BURIPL-H2P",
            "room_id": "room_2qfew7oRPTDPQ0f7X9ZotfoiI3w",
            "room_name": "Conference Room 100"
            // ... more fields
        }
        // ... more data
    ]
}
```

</details>

***

Query the **average hourly occupancy** of a room with [traffic](#traffic-mode) sensor installed:

{% hint style="info" %}
Use measurement: <mark style="color:purple;">**`traffic_room_occupancy`**</mark>

Use function: <mark style="color:purple;">**`mean`**</mark>

Use `"calibrated": "true"`
{% endhint %}

<details>

<summary>Request</summary>

```json
{
    "window": {
        "every": "1h",
        "function": "mean",
        "timezone": "Europe/Amsterdam" 
    },
    "filter": {
        "start": "2024-01-01T04:00:00Z",//start of the day
        "stop": "2024-01-02T04:00:00Z",//current time
        "measurements": ["traffic_room_occupancy"],
        "calibrated": "true",
        "rooms": {
            "eq": ["room_2qfew7oRPTDPQ0f7X9ZotfoiI3w"]
        }
    }
}
```

</details>

<details>

<summary>Response</summary>

```json
{
    "data": [
        {
            "field": "aggregator_occupancy",
            "measurement": "aggregator_headcount",
            "time": "2025-07-23T07:00:00Z",
            "value": 1.8,
            "space_id": "space_2SPA7GQmRtS7IcXpulHYhTZdQX",
            "space_name": "BURIPL-H2P",
            "room_id": "room_2qfew7oRPTDPQ0f7X9ZotfoiI3w",
            "room_name": "Conference Room 100"
            // ... more fields
        }
        // ... more data
    ]
}
```

</details>

***

### Presence-based Room Occupancy

Use the sample queries below to retrieve the total occupancy for areas covered by presence sensors in the room. Keep in mind that the sensor coverage area influences the count and may not represent the room's actual occupancy.

<div align="left"><figure><img src="https://3289302098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe3YixUK5tCcflJxye0bT%2Fuploads%2Fgit-blob-7a6ab5256f13d5f26005196ff2d4b4b0b6a49db1%2Fpresence%20mode_room.png?alt=media" alt="" width="375"><figcaption></figcaption></figure></div>

Query the **peak hourly occupancy** of a room with presence sensors installed:

{% hint style="info" %}
Use measurement: <mark style="color:purple;">**`room_occupancy`**</mark>

Use function: <mark style="color:purple;">**`max`**</mark>
{% endhint %}

<details>

<summary>Request</summary>

```json
// POST https://api.butlr.io/api/v3/reporting
{
    "window": {
        "every": "1h",
        "function": "max",
        "timezone": "Europe/Amsterdam"
    },
    "filter": {
        "start": "2024-01-01T04:00:00Z",
        "stop": "2024-01-02T04:00:00Z",
        "measurements": ["room_occupancy"],
        "rooms": {
            "eq": ["room_2qfew7oRPTDPQ0f7X9ZotfoiI3w"]
        }
    }
}
```

</details>

<details>

<summary>Response</summary>

```json
{
    "data": [
        {
            "field": "room_occupancy",
            "measurement": "room_occupancy",
            "time": "2024-01-01T04:00:00Z",
            "value": 2,
            "space_id": "space_2SPA7GQmRtS7IcXpulHYhTZdQX",
            "space_name": "BURIPL-H2P",
            "room_id": "room_2qfew7oRPTDPQ0f7X9ZotfoiI3w",
            "room_name": "Conference Room 100"
            // ... more fields
        }
        // ... more data
    ]
}
```

</details>

Query the **average hourly occupancy** of a room with presence sensors installed:

{% hint style="info" %}
Use measurement: <mark style="color:purple;">**`room_occupancy`**</mark>

Use function: <mark style="color:purple;">**`mean`**</mark>
{% endhint %}

<details>

<summary>Request</summary>

```json
// POST https://api.butlr.io/api/v3/reporting
{
    "window": {
        "every": "1h",
        "function": "mean",
        "timezone": "Europe/Amsterdam"
    },
    "filter": {
        "start": "2024-01-01T04:00:00Z",
        "stop": "2024-01-02T04:00:00Z",
        "measurements": ["room_occupancy"],
        "rooms": {
            "eq": ["room_2qfew7oRPTDPQ0f7X9ZotfoiI3w"]
        }
    }
}
```

</details>

<details>

<summary>Response</summary>

```json
{
    "data": [
        {
            "field": "room_occupancy",
            "measurement": "room_occupancy",
            "time": "2024-01-01T04:00:00Z",
            "value": 2,
            "space_id": "space_2SPA7GQmRtS7IcXpulHYhTZdQX",
            "space_name": "BURIPL-H2P",
            "room_id": "room_2qfew7oRPTDPQ0f7X9ZotfoiI3w",
            "room_name": "Conference Room 100"
            // ... more fields
        }
        // ... more data
    ]
}
```

</details>
