[SOLVED] Dimmer an item with voice command

Hello,
I wanna ask you how to dim a Dimmer item with the voice command.
I’m able to send ON - OFF command to a LIFX bulb via Habdroid, but I didn’t find any documentation about a rule to dim it at th % I want.

Example:
“Living light at 40 percent”

Thank you in advance!
Muplex

Ok,
I try to implement that very complicate rule by translating it buy I end up with

[ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Voice control': An error occured during the script execution: The name '<XFeatureCallImplCustom> != <XNullLiteralImplCustom>' cannot be resolved to an item or type.

Any suggestion???

I’m only interessed to undersund how to extract the percentage, not the whole rule of the example

As w e don’t know how you changed the rule it is difficult to guess. Could be a simple as a spelling error.

That’s my translation in Italian of the Example:

rule "Voice control"
when
	Item VoiceCommand received command
then
	var String command = VoiceCommand.state.toString.toLowerCase
	logInfo("Voice.Rec","VoiceCommand received "+command)
	var State newState = null

// find new state, toggle otherwise (if possible)
if (command.contains("gradi") || command.contains("percento") || command.contains("attenua")) {
	
	// extract new state (find the digits in the string)
	var java.util.regex.Pattern p = java.util.regex.Pattern::compile(".* ([0-9]+) (gradi|percento).*")
	var Matcher m = p.matcher(command)
	if (m.matches()) {
		newState = new StringType(m.group(1).trim())
	}
}

else if (command.contains("spegni")|| command.contains("off") || command.contains("stop") || command.contains("ferma")) {
	newState = OFF
} else if (command.contains("accendi") || command.contains("on")|| command.contains("start") || command.contains("inizia")) {
	newState = ON
} else if (command.contains("diminuisci") || command.contains("giù") || command.contains("meno") || command.contains("abbassa")) {
	newState = DOWN
} else if (command.contains("aumenta") || command.contains("su") || command.contains("più") || command.contains("alza")) {
	newState = UP
} else if (command.contains("rosso")) {
	newState = new HSBType(new Color(255, 0, 0));
} else if (command.contains("blu")) {
	newState = new HSBType(new Color(0, 0, 255));
} else if (command.contains("bianco")) {
	newState = new HSBType(new Color(255, 255, 255));
}

// find room
var String room = null
var String roomItemPart = null
var String roomArticle="in"
if (command.contains("soggiorno")) {
	room = "Soggiorno"
	roomItemPart = "Int_Soggiorno"
} else if (command.contains("camera")) {
	room = "Camera"
	roomItemPart = "Int_Camera"
} else if (command.contains("bagno")) {
	room = "Bagno"
	roomItemPart = "Int_Bagno"
} else if (command.contains("cucina")) {
	room = "Cucina"
	roomItemPart = "Int_Cunica"
}

	// purpose
var String itemType=null
var String itemSubType=""
var String reply=""
if (command.contains("luce") || command.contains("luci")) {
	itemType = "Accendi"
	if (newState instanceof HSBType) {
		if (room=="Soggiorno") {
			itemSubType="LIFX1"
		} 
	}
} 

/* else if (command.contains("rolladen") || command.contains("jalousien")) {
	itemType = "Shutter"
	if (newState instanceof StringType) {
		itemType = "Shutter_Pos"
	}
	if (room=="Wohnzimmer") {
		// Unterscheiden zwischen Tür/Fenster
		if (command.contains("tür")) {
			itemSubType = "_Door"
		} else if (command.contains("fenster")) {
			itemSubType = "_Window"
		}
	}
} */

else if (command.contains("temperatura")) {
	itemType = "Temperatura"
	itemSubType = "_Target"
	reply = "Ok, Temperatura "+roomArticle+" "+room+" a "+newState+" Gradi centigradi"
}

if (itemType!=null && (roomItemPart!=null || command.contains("tutto")) && newState!=null) {
	logInfo("Voice.Rec", "sending "+newState+" to "+itemType+"_"+roomItemPart+itemSubType)
	if (command.contains("tutto")) {
		if (roomItemPart==null)
			roomItemPart=""
		val String itemName = itemType+"_"+roomItemPart+itemSubType
		val State finalState = newState
		logInfo("Voice.Rec","searching for  *"+itemName+"* items")
		All?.allMembers.filter(s | s.name.contains(itemName) && s.acceptedDataTypes.contains(finalState.class)).forEach[item|
			logInfo("Voice.Rec","item  "+item+" found")
			sendCommand(item,finalState.toString)
		]	
	} else {
		sendCommand(itemType+"_"+roomItemPart+itemSubType,newState.toString)
	}
	if (reply!="")
			say(reply)
	}
end

The clue we get from that is a failure in “something != null” somewhere in your rule.

I think that is the only line with != , so one of those things has a problem.
I would logInfo() each variable just before that line to see what is going on.

Rossko,
I have another point maybe can help to undestand the problem. Indeed the error seems to be related to the var State newState type

at the beginning of the code

rule "Voice control"
when
	Item VoiceCommand received command
then
	var String command = VoiceCommand.state.toString.toLowerCase
	logInfo("Voice.Rec","VoiceCommand received "+command)
	var State newState = null

The smartHome designer give me an allert on the left column
State cannot be resolved as a type

I try with ctrl+space but i didn’t find the correct java State type

my global imports are :

// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*
import org.openhab.core.types.*
import org.openhab.core.items.*
import java.util.regex.Matcher
import java.util.regex.Pattern

Can you help me to fix it ?

Is there any test can I perform to try to solve the rules problem in your opinion guys?

Rossko57, can you help me out?

I reply the solution I found for the people that could have my same problem in the future.

the var State VarName problem is linked to the global IMPORTS!!!

// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
bla bla bla

I REPLACE

org.openhab with org.eclipse.smarthome

And The rule works!!!