Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » Automation : RuleProvider : Use module outputs as config parameters on the next module(Is this allowed? can we dynamically configure rules without using a RuleTemplate?)
Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720477] Mon, 18 January 2016 20:35 Go to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
I trying to build a RuleProvider whereby I would use a Context to provide the trigger with some inputs.

This trigger does nothing at all, but I would like to use some of the context variables as parameters for the Configuration of the ActionModule of the Rule, and not as parameters for the inputs of the ActionModule. e.g. I would like to do something like:

Before triggering the trigger:
Map<String, Object> context = new HashMap<String, Object>();
context.put(SomeType.INPUT_EXPRESSION, someString);


In the RuleProvider bit where the Rule is built:
config = new HashMap<String, Object>();
config.put("script", triggerId + "." + SomeType.INPUT_EXPRESSION);
List<Action> actions = new ArrayList<Action>();
actions.add(new Action("MyScriptAction", "ScriptAction", config, null));


Is this kind of construct allowed?

If not, then because of the fact that ScriptAction takes the script it needs to execute as a Configuration parameter, and not as an Input, I would have to build a separate Rule for each different script I would like to flow through the Rule (e.g. I would need to develop a RuleTemplate and apply that over and over)

It would be very convenient to be able to "dynamically" configure a Module by using the Outputs of a previous Module

Karel

[Updated on: Mon, 18 January 2016 20:36]

Report message to a moderator

Re: Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720597 is a reply to message #1720477] Tue, 19 January 2016 15:38 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
No one? Wink

Studying the source code of the new Rule Engine it find the ambiguity between Inputs and Configurations more and more troublesome. It is very confusing on when a parameter should be a fixed value as part of the configuration of a Module, as to when it should/could be an Input. In some case, either one could work, and to achieve maximum re-usage of a Module, you could even put the same parameter as an Input and a Configuration element.

Because the only other way to render Rules variable is to us RuleTemplates, in case you get stuck with a Module you want to use. For example, the ScriptAction module takes the content of the Script to execute under the form of a Configuration. But I would prefer to have it as an Input, so that I can feed the same ScriptActionModule instance different scripts, for processing by the same underlying ScriptEgine. Another example: in the newly introduced Java API example PR, the StateConditionHandler works with both an element through the Input, and other one via the Configuration. How to decide what is appropriate?

I think this should be clarified, otherwise we will end up with a lot of boiler plate code over and over again to solve the same trivial "problem"

Re: Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720653 is a reply to message #1720477] Wed, 20 January 2016 08:21 Go to previous messageGo to next message
Marin Mitev is currently offline Marin MitevFriend
Messages: 22
Registered: December 2014
Junior Member
Hi Karel,
sorry for delayed answer
Here you can find an example of Script action which defins in its config property a script and in the script accesses the dynamic properties of the trigger output:
https://github.com/eclipse/smarthome/blob/master/bundles/automation/org.eclipse.smarthome.automation.module.script.test/ESH-INF/automation/rules/DemoScriptRule.json
Re: Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720656 is a reply to message #1720597] Wed, 20 January 2016 08:29 Go to previous messageGo to next message
Marin Mitev is currently offline Marin MitevFriend
Messages: 22
Registered: December 2014
Junior Member
Basically the difference between inputs and configurations is that configuration values are staticaly defined when the rule is created (using the UI) , while the values of the inputs are available only when rule is executed. Such example could be event data reported from a sensor. In your action you need the same data when the rule was triggered and you express this via trigger outputs and action inputs.
Re: Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720661 is a reply to message #1720656] Wed, 20 January 2016 08:38 Go to previous messageGo to next message
Marin Mitev is currently offline Marin MitevFriend
Messages: 22
Registered: December 2014
Junior Member
You can create templates only for the script actions - by defining composite module types as explained in the documentation
https://github.com/eclipse/smarthome/blob/master/docs/documentation/features/rules.md#composite-module-types
Using composite module type you can define custom configurations and/or input objects can link them to nested action configuration property.
Have a look at this demo which has more examples how to achieve the above usecase
https://github.com/eclipse/smarthome/blob/master/bundles/automation/org.eclipse.smarthome.automation.sample.handler/ESH-INF/automation/moduletypes/SampleModuleTypeDefinition.json
check lines #119-121:
"configuration":{
"message":"$compositeActionInput"
}
Re: Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720679 is a reply to message #1720597] Wed, 20 January 2016 09:38 Go to previous messageGo to next message
Yordan Mihaylov is currently offline Yordan MihaylovFriend
Messages: 10
Registered: January 2016
Junior Member
In addition to Marin I want mention that the configuration properties of the rule are intended to be changed by the user gui. For that reason they are properties, which can be linked by other modules of the rule, instead of hard coded values.
The process of rule update is following:
1) rule1 = getRule(uid) - rule engine returns a copy of the rule
2) user set new properties rule1.setProperties(map). At this moment this properties have not effect over the running rule
3) user updates the rule containing new properties. RuleRegistry.updateRule(rule1). The rule engine creates a copy of the passed rule validate it and if it is ok updates the runneing rule.
Re: Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720682 is a reply to message #1720679] Wed, 20 January 2016 09:42 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Ok - that is a solution. For now I have done it by means of a RuleTemplateProvider

