[SOLVED] Why does my rule error?

I’m having an issue with the rule below, I get the below error in the openhab.org logfile. Have I done something stupid or am I just missing something.

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Arriving Home From Work’: An error occurred during the script execution: Couldn’t invoke ‘assignValueTo’ for feature JvmVoid: (eProxyURI: Kitchen.rules#|::

rule "Arriving Home From Work"
	Item Kitchen_ZD2102_Sensor changed or
	Item Kitchen_SP3102_Motion changed
	if(now.getHourOfDay < 15) return;
	if(Kitchen_ZD2102_Sensor.state != OPEN || Kitchen_SP3102_Motion.state != ON) return;
	logInfo("org.openhab","Kitchen: The Back Door is {} and the Motion Sensor is {}", Kitchen_ZD2102_Sensor.state, Kitchen_SP3102_Motion.state)
	if(now.getHourOfDay < 18) {
		announcement = "Good Afternoon, Welcome back home. It looks like " + Sonarr.state + " recently."
	} else {
		announcement = "Good Evening, Welcome home. I thought you might like to know that " + Sonarr.state + " recently."

Thanks for advice.



You don’t say what else is happening, such as when do you get this error: do you see any of the log statements in your log file before the error occurs, or are there no log statements.
A quick guess: did you declare announcement elsewhere in your rule file? Otherwise you will need to do so.

Yes I had used the variable announcement in another rule within the same file. So added this to the very top of the file, above all of the rules. This has resolved my issue, although I suspect it’s not the best way to do it.

var announcement = ""

Thanks @lipp_markus for the quick reply.

@Maximo variables are global in scope only for each file and do not cross into other rule files. You can declare local for each rule too if you prefer, their scope will then be restricted to the specific rule (add it after the ‘then’)

1 Like

Thanks for the heads up. Learning more each time.