Help with rules - method undefined? <solved>

I’m yet another SmartThings refugee who is looking for something better. I’ve got a working OH2 beta running on an RPi3 and am loving it. It’s definitely more work to get everything set up, but the stability and flexibility is just amazing.

I’m not an experienced programmer and only know how to code in bits and pieces, and never with Java. I’m trying to write a basic rule that plays a sound on system startup and every minute. I thought maybe I needed to import a library, but I read that OH2 doesn’t need that and the editor suggested removing the import statement I tried. I’m sure there’s a simple answer, but I’m not sure where to look - I’ve looked around quite a bit.

My code:

rule "Test notification"
		System started or
	    	Time cron "* * * * * ?"

Error text in Eclipse editor:

`The method playSound(String) is undefined`

Here is the error in my log:

`03:49:00.010 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Test speech: An error occured during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.Audio.playSound(java.lang.String) on instance: null`

Unfortunately I’m not going to be of much help with your actual problem.

NOTE: The rules are not Java. They are a Domain Specific Language that bears the most resemblance to the Xtend programming language. You will not find a whole lot of help looking only at Java language resources.

This will execute the rule every second. You want “0 * * * * ?”

I’m not any help with the playSound problem though.

Thanks for your response!

Thanks, I figured that anyways since the syntax appears to be OH specific, but that’s good to know.

Yeah, I wrote the cron bit too quickly - I was shooting for once a minute. Thanks for setting me straight. :slight_smile:

Anyways, here is where I’ve come with my understanding of rules:

rule "Test rule 2"
    		Item Mode changed to 2
//		Mode is a number defined in default.items, 2 corresponds to Away
		sendCommand(DevLight, ON)
//		sendBroadcastNotification("test notification")
//		playSound("critical.mp3")
//		say("test notification")
//		increaseMasterVolume(10)
//	     	sendMail("", "Away", "Mode is now away")

The commented out sections are lines that don’t work - the Eclipse editor gives the same error that the corresponding method is undefined. Given that they cover different areas, I think I’m missing something other than a configuration of my sound card or something related. Also, I doubt Eclipse would even know that.

Once the offending lines are commented out, the rule runs fine.

I’m just copying and pasting from the OH rules page, so I’m truly puzzled why it’s not working. Again, I tried import statements but Eclipse flags them for removal and the docs say import is not required in OH2 anyways.

I’ll post this for the benefit of anyone who comes after me with a similar issue. @rlkoshak, I dug into this a bit more and found your reply to this thread:

I think my issue is two-pronged. First, I trusted the Eclipse Smart Home IDE error, but as you said on the other post, the editor is a work in progress and those errors should be ignored if the code is working. Once I got past that, I was able to get some of the commands to work properly, specifically the sendBroadcastNotification. No import statements were needed.

Likely, my issues with sound and speech are stemming from a setup issue, which obviously has nothing to do with rules. I’ll dig into that and post a new topic if I’m unsuccessful.

Update: Got it working thanks to this thread:

Glad you got it working!

1 Like