Hello,
just wondering if it's possible to execute makros according to specific rules?
What I want to achieve is simply turn off all lights in the house when the switch in the bedroom is pressed three times in quick succession
is this possible somehow? Maybe using rules?
regards
Martin
Comments (6)
Jul 11, 2012
Martin Hauser says:
any ideas?any ideas?
Jul 11, 2012
Juha Lindfors says:
Hmm, there might be a way but I haven't had time to think/build examples that in...Hmm, there might be a way but I haven't had time to think/build examples that involve timing.
The rule engine itself does support temporal rules (trigger if certain events occur within some timeframe) but I'd need to spend some time on it to see what changes we need to make in our rule handling to support these.
In the meantime, there may be a way to do some simple counters by inserting facts into the knowledgebase but haven't created examples with it. A rule can insert new "facts" which are regular Java objects, and the idea is demonstrated in the vacation example here: Vacation Example
Java functions can also be called from within rules, for example System.currentTimeMillis() to retrieve current system time, there's an example of function definition here: Function Example
Combining those ideas or similar should make it possible to create simple timing and counters, at least until temporal rules are introduced. In the meanwhile the rule engine documentation is a useful source: http://docs.jboss.org/drools/release/5.2.0.Final/drools-expert-docs/html_single/
Jul 11, 2012
Martin Hauser says:
I think I might understand what you are saying, but I'm far from fit in "drools"...I think I might understand what you are saying, but I'm far from fit in "drools" programming. But I will give it a try...
basically, what the rule should do is, count how often the status of the button CHANGES, but when the time between two presses exceeds 2 second the counter gets reset to 0
just roughly drafted as I don't know any of the drools syntax:
Rule Button_pressed
when button1.status = ON and button_was_not_pressed then
press_count = press_count +1
button_was_pressed = true
if System.currentTimeMillis() - time_last_pressed > 2 seconds then
time_last_pressed = System.currentTimeMillis()
press_count= 1
else
if press_count = 3 then
issue "ALL_OFF_COMMAND"
end if
end if
end
Rule Button_not_pressed
whenn Button1.Status = OFF and button_was_pressed then
button_was_not_pressed = true
If this is correct, I "just" have to translate it to native DROOL...
Jul 11, 2012
Martin Hauser says:
sorry for the bad formatting, I swear I used proper indents when writing it... s...sorry for the bad formatting, I swear I used proper indents when writing it... seems like the Wiki swallows blanks...
Jul 11, 2012
Juha Lindfors says:
NP, the blanks must be preserved by wrapping code in {code} ... {code} segments....NP, the blanks must be preserved by wrapping code in {code} ... {code} segments.
Roughly you have the idea, the mind warp is going to be that you're thinking about it imperatively, where as rules are declarative (depending on your background those terms might or might not make sense).
Another idea might be to provide an alternative "Event Processor" (which is what the rule engine is as well) and instead of rules, execute an imperative script on the event instead. If you have Java background, customizing the controller to do this might be a nice little project – something on my todo list as well but I'm unlikely to get there anywhere soon.
Jul 11, 2012
Martin Hauser says:
Only thing I remember about declarative programming is that I hated it even back...Only thing I remember about declarative programming is that I hated it even back then when I knew how it was done
Implementing a new event processor sound like a lot of "fun"
, but the amount of ideas in my head exceed the available time by factor 5 to 10 
So, back to square one then... will take a break and dig into the drool examples to re-learn the long forgotten...