[Solved] Use a string item state as a name for another item

hi, can u help me guys… my items and rules are:

my items
Switch LivingRoom_AirCon        "Air Conditioner" 
String ALARM3_DEVICE            "Device"
Switch ALARM3_COMMAND           "Command"

my rule:
rule "LR AC"
	when
		Item LivingRoom_AirCon changed
	then
		if (LivingRoom_AirCon.state == ON)
		{
			RM2.sendCommand("LR_AC_ON")
}
end

rule "ALARM test"
when
    Time cron "0 * * * * ?"
then
    sendCommand(ALARM3_DEVICE.state.toString , ALARM3_COMMAND.state)
	
end
  • ALARM3_DEVICE has a selection of [LivingRoom_AirCon=“LivingRoom AC”]
  • ALARM3_COMMAND has a selection of [ON=“ON”, OFF=“OFF”]

im getting below error in the log:

2018-03-26 12:15:00.006 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'ALARM testss': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(java.lang.String,java.lang.String) on instance: null

what code be wrong in this line:
sendCommand(ALARM3_DEVICE.state.toString , ALARM3_COMMAND.state)

thanks
Chaaban

I think ALARM3_DEVICE.state.toString is “LivingRoom AC”. And this causes the error. An item with this name does not exist.

hi, i tried to use only “ALARM3_DEVICE.state” also,im getting error:

2018-03-26 13:02:00.005 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'ALARM testss': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.Number) on instance: null

Let’s find out the value…

rule "ALARM test"
when
    Time cron "0 * * * * ?"
then
    logInfo("TEST", ALARM3_DEVICE.state.toString)
    logInfo("TEST", ALARM3_COMMAND.state.toString)
    sendCommand(ALARM3_DEVICE.state.toString , ALARM3_COMMAND.state)
end

What does the log show?

2018-03-26 13:25:07.470 [INFO ] [.eclipse.smarthome.model.script.TEST] - LivingRoom_AirCon
2018-03-26 13:25:07.471 [INFO ] [.eclipse.smarthome.model.script.TEST] - ON
2018-03-26 13:25:07.472 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'ALARM testss': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(java.lang.String,java.lang.String) on instance: null

you understood it wrong.

In clear text:
sendCommand(ALARM3_DEVICE.state.toString , ALARM3_COMMAND.state)

is translated via rule to:
sendCommand(“LivingRoom AC” , “ON”)

But there is no item with name “LivingRoom AC”

Good!

rule "ALARM test"
when
    Time cron "0 * * * * ?"
then
    logInfo("TEST", ALARM3_DEVICE.state.toString)
    logInfo("TEST", ALARM3_COMMAND.state.toString)
    sendCommand(ALARM3_DEVICE.state.toString , ALARM3_COMMAND.state.toString)
end

u want me to try this?

Should work

u r king… thanks… it worked

the sendCommand action needs Strings
All you had to do in convert the item states with .toString in both arguments of the action

noted…

Can you mark the thread as solved, please?
Thank you

i never did this before… shall i include solved in the title?