Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Provide access to Thing status in textual (DSL) rules #1654

Closed
kaikreuzer opened this issue Jun 12, 2016 · 7 comments
Closed

Provide access to Thing status in textual (DSL) rules #1654

kaikreuzer opened this issue Jun 12, 2016 · 7 comments
Labels

Comments

@kaikreuzer
Copy link
Contributor

In rules it is often desirable to access the status of a Thing - currently, this information is not yet available.
We should add a function to access this information within the (old) Xtext DSL rules.

@kceiw
Copy link
Contributor

kceiw commented Dec 10, 2016

Hi @kaikreuzer . Can you point me how to start? I would like to implement it in spare time. I look at the document https://www.eclipse.org/smarthome/documentation. But still I am not sure how to do.

@kaikreuzer
Copy link
Contributor Author

Hi @kceiw Unfortunately, this isn't too trivial - you should have some understanding of Xtext/Xtend/Xbase.

FTR, this is the place where item names are made available and resolvable within scripts/rules:
https://github.com/eclipse/smarthome/blob/master/bundles/model/org.eclipse.smarthome.model.script/src/org/eclipse/smarthome/model/script/jvmmodel/ScriptJvmModelInferrer.xtend

And the classes in https://github.com/eclipse/smarthome/tree/master/bundles/model/org.eclipse.smarthome.model.script/src/org/eclipse/smarthome/model/script/scoping bring implicit java package imports, command and state types and the action methods.

Somewhere along these places the Things would need to be added. We probably should first discuss the syntax of what we want to achieve. Probably, adding an action could be the simplest solution in the end, although I think we would also want a new rule trigger type.

@kceiw
Copy link
Contributor

kceiw commented Jan 4, 2017

Thanks @kaikreuzer .
There is a big learning curve. I'm ramping up the code base and trying to understand ESH's design. It could take much time for me to work on this. Anybody with more experience is welcome to work on it. However, I'm still interested in working on it, for satisfy my own requirement.

I'm not quite understand about "the Things need to be added". My understanding is that the status is an attribute of the Thing. Why do we need to add Things?
And for me, I'm using OH1's syntax (is there a new one?). So something like

when
    Thing DoorSensor changed from ONLINE to DEAD
then
    ...
end

It seems more like a condition than an action. Do you mean that setting state DEAD is an action in the rule system, and that'll trigger whatever in between then and end to be executed? Please correct me if I misunderstand.

@kceiw
Copy link
Contributor

kceiw commented Jan 9, 2017

