For DSL Rule, we now have tags and time of day trigger available.
I also created a PR to add UID and another one is in progress to add conditions.
For DSL Rule, we now have tags and time of day trigger available.
I also created a PR to add UID and another one is in progress to add conditions.
Can someone explains what means and what is the purpose of this condition ?
What means âchecksâ in that context ?
I donât know it, but it seems like, if you have a trigger that might happen very often, depending on other circumstances, but you want to make sure that the rule doesnât run too often, you can set a condition that it wonât run more than e.g. once a minute.
I interpret it as âtriggeringâ, but perhaps itâs badly worded.
It is badly worded, but it is not âminimum interval between triggersâ.
A better description may be: âa minimum interval since the previous rule executionâ.
Say you have triggers that can occur as often as every second, but you only want to run your rule every 60 seconds at most, and not any more often than that. In this case you would set the minimum interval to 60 seconds and it will ignore triggers until 60 seconds have passed since the last rule run.
It is what I meant, you canât prevent the triggers, but you can prevent letting them trigger. That is, reject any triggers that occur before the defined interval has elapsed since the rule was last triggered.
Yes I understand what you meant and I knew you were going to come back with this statement! ![]()
Using the word âtriggerâ or âtriggeringâ or âtrigger*â may cause ambiguity / confusion, so itâs best to avoid it.
Iâve now rebased my working branch to latest main, and something has broken when serializing DSL rules. Does anybody have any idea what might cause this?
java.lang.IllegalStateException
at org.eclipse.xtext.serializer.sequencer.AbstractSyntacticSequencer.enterAssignedParserRuleCall(AbstractSyntacticSequencer.java:354)
at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:325)
at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:354)
at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:248)
at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:452)
at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:512)
at org.openhab.core.model.rule.serializer.AbstractRulesSemanticSequencer.sequence_Rule(AbstractRulesSemanticSequencer.java:587)
at org.openhab.core.model.rule.serializer.AbstractRulesSemanticSequencer.sequence(AbstractRulesSemanticSequencer.java:133)
at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:68)
at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:327)
at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:354)
at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:265)
at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:445)
at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:512)
at org.openhab.core.model.rule.serializer.AbstractRulesSemanticSequencer.sequence_RuleModel(AbstractRulesSemanticSequencer.java:567)
at org.openhab.core.model.rule.serializer.AbstractRulesSemanticSequencer.sequence(AbstractRulesSemanticSequencer.java:136)
at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:68)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:122)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:135)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:205)
at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:431)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1475)
at org.openhab.core.model.core.internal.ModelRepositoryImpl.generateFileFormat(ModelRepositoryImpl.java:283)
at org.openhab.core.model.rule.runtime.internal.converter.DslRuleConverter.generateFormat(DslRuleConverter.java:279)
at org.openhab.core.io.rest.core.internal.fileformat.FileFormatResource.createFileFormatForRules(FileFormatResource.java:495)
@Lolodomo Could it be because of the added tag, do I have no initialize something related to the tag before trying to serialize?
Sorry I donât know but I doubt that it is related to my small changes.
I donât know, I just know that something has changed, and I have no idea how to figure out what.
Iâm guessing that itâs most likely related to the tags, I had to redo the formatter because of that, because the IDs of most of the fields had changed.
edit: Something is missing here, the rule model only has getTags() but no setTags() method. I need setTags() to be able to set the tags when serializing.
edit2: I think I understand why thereâs no setTags(). In Xtextâs weird world, you donât set collections, you get them and add/remove/clear them. So, I have to use getTags().add().
I managed to run a validator, and it gives this error:
Validation issue: This expression is not allowed in this context, since it doesn't cause any side effects.
So, perhaps this is related to one of your changes @dpa-openhab?
Iâm creating a âplaceholder scriptâ that is only a string (so, it has âno side effectsâ). But, this used to work.
The above message was always shown, if the XBase code did nothing, and it supposed to be a warning, not an error. In the concrete case it is unclear which input creates that Validation issue and how to reproduce it. If I create a file openhab/scripts/a.script with content "abc" I see no such message in openHAB 5.2.0 build 5275.
You might have tweaked the default logging and for this reason you started seeing the message.
There is nothing wrong with the logging, I manually invoked the validator like this:
IResourceValidator validator = ((XtextResource) resource).getResourceServiceProvider().getResourceValidator();
List<Issue> issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
for (Issue issue : issues) {
logger.error("Validation issue: {}", issue.getMessage());
}
The reason I did that was to try to find the reason why serialization now fails with the exception shown a couple of posts above. If this is just a warning, and has always been there, itâs fine. I know why itâs there, I use a placeholder value for the script/action/then part when serializing, and then replaces that with the actual content after serialization. The placeholder is just a string, which has âno side effectsâ.
What I really need to know is why serialization of DSL now fails.
I plan to make another change in DSL Rule file syntax to allow 0 trigger. Easy to do
Regarding the visibility, what is exactly the purpose of making a rule hidden to UI? I could also add this visibility feature to DSL file syntax.
I have absolutely no idea, itâs something that has been there since the Eclipse days I believe. I did look into it somewhat once, and as far as I remember, there were some elaborate plans for using rules for âpartial processingâ or something that would make sense to be presented as separate rules. But, I just donât remember. Itâs there, and removing it would probably break something, so Iâve just âworked with itâ.
Since I donât know what it can be used for, I donât know if thereâs any point in implementing it in DSL.
But, unless I can figure out what broke DSL serialization, Iâm stuck with this whole project. I really have no idea where to look, the DSL model structure isnât very easy to debug.
In the JRuby helper library, it is used to create ephemeral internal supporting rules.
Regarding the serialization problem, I have gotten something to work now, but there is some work remaining to put it all together. Iâm not entirely sure exactly what caused it yet, but I think Iâm on my way to figuring it out.
edit: Tags are working too now:
rule "Self contained rule 1" [Test, Test2]
when
Item MySwitch received command
then
logInfo("test", "Global variable is not")
end
rule "Self contained rule 2" [Test, Test2]
when
Item MySwitch received command
then
logInfo("test", "Global variable is not in use")
end
It looks like the problem is solved. I have no idea exactly what triggered the problem, but it seems like it had to do with âhidden referencesâ in the model. I create a placeholder for the script/action/then part during serialization, and then replace that with the actual content after serialization. This is to preserve the formatting of the script, and frankly, because itâs simpler than having to parse it.
When I generated the placeholder, I did it in a âtemporary contextâ, and I then moved the generated âexpressionâ into the rule. This used to work, but no more, apparently, probably because it contained some âhidden referencesâ to the temporary context. Iâve now found a different way to generate the placeholder, that I think is âmore robustâ in that it shouldnât contain any âhidden referencesâ, and this made serialization start working again.
So, perhaps this had nothing to do with the rebasing, but that the previous process was simply âvolatileâ. Or, perhaps this has to do with changes to ScriptStandaloneSetup (which I used), but regardless, the ânew wayâ is cleaner and should be more robust.
Isnât it even dangerous to have rules that can be hidden to our administrator UI ?
If they are hidden, by the way, they canât benefit from any conversion feature in Main UI. So should not be annoying in practice if you reject these rules.
And what is the expert visibility?
I canât answer these questions, itâs been like this âsince the beginning of timeâ as far as I know. I donât think itâs âdangerousâ, we could easily make an option in the UI to show hidden and expert, so that they canât be âtruly hiddenâ.
From what I can see, these options have been there since the very introduction of automation:
I think I got tags working correctly now, Iâll have to study the changes to the triggers next:
rule "Self contained rule 1"
when
Item MySwitch received command
then
logInfo("test", "Global variable is not")
end
rule "Self contained rule 2"
when
Item MySwitch received command
then
logInfo("test", "Global variable is not in use")
end
rule "Managed DSL Test" [Testing, Tag2, tag3]
when
Item MySwitch received command
then
logInfo("testing", "Not really doing anything")
end