ruleway 0.1.1 copy "ruleway: ^0.1.1" to clipboard
ruleway: ^0.1.1 copied to clipboard

A lightweight embeddable rule engine for device automation and edge applications.

example/main.dart

import 'package:ruleway/ruleway.dart';

Future<void> main() async {
  final rule = Rule(
    id: 1,
    targets: ['AC01', 'Door01'],
    triggers: [
      Trigger(
        type: TriggerType.attrChange,
        targetIndex: 0,
        attr: 'has_person',
        from: 0,
        to: 1,
      ),
    ],
    conditions: [
      Trigger(
        type: TriggerType.deviceExpr,
        targetIndex: 1,
        attr: 'door_open',
        op: '==',
        value: true,
      ),
    ],
    actions: [
      ActionConfig(
        type: 'emit_alarm',
        params: {'reason': 'person at open door'},
      ),
    ],
  );

  final engine = RuleEngine(timeZone: 'Asia/Shanghai', rules: [rule]);
  engine.onAlarm.listen((alarm) {
    print(alarm.toJson());
  });

  await engine.postAttrUpdate('Door01', {'door_open': true}, timestamp: 100);
  await engine.postAttrUpdate('AC01', {'has_person': 0}, timestamp: 101);
  await engine.postAttrUpdate('AC01', {'has_person': 1}, timestamp: 102);
  engine.dispose();
}
1
likes
140
points
8
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A lightweight embeddable rule engine for device automation and edge applications.

Repository (GitHub)
View/report issues

Topics

#rules #automation #iot #edge #sqlite

License

MIT (license)

Dependencies

sqlite3, timezone

More

Packages that depend on ruleway