Anyway calling a file-based rule from UI has another problem:
each time the file is saved the rule gets another UID. The UI references rule UID’s. each time you save a changed file you lose the connection to the rule inside the UI.
I will implement the following solution:
1. Define a proxy item
String MyRuleTrigger "My Rule Trigger Proxy"
2. Set this proxy item to textual commands whatever in UI
3. Evaluate these commands inside the rule
triggers = []
triggers.append(ItemStateUpdateTrigger("MyRuleTrigger", None, "UI-TRIG").trigger)
@rule("test rule", description="test calling from ui")
class rsManagerRule(object):
def __init__(self):
self.triggers = triggers
def execute(self, module, inputs):
act = str(inputs["module"]).split("_")[0]
# value of MyRuleTrigger causing the trigger event
value = inputs[inputs["module"]+".state"]
Getting the value of MyRuleTrigger from the rule inputs binds also the event with the value
It’s not clear which rule you are talking about that was created in the UI. Are you calling a rule created in the UI from your Python rule? Or are you calling your Python rule from a rule created in the UI?
If the former then yes, it’s possible to pass data to the rule you’ve called. I think this is supported by the Helper Libraries (look at core.rules).
If not it’ll look something like the following JavaScript
// Run another rule
var FrameworkUtil = Java.type("org.osgi.framework.FrameworkUtil");
var _bundle = FrameworkUtil.getBundle(scriptExtension.class);
var bundle_context = _bundle.getBundleContext()
var classname = "org.openhab.core.automation.RuleManager"
var RuleManager_Ref = bundle_context.getServiceReference(classname);
var RuleManager = bundle_context.getService(RuleManager_Ref);
RuleManager.runNow("tocall");
var map = new java.util.HashMap();
map.put("test_data", "Passed data to called function!")
RuleManager.runNow("tocall", true, map); // second argument is whether to consider the conditions, third is a Map<String, Object>
map will be available as context in the called rule.
if the latter, then no it’s not possible. There is no place to in the UI to specify the data to pass in the forms. Though you can use the same code as above in a Script Action defined in the UI.
But I think the solution with a command to a string-type item is better for me. I could also pack a JSON string into the command (no clue how big that can be?).