When the jsr223 integration was introduced, I started out creating a library that could handle interaction between rules. I have now started updating the script library to be compliant with the openhab-helper-library. How does it work?
My initial problem was that I wanted to have the ability control my lights through various rules, for instance I have one set of rules that is active when I am at home, other rules is active at night and so forth. Two rules could also control the same light, eg. when I open my door when it is dark, I want the spotlight to turn on for 2 minutes, but I also want the same light to turn on (together with another spotlight in the backyard) when somebody is at home and the outside door to the backyard is opened. A third spotlight will also turn on, when nobody is at home, it is a spotlight that the neighbours will notice :-). Just to illustrate that I have some complexity in my rules.
With jsr223 I have created a library to handle this complexity, allowing me to create rules on top of openHAB rules. Right now I have support for these rule types:
- ScheduleRule
- TriggerRule
I also plan to implement a SequenceRule, which I will use as a simple way of running a sequence of events (simulating presence when nobody at home)
Each rule has:
- Input
- Conditions
- Output
That is pretty much like the openHAB rules, but each rule is registered in a rule manager and in this context, each rule share the required state of the output. Lets say rule-1 and rule-2 both can turn on light-1. If both rulesturn on light-1, then the light will remain turned on, until the last rule turn off for light-1. It is simply implemented by adding a count of rules that request an item to be on. When it reaches zero it turns off.
I support the following input:
- Contacts (OPEN / CLOSED)
- Switches (ON/OFF)
- Dimmer (Only as ON/OFF)
I support the following conditions:
- ActiveNight (uses astro1 Action and Binding)
- Contacts (OPEN / CLOSED)
- Switches (ON/OFF)
- Dimmer (Only as ON/OFF)
- A jsr223 script that returns either True or False
I support the following outputs:
- Contacts (OPEN / CLOSED)
- Switches (ON/OFF)
- Dimmer (Only as ON/OFF)
If the conditions is false the script will be disabled.
I plan to implement the following features:
- Allow a script to be called as an output
- Support for Dimmers as output (e.g. use another value than ON as active value)
- Support more complex datatypes as triggers and conditions (e.g. Range/Percentage, Text, Number etc)
- Support for Text as output (similar to handling Dimmers)
I still need some rework in the library, I do expect some breaking changes, but for those interested I have the library checked in in my own
GitHub repo. It isn’t documented besides from a sample config file. I have tried to follow the jsr223 library concept, so in that manner it should be straight forward. I there is some interest for this library, I will share it to the official library, but for now it is in the personal section
Hope it can be helpfull for some of you.