Habmin Rules: no viable alternative at input "then"

Hey to all,

I got a problem with the configuration of rules, i got always the following error in the logfiles:

Preformatted text2018-02-23 17:29:22.578 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘(3)_funktionsstecker_anschalten_bei_harmony_szene_poweron.rules’ has errors, therefore ignoring it: [13,1]: no viable alternative at input ‘then’

2018-02-23 17:29:22.819 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘(3)_funktionsstecker_anschalten_bei_harmony_szene_poweron.rules’ has errors, therefore ignoring it: [13,1]: no viable alternative at input ‘then’Preformatted text

The source code for the rule looks like that:

// This rule file is autogenerated by HABmin.
// Any changes made manually to this file will be overwritten next time HABmin rules are saved.

// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

// Global Variables

rule "Funktionsstecker anschalten bei Harmony Szene PowerOn"
when
then
  if ((HarmonyHubWohnzimmer_CurrentActivity.state != PowerOff)) {
    postUpdate(FunktionssteckerTV_Switch, ON)

    postUpdate(FunktionssteckerBeamer_Switch, ON)
  }
end

I dont know where there is an issue with that rule?
there is no text in the “when” definition, only in the “then” definition. is that the problem?!
see attached an image of my rule from the designer of habmin.

rule

rule|690x276

What version of OH are you running?

Regardless, yes, that is a problem. You have to have at least one trigger in a Rule.

I’m not certain that HABmin’s Rules generator is fully working in OH 2.x. The fact that it is importing things that are not valid for OH 2.x implies you are either running OH 1.8 or the Rules generator has not been updated for OH 2.x.

hey,

thanks for the fast reply!

Im running on the newest build openHAB 2.2.0 Release.

Meaning that there are issues with using habmin with the newest version of openhab, but the thing is, that this is a graphical rule designer which should be much more easy to use than the normal one to code the rules…
is there another graphical rule designer to use with openhab 2?

I honestly thought that chris had disabled that as it has not kept up with the changes in OH.

You can look at the Experimental Rules Engine but for the default Rules I think writing the code manually is the only viable approach.

Totally agree. The gap between the richness of (and gaps in…) the OHx event bus and the rules language formalities (either the rules DSL or the jsr223 alternatives) make it VERY difficult to do GUI rules for other than semi-trivial cases. OH is an event-bus — it can coordinate (on good days ) widely-disparate device events. Unless you are doing de-minimus things, you are going to have to go to text rules (at least for now).

ok thanks for your answers.

the experimental rule engine is for very easy rules, but when you want to some more complex ones with dependencies links, its not possible.

bad luck that the habmin engine does not work anymore, i set a lot of hope in this tool

I have used the HABmin rule designer for a couple simple OH 2 rules and found it to work fairly well.

I believe the issue you are having is caused by the type of operations used in the condition of your If block. The red operations deal with local rule variables. The purple operations deal with items.

  • Change the “HarmonyHubWohnzimmer_CurrentActivity” part of the If condition to the use the Get Item <item> operation
    • The rule generator will automatically add the trigger Item HarmonyHubWohnzimmer_CurrentActivity changed to the rule
  • If the “PowerOff” part is meant to be treated as the actual text that will be in the item’s state, then change it to the literal string operator (it is green).

Hi!

Thansk for the reply; i changed the rule accordingly, no i get the following errors in the logfile

2018-02-25 08:45:36.200 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model '(1)_funktionsstecker_anschalten_bei_harmony_szene_poweron.rules' has errors, therefore ignoring it: [10,5]: no viable alternative at input 'null'

[11,5]: no viable alternative at input 'null'

2018-02-25 08:45:36.360 [ERROR] [xt.xbase.jvmmodel.JvmModelAssociator] - Error calling inferrer

