Is it a bug?

Hi, i can use sendCommand(i, ON) (documentation), but this command gives error:

An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.actions.BusEvent.sendCommand(java.lang.String,java.lang.String) on instance: null

If i use sendCommand(i, “ON”) with quotation marks - it works ok

In the documentation link you posted, I believe this is the answer:

image

Why not use the recommended MyItem.sendcommand(<new_state>) syntax?

Because i need to construct Item name in rule:

val i = triggeringItemName.split("_").get(0) + "_OnSet"
	sendCommand(i, "ON")

This is one of the reasons why it’s recommended in Rules DSL where ever possible to always use the ItemName.sendCommand() method over the sendCommand() action.

However, in this case you can’t easily do that, but then it’s important to understand that the sendCommand() action only and always takes two Strings as arguments, as Russ pointed out.

Where it gets tricky is that sometimes Rules DSL is good at recognizing this and converting the argument to a String for you. Other times, it falls flat on its face. So to practice some defensive programming, always explicitly use or convert the arguments to a String and you’ll avoid this problem.