Code Examples

This examples can be used as kick-off before jumping into the bco development. They pick up the basic functions like how to query, control and access any units.


Please make sure an mqtt broker and bco are started within your network before performing the howtos.

Java DAL Remote

For running any java examples you only need to include the dal remote dependency in your maven or gradle project description:


How to query unit configurations

Query units"query lights");
final List<UnitConfig> lightUnitConfigList =
    Registries.getUnitRegistry().getUnitConfigsByLocationIdAndUnitType(locationId, unitType);

How to activate a scene

Request the unit"request the scene with the alias \"Scene-9\"");
testScene = Units.getUnitByAlias("Scene-9", true, Units.SCENE);

Control the unit"activate the scene");

How to control a colorable light

Request the unit"request the light unit with the alias \"ColorableLight-0\"");
testLight = Units.getUnitByAlias("ColorableLight-7", true, Units.LIGHT_COLORABLE);

Control the unit"switch the light on");
testLight.setPowerState(PowerState.State.ON);"switch light color to red");

How to observe a location specific reed contact

How to observe service state changes

How to observe motion states of rooms

Observe a locations motion state

location.addServiceStateObserver(ServiceTempus.CURRENT, ServiceType.MOTION_STATE_SERVICE, (source, data) -> {
    // we know its a motion state
    final MotionState motionState = (MotionState) data;"EXAMPLE 2: "+location.getLabel("?") + " has changed its motion state to " + motionState.getValue().name());

How to resolve units via its label

Resolve the label

final List<UnitConfig> targetUnitConfigs =

How to check the infrastructure flag of a unit

The infrastructure flag can be used to determine if a unit is related to any important environment services. E.g. an internet router/ water boiler / voice assistant is connected to a powerplug. If its related POWER_SWITCH unit is marked as infrastructure (MetaConfig Entry: INFRASTRUCTURE = true) it will not be affected by any location based control actions (e.g. switch off all power switches in the living room). The following code shows how to check the infrastructure flag of a unit:

// Check infrastructure flag via UnitRemote
ColorableLightRemote unit = Units.getUnit("myUnitId", false, Units.COLORABLE_LIGHT);

// Check infrastructure flag via RemoteAction
RemoteAction action = new RemoteAction(...);