Xiaomi Cube Controller Rules - The source element must be contained in a resource

Hi there,

I’m using a bunch of Xiaomi devices on my openHab 2.4 (Raspi 3).

Now I’wanted to connect the Cube Controller. But I get a lot of error messages for my rule (code taken from OH documentation:

rule "Xiaomi Cube Controller"
when
    Channel "mihome:sensor_cube:XXXXXXX:action" triggered
then
    var actionName = receivedEvent.getEvent()
    switch(actionName) {
        case "MOVE": {
            logInfo("RULE", "--> Cube: move")
        }
        case "ROTATE_RIGHT": {
            logInfo("RULE", "--> Cube: rotate right")
        }
        case "ROTATE_LEFT": {
            logInfo("RULE", "--> Cube: rotate left")
        }
        case "FLIP90": {
            logInfo("RULE", "--> Cube: flip 90")
        }
        case "FLIP180": {
            logInfo("RULE", "--> Cube: flip 180")
        }
        case "TAP_TWICE": {
            logInfo("RULE", "--> Cube: tap twice")
        }
        case "SHAKE_AIR": {
            logInfo("RULE", "--> Cube: shake air")
        }
        case "FREE_FALL": {
            logInfo("RULE", "--> Cube: free fall")
        }
        case "ALERT": {
            logInfo("RULE", "--> Cube: alert")
        }
    }
end
2019-03-08 20:18:19.111 [ERROR] [xtext.xbase.jvmmodel.JvmTypesBuilder] - The source element must be contained in a resource
java.lang.IllegalArgumentException: The source element must be contained in a resource
	at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.isValidSource(JvmTypesBuilder.java:654) ~[?:?]
	at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.associate(JvmTypesBuilder.java:645) ~[?:?]
	at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.toParameter(JvmTypesBuilder.java:836) ~[?:?]
	at org.eclipse.smarthome.model.rule.jvmmodel.RulesJvmModelInferrer.lambda$10(RulesJvmModelInferrer.java:241) ~[?:?]
	at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.initializeSafely(JvmTypesBuilder.java:211) ~[?:?]
	at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.toMethod(JvmTypesBuilder.java:692) ~[?:?]
	at org.eclipse.smarthome.model.rule.jvmmodel.RulesJvmModelInferrer.lambda$9(RulesJvmModelInferrer.java:252) ~[?:?]
	at org.eclipse.xtext.xbase.lib.internal.FunctionDelegate.apply(FunctionDelegate.java:42) ~[?:?]
	at com.google.common.collect.Lists$TransformingRandomAccessList$1.transform(Lists.java:617) ~[?:?]
	at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48) ~[?:?]
	at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.operator_add(JvmTypesBuilder.java:137) ~[?:?]
	at org.eclipse.smarthome.model.rule.jvmmodel.RulesJvmModelInferrer.lambda$0(RulesJvmModelInferrer.java:255) ~[?:?]
	at org.eclipse.xtext.xbase.jvmmodel.JvmModelAssociator$1.run(JvmModelAssociator.java:397) ~[?:?]
	at org.eclipse.xtext.xbase.jvmmodel.JvmModelAssociator.installDerivedState(JvmModelAssociator.java:407) ~[?:?]
	at org.eclipse.xtext.resource.DerivedStateAwareResource.installDerivedState(DerivedStateAwareResource.java:243) ~[?:?]
	at org.eclipse.xtext.xbase.resource.BatchLinkableResource.getContents(BatchLinkableResource.java:148) ~[?:?]
	at org.eclipse.xtext.ide.server.ProjectManager.getResource(ProjectManager.java:173) ~[?:?]
	at org.eclipse.xtext.ide.server.WorkspaceManager.doRead(WorkspaceManager.java:276) ~[?:?]
	at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$documentSymbol$35(LanguageServerImpl.java:609) ~[?:?]
	at org.eclipse.xtext.ide.server.concurrent.ReadRequest.lambda$run$0(ReadRequest.java:37) ~[?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]

What’s wrong with the rule?

Is that the actual rule you are using? The string of x’s in the channel ID need to be the serial of your cube.

Thanks for your reply - I’m aware or it :wink:

In all the years I’ve been working with OH I’ve never seen that error before. The stack trace looks like it’s coming from the Rule somehow. Add a line to log out first thing when the Rule is entered.

Then add a line to log out actionName.

I’m not certain that actionName is a String so you might need to call toString in the switch statement in order for your case statements to work.