Hi @kaikreuzer,
After reading the code, I think we could
(assuming we're using the syntax "Thing DoorSensor changed from ONLINE to OFFLINE)

  1. Have RuleEngineImpl listen to/handle ThingStatusInfoChangedEvent. I also assume OFFLINE means disconnect. Otherwise, we need to create a new ThingStatusInfo for Thing.
    RuleEngineImple will execute the rule.
  2. Create a new EventTrigger, for example, ThingStatusEventTrigger.
  3. Need to extend the syntax in Rules.xtext.
  4. Expand RulesJvmModelInferrer to handle the new EventTrigger.
  5. Create a new state (ONLINE/OFFLINE) and add that to StateAndCommandProvider. And also add missing parts to org.eclipse.smarthome.model.script.scroping, for example, implicit package imports.

That's what I think what needs to be done to have a rule run when Thing goes OFFLINE.
If at the other hand, we want to get Thing status in all rules' actions (regardless their triggers), we don't need to do most of the above, but create a new ActionService to expose the things status (assuming this is what you mean by "adding an action"). But can we get any item state in any scripts? We may be able to use a similar syntax. And how do we expose those item state? Is it via some kind of ActionService? But I don't find any one.

Please let me know if I am missing anything.

kceiw added a commit to kceiw/smarthome that referenced this issue Feb 12, 2017
We're going to expose thing status to rule. This is the first step
toward the goal. The rule engine needs to subscribe to the event.

Bug: eclipse-archived#1654
Signed-off-by: Maoliang Huang <hellomao@outlook.com>
kceiw added a commit to kceiw/smarthome that referenced this issue Feb 12, 2017
The syntax is "Thing <thingUid> changed [from <oldState>] [to <newState>]"

Bug: eclipse-archived#1654
Signed-off-by: Maoliang Huang <hellomao@outlook.com>
kceiw added a commit to kceiw/smarthome that referenced this issue Feb 12, 2017
Similar to how ItemRegistry is exposedin RulesJvmModelInferrer, ThingRegistry
is exposed in RulesJvmModelInferrer.xtend

Bug: eclipse-archived#1654
Signed-off-by: Maoliang Huang <hellomao@outlook.com>
kceiw added a commit to kceiw/smarthome that referenced this issue Feb 12, 2017
RulesThingsRefresher acts like RulesItemRefresher. It listens to
things changes (added/removed) and schedules to reload the rules.

Bug: eclipse-archived#1654
Signed-off-by: Maoliang Huang <hellomao@outlook.com>
kceiw added a commit to kceiw/smarthome that referenced this issue Feb 12, 2017
Bug: eclipse-archived#1654
Signed-off-by: Maoliang Huang <hellomao@outlook.com>
kceiw added a commit to kceiw/smarthome that referenced this issue Feb 12, 2017
Convert the thing status from online to Online which is used in the rule.
Other thing status are converted to Offline.
The rule engine also supports the rule with trigger thing state change.

Bug: eclipse-archived#1654
Signed-off-by: Maoliang Huang <hellomao@outlook.com>
kceiw added a commit to kceiw/smarthome that referenced this issue Feb 12, 2017
Add the syntax 'Thing' <thingUid> 'received update' in the syntax file. This
is similar to item status update.
Handle the thing status event and execute thing update rule in rule engine.

Bug: eclipse-archived#1654
Signed-off-by: Maoliang Huang <hellomao@outlook.com>
kceiw added a commit to kceiw/smarthome that referenced this issue Feb 12, 2017
The rule is changed to take thingUid as a string instead of an ID. And we
don't use the type Thing internally to pass the information in the rule. This
is done so because when the thing is removed, it can occur before the rule is
checked and executed. When it occurs, we cannot get the Thing from thingUid.
Fix an issue in storing thing related rules and retrieve them.

Bug: eclipse-archived#1654
Signed-off-by: Maoliang Huang <hellomao@outlook.com>
kceiw added a commit to kceiw/smarthome that referenced this issue Apr 1, 2017
- Use a pre-defined list as the thing status. the list is the same as
  ThingStatus.

Bug: eclipse-archived#1654
Signed-off-by: kceiw <hellomao@outlook.com>
kceiw added a commit to kceiw/smarthome that referenced this issue Apr 1, 2017
- The thing uid contains ':' which cannot be used as an identifier. So we cannot
  use something like "ThingType:Thing" in the script and interpreset it as a
  thing. So we need to create an action to accept the thing uid and return its
  status.
- This is to allow the user to create more restrains using ThingStatusInfo in
  the script.

Bug: eclipse-archived#1654
Signed-off-by: kceiw <hellomao@outlook.com>
kceiw added a commit to kceiw/smarthome that referenced this issue Apr 1, 2017
kceiw added a commit to kceiw/smarthome that referenced this issue Apr 1, 2017
kceiw added a commit to kceiw/smarthome that referenced this issue Apr 1, 2017
kceiw added a commit to kceiw/smarthome that referenced this issue Apr 8, 2017
Bug: eclipse-archived#1654
Signed-off-by: kceiw <hellomao@outlook.com>
kceiw added a commit to kceiw/smarthome that referenced this issue Apr 15, 2017
Bug: eclipse-archived#1654
Signed-off-by: kceiw <hellomao@outlook.com>
kceiw added a commit to kceiw/smarthome that referenced this issue Apr 15, 2017
Bug: eclipse-archived#1654
Signed-off-by: kceiw <hellomao@outlook.com>
maggu2810 pushed a commit that referenced this issue Apr 18, 2017
Bug: #1654
Signed-off-by: kceiw <hellomao@outlook.com>
@sjsf
Copy link
Contributor

sjsf commented Jun 30, 2017

As far as I can see, #3001 added trigger and and an action service to access the thing status at any location. So to me it looks like this issue was resolved, or did I miss anything?

@sjsf sjsf closed this as completed Jun 30, 2017
@gersilex
Copy link

gersilex commented Jul 1, 2017 via email

@kaikreuzer
Copy link
Contributor Author

The only part that is missing is to add it to the documentation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants