Voice Command

Hi All,

I am trying to follow the Wiki link on voice commands but can’t get it to function at all.

I have several items I want to control by voice, one such item is called “CL_Toggle”. Here’s a simplified version of my rule file.

import org.openhab.model.script.actions.*
import org.openhab.core.library.types.*
import java.util.*

rule VoiceEngine
	Item VoiceCommand received command
	var State newstate = null
	var String typename = null
	var String thingname = null

	newstate = ON
	thingname = "CL"
	typename = "Toggle"

	logError("Voice.Send", "VoiceCommand: Set " + thingname + "_" + typename + " to " + newstate.toString)

	sendCommand(thingname + "_" + typename,newstate)

This produces the following error:

Error during the execution of rule 'VoiceEngine': The name '<XFeatureCallImplCustom>.toString' cannot be resolved to an item or type.

or on deleting that particular line

Error during the execution of rule 'VoiceEngine': Could not invoke method: org.openhab.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,org.openhab.core.types.Command) on instance: null

Have I missed something? Using a RPi 2 with OpenHAB v1.8.0

VoiceEngine should be in quotes:

rule "VoiceEngine"

As an aside, in this specific example your sendCommand probably won’t work as you expect, as your concatenation will end up with two underscores.

You only need to have your rule title in quotes if it contains a space, “VoiceEngine” and VoiceEngine are the same.

Didn’t mean to add the extra “_” edited it out. Issue still happens.

What happens if you get rid of the toString?

2016-01-15 15:52:34.340 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'VoiceEngine': Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null

Which is strange, because newstate is definitely set. thingname + “_” + typename evaluates to CL_Toggle as it should.

If you comment on the log line does it send the command properly? The rest looks OK to me, I’m wondering if the string concatenation is being picky.

Unfortunately not, I’ve said what the error is when I remove that particular line in the first post.

I’ve got it working to some extent by using String throughout. Most types seem to readily convert to string so states of HSBType etc just need a .toString.

Spent a bit of time thinking about this, could it possibly be because you’re sending it a State when it expects a Command?

I thought they should be the same, but on reading documentation sendCommand() defaults to “String ItemName, String Command String” so I don’t have much trouble with this on using strings.