Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add a condition decorator #47

Open
andiwirs opened this issue Dec 9, 2018 · 6 comments
Open

[Feature Request] Add a condition decorator #47

andiwirs opened this issue Dec 9, 2018 · 6 comments

Comments

@andiwirs
Copy link

andiwirs commented Dec 9, 2018

Hello, for quite some time i thought about logical AND-links for triggering rules.

OR-links are already possible with successive @when decorators

@when("Item Item1 changed")
@when("Item Item2 changed")
...

but how about a corresponding @and decorator to a @when?

As one of many examples i have a rule that should notify me when a door or window was opened while i am on holiday. It triggers every time a door or window is opened:

@rule("rNotificationDoorWindowOpenedDuringHoliday")
@when("Descendent of gWindowsDoors changed to OPEN")
def rNotificationDooWindowrOpenedDuringHoliday(event):
	if items.Sw_sRules_HolidayMode == ON:
		# some warning

But i would prefer it would only trigger when i am away, because this would not flood the log that much:

@rule("rNotificationDoorWindowOpenedDuringHoliday")
@when("Descendent of gWindowsDoors changed to OPEN")
@and("Item Sw_sRules_HolidayMode  == ON")
def rNotificationDooWindowrOpenedDuringHoliday(event):
	# some warning

Whats your opinion? Thanks a lot :)

@mjcumming
Copy link

mjcumming commented Dec 9, 2018

Essentially, you are adding what the new rules engine calls a condition, ie the rule gets execute when the event happens and when certain conditions are met. I wonder if that could be added to the decorator?

@5iver
Copy link
Member

5iver commented Dec 9, 2018

Conditions could be added, and I've thought about adding them several times, but I always decide against it. It would be a significant amount of coding, and they really aren't necessary for JSR223 scripting, since you can very easily just add them to the script... like in your example. But thank you for the suggestion. We can leave this open to see if anyone else would be interested in putting it together.

It sounds like the issue you are trying to solve is the amount of logging. If your logs are getting flooded, you probably have it still set to DEBUG... change the logging level to WARN (log:set WARN org.eclipse.smarthome.automation). Also, IIRC the rule will still be triggered when using conditions, but the action will not be executed, so there would still be trigger and rule log entries.

@andiwirs
Copy link
Author

Thanks for your feedback. My logging is definitly set to WARN, so no chance with that approach :(

Regarding the conditions: If the rule would still trigger (and place a log entry) but not be executed then it would really not be better than a simple if condition in the action block.

@5iver
Copy link
Member

5iver commented Dec 10, 2018

Thanks for your feedback. My logging is definitly set to WARN, so no chance with that approach :(

Would you please paste in an example of the logs you're being flooded with? When logging level is set to WARN, there shouldn't be anything but errors, warnings, and log entries from your rules.

@andiwirs
Copy link
Author

It is not the flodding what you're thinking :)
I just have a lot of rules, which are triggered from various items and there i always get the entries that certain rules are running and then idle again.
So no log entries where i don't know where they are coming from...

@5iver
Copy link
Member

5iver commented Dec 10, 2018

OK... so totally under your control 😉

@5iver 5iver changed the title [Feature Idea] Logical link @and for triggering rules [Feature Request] Add a condition decorator Dec 10, 2018
@5iver 5iver added the jython label May 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants