Getting rule name in rule

Hello - I need to create lots of similiar rules and I need a way to:

  1. Disable rule for ex. 1h with rule code - I didn`t find any solution :frowning:
  2. dinamic get rule name in rule script- something like getActualRule().getName() - also not found a sollution :frowning:

I now I can achieve 1 point with making dummy items witch will be store time of last execution but I search of something more complex.
Pkt 2 is to make commandLine exec with rule name to ex. mysql and check it in external script.

Point 1:

You can use a dummy item with the expire binding
For example:

Install the expire binding!!

Switch dummy { expire="1h, command=OFF" }

In the rule:

rule "dummy disable for 1 hour"
when
    // Your trigger
then
    if (dummy.state == ON) return; //Do nothing if the dummy is ON
    // Do your stuff
    dummy.sendCommand(ON) // Starts the dummy item for 1 hour
end

Point 2:

I am afraid but that is not part of the rules DSL
But that can be achieved in the rules code:

rule "blah blah"
when
    // trigger
then
    val ruleName = "blah blah"
end

Now to the crux of your question:

Why? There are ways to use the same rule for several items:

The Rules DSL does not provide either OOTB, but the new rule engine (JSR223) does. I haven’t tried using the functionality outside of the UI, but I would be willing to look into it, if you wanted to go in this direction.

  1. As mentioned, the dummy Item and conditional statements that exit your Rule is your only option with Rules DSL.

  2. It might be helpful to describe in a little more detail what you are trying to accomplish. Since you can’t actually call another Rule from a Rule (in Rules DSL) what good would getting the name of a Rule do for you?

However, if you do want to call a Rule from another Rule, see Design Pattern: Separation of Behaviors.

I’ll note that both of these are features that will be available in the Experimental Rules Engine. And 2 I believe is available in JSR223 as Scott mentions.