/zetta-automate-app

Zetta application for running simple if-than-that-rules

Primary LanguageJavaScriptMIT LicenseMIT

zetta-automate-app

A minimal Zetta application for automating devices based on simple if-than-that rules described by a YAML file.

Install

Install it into your existing Zetta project by running:

$ npm install timonreinhard/zetta-automate-app --save

Usage

Add the module to your existing server.js, e.g.:

var zetta = require('zetta');
var Automate = require('zetta-automate-app');

zetta()
  .use(Automate)
  .listen(1337);

Then create a custom rules.yml in the root of your project directory. See the following section on how to write rules.

Rule Syntax

# rules.yml
my_rule:
  trigger:
    Water Sensor: wet
    Button: pressed
  action:
    Pump: turn-on

my_rule

An unique identifier for the subsequent rule. Used for logging purposes and for triggering rules via Webhooks (see below).

trigger

The optional trigger contains a list of device names and their corresponding state that should trigger the rule. In the example above the rule my_rule would be triggered if the device with name Water Sensor changes its state property to wet. Or if the device named Button changes to pressed.

action

The action holds one or more device transitions that should be run whenever the rule gets triggered. In the given example the transition turn-on would be called for the device named Pump.

Webhooks

Rules can be triggered externally by sending POST requests to http://localhost:1337/rule_name/trigger.

Limitations

  • Only state changes are considered for triggering rule actions, other streams (monitors) are not supported.
  • Devices are identified by their human-friendly name property, which is however not necessarily unique.

Alternatives

I quickly hacked together this module, because I love the simplicity behind Zetta.js and wanted to do some basic home automation with it. If you're looking for something way more sophisticated, you might like one of these fine FOSS projects:

License

Published under the MIT License.