A minimal Zetta application for automating devices based on simple if-than-that rules described by a YAML file.
Install it into your existing Zetta project by running:
$ npm install timonreinhard/zetta-automate-app --save
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.
# rules.yml
my_rule:
trigger:
Water Sensor: wet
Button: pressed
action:
Pump: turn-on
An unique identifier for the subsequent rule. Used for logging purposes and for triggering rules via Webhooks (see below).
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.
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.
Rules can be triggered externally by sending POST
requests to http://localhost:1337/rule_name/trigger
.
- 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.
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:
- openHAB (Java)
- Home Assistent (Python)
- pimatic (Coffee Script)
Published under the MIT License.