It would be helpful of the Java API sample could be extended with a Composite Action so that it becomes clear how to do this via Java instead of json
Re: Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720683 is a reply to message #1720679] Wed, 20 January 2016 09:45 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Yordan Mihaylov wrote on Wed, 20 January 2016 04:38
. For that reason they are properties, which can be linked by other modules of the rule, instead of hard coded values.


Ok - How is this linkage by other Modules done in Java? In essence, I would like to connect a Trigger Input to an Action Configuration

Karel
Re: Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720717 is a reply to message #1720683] Wed, 20 January 2016 14:08 Go to previous messageGo to next message
Yordan Mihaylov is currently offline Yordan MihaylovFriend
Messages: 10
Registered: January 2016
Junior Member
You can't . The configuration properties of a module are private for the module. The legal result of module is defined by his outputs. You can access this result through the context of rule execution.
Also the rule flow is:
trigger -> check conditions -> execute actions
trigger have't depend of actions, actions depends from the trigger outputs
Of course you can create a special trigger which is base of action execution or rule status execution to chain rules, but this is not implemented.

[Updated on: Wed, 20 January 2016 14:16]

Report message to a moderator

Re: Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720724 is a reply to message #1720717] Wed, 20 January 2016 14:37 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Ok - I need to rephrase, my mistake .

How to connect a Trigger Output to an Action Configuration?

Re: Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720726 is a reply to message #1720717] Wed, 20 January 2016 14:42 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Ok, I need to rephrase, my mistake

How to connect a Trigger Output to an Action Configuration?
Re: Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720739 is a reply to message #1720726] Wed, 20 January 2016 15:24 Go to previous messageGo to next message
Yordan Mihaylov is currently offline Yordan MihaylovFriend
Messages: 10
Registered: January 2016
Junior Member
You can't connect configuration to anywhere. The configuration is only used by the module where it is defined. If you want to receive a result from other module this can be done only by input/output connections.
But I don't understand your logic. Why do you want to connect config property to output? When your module is evaluated it receives, in the context, all calculated outputs (to the moment of evaluation), this means you will receive the trigger outputs from context in form of triggerUID.outputUID=value instead of configuration propertis.
Re: Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720740 is a reply to message #1720739] Wed, 20 January 2016 15:29 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
the ScriptAction Module takes the script to execute as a Configuration parameter, not as an Input. So, each time I need to execute another script, well, I basically have to (1) update the rule, or (2) create a new rule. Which i now do, by using a RuleTemplate
Re: Automation : RuleProvider : Use module outputs as config parameters on the next module [message #1720746 is a reply to message #1720740] Wed, 20 January 2016 15:53 Go to previous message
Yordan Mihaylov is currently offline Yordan MihaylovFriend
Messages: 10
Registered: January 2016
Junior Member
Yes, but I think it is normal because you change the rule.
Previous Topic:Automation : How to add Triggers to an existing Rule?
Next Topic:Binding Hierarchy - Architecture Question
Goto Forum:
  


Current Time: Fri Apr 19 15:35:47 GMT 2024

Powered by FUDForum. Page generated in 0.02493 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top