java.lang.NullPointerException: null

	at org.eclipse.smarthome.model.rule.jvmmodel.RulesJvmModelInferrer.lambda$6(RulesJvmModelInferrer.java:139) ~[?:?]

	at org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(ObjectExtensions.java:139) ~[?:?]

	at org.eclipse.smarthome.model.rule.jvmmodel.RulesJvmModelInferrer.lambda$1(RulesJvmModelInferrer.java:145) ~[?:?]

	at org.eclipse.xtext.xbase.lib.internal.FunctionDelegate.apply(FunctionDelegate.java:42) ~[?:?]

	at com.google.common.collect.Lists$TransformingRandomAccessList$1.transform(Lists.java:617) ~[23:com.google.guava:18.0.0]

	at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48) ~[23:com.google.guava:18.0.0]

	at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.operator_add(JvmTypesBuilder.java:137) ~[164:org.eclipse.xtext.xbase:2.12.0.v20170519-0752]

	at org.eclipse.smarthome.model.rule.jvmmodel.RulesJvmModelInferrer.lambda$0(RulesJvmModelInferrer.java:148) ~[?:?]

	at org.eclipse.xtext.xbase.jvmmodel.JvmModelAssociator$1.run(JvmModelAssociator.java:397) [164:org.eclipse.xtext.xbase:2.12.0.v20170519-0752]

	at org.eclipse.xtext.xbase.jvmmodel.JvmModelAssociator.installDerivedState(JvmModelAssociator.java:407) [164:org.eclipse.xtext.xbase:2.12.0.v20170519-0752]

	at org.eclipse.xtext.resource.DerivedStateAwareResource.installDerivedState(DerivedStateAwareResource.java:242) [160:org.eclipse.xtext:2.12.0.v20170518-0959]

	at org.eclipse.xtext.xbase.resource.BatchLinkableResource.getContents(BatchLinkableResource.java:148) [164:org.eclipse.xtext.xbase:2.12.0.v20170519-0752]

	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.validateModel(ModelRepositoryImpl.java:279) [134:org.eclipse.smarthome.model.core:0.10.0.b1]

	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:97) [134:org.eclipse.smarthome.model.core:0.10.0.b1]

	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:247) [134:org.eclipse.smarthome.model.core:0.10.0.b1]

	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:311) [134:org.eclipse.smarthome.model.core:0.10.0.b1]

	at org.eclipse.smarthome.core.service.WatchQueueReader.run(WatchQueueReader.java:209) [109:org.eclipse.smarthome.core:0.10.0.b1]

	at java.lang.Thread.run(Thread.java:748) [?:?]

2018-02-25 08:45:36.410 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model '(1)_funktionsstecker_anschalten_bei_harmony_szene_poweron.rules' has errors, therefore ignoring it: [10,5]: no viable alternative at input 'null'

[11,5]: no viable alternative at input 'null'

and the code of the rule looks like:

// This rule file is autogenerated by HABmin.
// Any changes made manually to this file will be overwritten next time HABmin rules are saved.

// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

// Global Variables
var null FunktionssteckerBeamer_Switch = 0
var null FunktionssteckerTV_Switch = 0

rule "Funktionsstecker anschalten bei Harmony Szene PowerOn"
when
    Item HarmonyHubWohnzimmer_CurrentActivity changed
then
  if ((HarmonyHubWohnzimmer_CurrentActivity.state != "PowerOff")) {
    FunktionssteckerBeamer_Switch = ON

    FunktionssteckerTV_Switch = ON
  }
end



Any ideas?

The condition of the If block looks good now. The issue is the “do” section. They are local variable operations instead of item based operations (they were item operations in your original post).
You need to change the operations in the “do” section to the purple Set Item <item> to <value> operations.

It can be a little confusing when you go to select the operation to insert it because there are two of them in the list that look almost identical.

  • One is listed as Set Item <Item> to <value>
    • This version will use postUpdate on the item which only updates openHAB’s internal state of the item
  • The other is listed as Set Item <command> to <value>
    • This version will use sendCommand on the item which will issue the command to the physical device if one exists
    • I believe this is the version you should use for you rule

you are great, honestly!!

everything works no like a a charm, thank you very much