Skip to content

Instantly share code, notes, and snippets.

@christianbauer
Last active March 28, 2017 19:08
Show Gist options
  • Save christianbauer/d88a0df8d32b0c28b3c7a4052d0f249c to your computer and use it in GitHub Desktop.
Save christianbauer/d88a0df8d32b0c28b3c7a4052d0f249c to your computer and use it in GitHub Desktop.
DRL examples
package org.openremote.test.rules;
import org.openremote.model.*;
import org.openremote.model.asset.*
import elemental.json.Json;
global java.util.logging.Logger LOG;
global org.openremote.model.rules.Assets assets;
rule "Switch room lights off when apartment ALL LIGHTS OFF switch is off"
when
// In an asset of type RESIDENCE the power switch is turned off
$e: AssetUpdate(attributeName == "allLightsOffSwitch", type == AssetType.RESIDENCE, value.asBoolean() == false)
then
assets.query() // Execute a query to get "other" assets
.parent($e.getId()) // Where parent is the apartment in LHS
.type(AssetType.ROOM) // And the children are of type ROOM
.applyResults(assetIds -> assetIds.forEach(assetId -> assets.dispatch( // For each asset ID in result...
new AttributeEvent(assetId, "lightSwitch", Json.create(false)) // Dispatch an event that turns the switch off
)));
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment