Rules Validation Issues

I don’t often edit inside the ESH editor as it often indicates potential errors, that seem to work fine in the actual processing of rules. Many times it seems it is minor indications of missing all the relevant items as they’ve been auto-discovers and thus not made available via local defined rules files.

None the less, the issue I’m finding is that upon startup in processing a particular file, there are errors of the following listed out. Unfortunately they don’t indicate like some others had, what lines and marks they’re at. But based on some of the info, I believe it is relevant to a particular timer section I’ve setup.

2017-06-30 23:02:01.427 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'automation.rules', using it anyway:
This expression is not allowed in this context, since it doesn't cause any side effects.
This expression is not allowed in this context, since it doesn't cause any side effects.
The field Tmp_automationRules.stateOutsideDogWalk refers to the missing type Object
The field Tmp_automationRules.stateOutsideDogWalk refers to the missing type Object
The field Tmp_automationRules.stateOutsideDogWalk refers to the missing type Object
This expression is not allowed in this context, since it doesn't cause any side effects.
This expression is not allowed in this context, since it doesn't cause any side effects.
This expression is not allowed in this context, since it doesn't cause any side effects.

Specifically, I have a rule setup that uses the stateOutsideDogWalk as a map for a bunch of stored item states. Basically, when we walk the dog, I have a scene trigger that will starts the following rule:

rule "Mudroom Switch Automation"
when
  Item mudroom_scene changed
then
{
  switch(mudroom_scene.state){
    case 2.1 : [break;]
    case 1.4 : { // 3 taps up
        logInfo("rules.automation", "Dog Walk - Dog Walk scene executed (3 Taps UP)")
      stateOutsideDogWalk = storeStates(g_outside_lights) // Storing outside light states
        logInfo("rules.automation", "Dog Walk - Storing outside light states")
      sendCommand(g_outside_lights, ON) // Turning all outside on
      sendCommand(mudroom_switch, ON)
        logInfo("rules.automation", "Dog Walk - Creating timer")
      timerDogWalk = createTimer(now.plusSeconds(600)) [| // Setting timer
        restoreStates(stateOutsideDogWalk) // Resetting lighting state
          logInfo("rules.automation", "Dog Walk - Timer ended, restoring lighting states")
        postUpdate(mudroom_scene, 2.1)
      ]
    }
    case 2.4 : { // 3 taps down
        logInfo("rules.automation", "Dog Walk - Dog Walk scene canceled (3 Taps DOWN)")
      timerDogWalk.cancel // Turning off the timer
      restoreStates(stateOutsideDogWalk) // Reverting light states to prior
        logInfo("rules.automation", "Dog Walk - Restoring lighting states")
      postUpdate(mudroom_scene, 2.1)
    }
  }
}
end

The relevant item definitions at the top of the rules file:

var Map stateOutsideDogWalk = null
var Timer timerDogWalk = null

I’m not sure I understand specifically the issue here. But it seems this would be the rule that is causing the issue. Checking in the ESH editor, this section does have some larger Red X marks next to it. And hovering on them displays the same message about “missing type Object”.

Any ideas on what could be the issue here? And/or how to validate WHERE the issues really lie, as the other errors in the initial launch concern me that I have something else I don’t even know about that could be incorrectly processing.

That error usually indicates you have a lambda or closure (i.e. code surrounded by []) and the last line doesn’t returna value. Often one can solve them by adding a true as the last line.

This has always been a problem. It is just now 2.1 is more explicit about such errors.

@rlkoshak - yes you are correct. I did find the pieces that were causing the repeat of the following line:

This expression is not allowed in this context, since it doesn’t cause any side effects.

This was actually due to the use of [break;] in my switch statements. I used this thinking from an efficiency standpoint, I’m best to meet a case I know will often happen, rather than have the code continue to evaluate the full switch, even if the resulting action is nothing. After reviewing XTend documentation a bit more, I understand that it doesn’t operate the same as it does in Java. So I removed those statements and just used {} instead.

Now I just need to try and understand what has changed about how MAPS worked from OH1.x. I pulled this usage from my last OH installation which ran on 1.x (over a year ago). It worked well, and it seems to still work to my understanding even with the error messages. The idea is, I like to use a switch to start a timer for walking the dog. It will store the state of the outside lights (so if the front porch lights are on for example, it remembers that). Then it will turn ALL the outside lights on. And finally, when the timer runs out (10 min), it will then restore the state of ALL the outside lights to what they were when the dog was taken out. It works BEAUTIFULLY, but I just would like to nab these last minor error messages.

First I would create the Map to start instead of initializing it to null. Use newHashMap.

I’ve no real experience with storeStates and restoreStates so I can’t comment on what, if anything has changed for those Actions.

So it seems I’ve reduced my error down to a single line now with the removal of setting the Map to a null value.

I’ve updated to the following at the top with my imports and variable declarations:

import java.util.Map
var Map stateOutsideDogWalk
var Timer timerDogWalk = null

This is leaving me with a single error on rules loading now:

2017-07-03 11:08:40.995 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model ‘automation.rules’, using it anyway:
Map is a raw type. References to generic type Map<K, V> should be parameterized

ALMOST THERE! :hushed:

That is really just a warning. If you want to get rid of it you need to provide the types for the key and the value on the map.

Again, I have almost no experience with storeStates, but I believe the following will work:

var Map<GenericItem, State> stateOutsideDogWalk

@steve1 - I think you were responding in the other thread, so I’ll pull the attention here. :slight_smile: - no the issue hasn’t been fully resolved yet. I’m stuck with this last piece.

From Rich’s recent indication, I was able to try putting in the parameterization he suggested, but this results in me getting the initial errors back again:

The field Tmp_automationRules.stateOutsideDogWalk refers to the missing type Object
The field Tmp_automationRules.stateOutsideDogWalk refers to the missing type Object
The field Tmp_automationRules.stateOutsideDogWalk refers to the missing type Object

And it occurs three times for each instance of the use of the stateOutsideDogWalk variable (2 x restore, 1 x store).

1 Like

I’m not an expert on XTend rules since I don’t use them. However, if the code works without the Map generic parameters, I’d leave them out.

Ok, you’ve peaked my interest … If you don’t use XTend rules, then how do you setup rules in OH? :thinking: Is there a secret I’ve been missing all along?! :slight_smile:

I use the JSR223 Scripting extensions to write rules using Jython (Python on the JVM). I’ve used Jython rules for years in OH1. The OH2 support is about 99% there but there’s still at least one important bug that needs to be fixed. You can also write rules in Javascript and Groovy (although I’ve seen a few OH2 Groovy issues reported recently).

Ahh, interesting. Ok, I didn’t realize there was an alternative. I’ve been living in ignorant bliss!! :stuck_out_tongue: I may take a look into that. Thanks for the info, I guess I’ll have to live with the single error I have for now. Thankfully everything still works as you indicated, guess if it ain’t broke don’t fix it. :slight_smile:

I have the following error, too, when using:
var Map<GenericItem, State> stateOutsideDogWalk

The field Tmp_automationRules.stateOutsideDogWalk refers to the missing type Object

Has anybody a solution using openHAB 2.5m2?