freedomotic

Listen to Events programmaticallyΒΆ

First you have to add a listener for each channel you want to listen to. In the onStart() method of your plugin add for example:

addEventListener("app.event.sensor.object.behavior.change");
addEventListener("app.event.sensor.environment.zone.change");
addEventListener("app.event.sensor.plugin.change");

if you want intercept all events about changing in sensors behaviors, zones or plugins.

Then modify the onEvent(EventTemplate event) method

protected void onEvent(EventTemplate event) {
        if (event instanceof ObjectHasChangedBehavior) {
            // here what you want todo
        } else if (event instanceof ZoneHasChanged) {
            // here what you want todo
        }
    }

Here a complete example.