Skip to main content

Groups

Organize devices into groups for batch operations and aggregated telemetry streaming. RelayX supports two grouping models.

Group Types

TypeAccessDescription
Logical groupsapp.logicalGroupTag-based grouping — a device can belong to multiple groups
Hierarchy groupsapp.heirarchyGroupPath-based grouping — organize devices in a tree structure (e.g., zone-1.building-a.floor-1)

Logical Groups

Tag-based groups where devices are organized by labels. A device can belong to multiple logical groups.

create()

Create a new logical group with tags and devices. The returned object includes stream() and off() methods for immediate telemetry streaming.

const group = await app.logicalGroup.create({
name: "floor_1_sensors",
tags: ["floor_1", "temperature"],
device_idents: ["sensor_01", "sensor_02"],
});

// you can start streaming right away
group.stream({
callback: (data) => console.log(data),
});

Example response:

{
"id": "69cb12a4ed4d9fe786145c01",
"name": "floor_1_sensors",
"tags": ["floor_1", "temperature"],
"device_ids": ["69ca39e4ed4d9fe786145b48", "69ca3a12ed4d9fe786145b49"]
}

update()

Add or remove tags and devices from an existing logical group. The returned object includes stream() and off() methods.

await app.logicalGroup.update({
id: groupId,
tags: { add: ["humidity"], remove: ["floor_1"] },
devices: { add: ["sensor_03"], remove: ["sensor_01"] },
});

list()

Retrieve all logical groups. Each group object includes stream() and off() methods.

const groups = await app.logicalGroup.list();

Example response:

[
{
"id": "69cb12a4ed4d9fe786145c01",
"name": "floor_1_sensors",
"tags": ["floor_1", "temperature"],
"device_ids": ["69ca39e4ed4d9fe786145b48", "69ca3a12ed4d9fe786145b49"]
},
{
"id": "69cb12b8ed4d9fe786145c02",
"name": "outdoor_sensors",
"tags": ["outdoor", "weather"],
"device_ids": ["69ca3a12ed4d9fe786145b49"]
}
]

get()

Retrieve a single logical group by ID. The returned object includes stream() and off() methods.

const group = await app.logicalGroup.get(groupId);

listDevices()

Retrieve all devices in a logical group.

const devices = await app.logicalGroup.listDevices(groupId);

Example response:

[
{
"id": "69ca39e4ed4d9fe786145b48",
"ident": "sensor_01",
"schema": {
"temperature": { "type": "number", "unit": "Celsius", "unit_symbol": "°C" },
"humidity": { "type": "number", "unit": "Percent", "unit_symbol": "%" }
},
"config": { "reportInterval": 5000 }
},
{
"id": "69ca3a12ed4d9fe786145b49",
"ident": "sensor_02",
"schema": {
"pressure": { "type": "number", "unit": "Pascal", "unit_symbol": "Pa" }
},
"config": {}
}
]

delete()

Permanently remove a logical group.

await app.logicalGroup.delete(groupId);

stream() / off()

Stream telemetry from all devices in a group, or stop streaming.

const group = await app.logicalGroup.get(groupId);

group.stream({
callback: (data) => {
console.log(`Device ${data.ident}:`, data.data);
},
});

// stop streaming
group.off();

Example callback data:

{
"ident": "sensor_01",
"data": {
"metric": "temperature",
"value": 22.5,
"timestamp": 1774690200000
}
}

Hierarchy Groups

Path-based groups that organize devices in a tree structure using dot-separated paths. Useful for physical layouts like buildings, floors, and rooms.

create()

Create a new hierarchy group with a dot-separated path and devices. The returned object includes stream() and off() methods.

const group = await app.heirarchyGroup.create({
name: "building_a_floor_1",
heirarchy: "zone-1.building-a.floor-1",
device_idents: ["sensor_01", "sensor_02"],
});

Example response:

{
"id": "69cb14c2ed4d9fe786145c05",
"name": "building_a_floor_1",
"heirarchy": "zone-1.building-a.floor-1",
"device_ids": ["69ca39e4ed4d9fe786145b48", "69ca3a12ed4d9fe786145b49"]
}

update()

Modify a hierarchy group's path or devices. The returned object includes stream() and off() methods.

await app.heirarchyGroup.update({
id: groupId,
heirarchy: "zone-1.building-a.floor-2",
devices: { add: ["sensor_05"], remove: ["sensor_01"] },
});

list()

Retrieve all hierarchy groups. Each group object includes stream() and off() methods.

const groups = await app.heirarchyGroup.list();

Example response:

[
{
"id": "69cb14c2ed4d9fe786145c05",
"name": "building_a_floor_1",
"heirarchy": "zone-1.building-a.floor-1",
"device_ids": ["69ca39e4ed4d9fe786145b48", "69ca3a12ed4d9fe786145b49"]
},
{
"id": "69cb14d6ed4d9fe786145c06",
"name": "building_a_floor_2",
"heirarchy": "zone-1.building-a.floor-2",
"device_ids": ["69ca3b22ed4d9fe786145b50"]
}
]

get()

Retrieve a single hierarchy group by ID. The returned object includes stream() and off() methods.

const group = await app.heirarchyGroup.get(groupId);

listDevices()

Retrieve all devices in a hierarchy group.

const devices = await app.heirarchyGroup.listDevices(groupId);

Example response:

[
{
"id": "69ca39e4ed4d9fe786145b48",
"ident": "sensor_01",
"schema": {
"temperature": { "type": "number", "unit": "Celsius", "unit_symbol": "°C" }
},
"config": { "reportInterval": 5000 }
}
]

delete()

Permanently remove a hierarchy group.

await app.heirarchyGroup.delete(groupId);

stream() / off()

Stream telemetry from devices in a hierarchy group with wildcard support.

const group = await app.heirarchyGroup.get(groupId);

group.stream({
heirarchy: "zone-1.building-a.*", // all floors in building A
metrics: ["temperature"],
callback: (data) => {
console.log(`${data.ident}${data.metric}: ${data.value}`);
},
});

group.off();

Example callback data:

{
"ident": "sensor_01",
"data": {
"metric": "temperature",
"value": 22.5,
"timestamp": 1774690200000
}
}