Trigger Item from rule variable

Hey there =)

I am trying to send an Item a Command. The name of the item is dynamic and therefore set via a variable “item”. The declaration looks like this:

var item = “”
[…]
item = “Steckdosen_Ventilator”

The setting of the variable works; tested via logInfo:

23:36:35 [INFO] [org.eclipse.smarthome.model.script.] - Steckdosen_Ventilator

I am trying to send this item an ON or OFF command. However I can’t get that to work. I tried

  • item.state.sendCommand(ON) AND
    item.state.toString.sendCommand(ON)
    Error: Error during the execution of rule ‘Testrule’: ‘state’ is not a member of ‘java.lang.String’;

  • item.toString.sendCommand(ON) AND
    item.sendCommand(ON)
    Error: Error during the execution of rule ‘Testrule’: 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

Can someone help my on how the syntax is? Thanks in advance.

Felix

Well, as you define it, item is a String. It’s not an Item. String only know how to do String things so obviously have no idea how to sendCommand or postUpdate. But, as documented here there is a sendCommand(itemName, state_string) Action you can call.

1 Like