[SOLVED] Openhab2 .rules file not working

i created rule file but it is not executed ,no trace in logs
import org.openhab.model.script.actions.*
import org.openhab.core.library.types.*
import java.util.*
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.core.types.Command
import org.openhab.core.types.*
import org.openhab.core.items.GenericItem
import java.util.regex.Matcher
import java.util.regex.Pattern

rule “voicecommand”

when
Item VoiceCommand received command
then
var String command = VoiceCommand.state.toString.toLowerCase
logInfo(“Voice.Rec”,“VoiceCommand received”+command)

if (command.contains("turn on light“)
{
sendCommand(light,ON)
}

else if (command.contains("turn off light“)
{
sendCommand(light,OFF)
}

end

rules in paper ui works fine but rules saved in home.rules is not executed
i tried most of the examples
anyone knows the reason replay me

Try 6 things:

  • do not import anything at the start (it’s not needed anymore with OH2)
  • use <item>.sendCommand() (instead of sendCommand(item,command)
  • use another variable name for the string (not command)
  • fix your quote marks (" vs “)
  • fix your parenthesis in the if and else if statements
  • use triple ticks (`) to put the rule content in and use idents (easier to read)
rule "voicecommand"
when
	Item VoiceCommand received command
then
	var String VoiceInput = VoiceCommand.state.toString.toLowerCase
	logInfo("Voice.Rec","VoiceCommand received"+VoiceInput)
	if (VoiceInput.contains("turn on light"))	{
		light.sendCommand(ON)
	}
	else if (VoiceInput.contains("turn off light")) {
		light.sendCommand(OFF)
	}
end

or use: ESHD (v0.80) :slight_smile: http://docs.openhab.org/installation/designer.html

Tq. I solved by uninstalling the bindings
Now it works fine