Sadly this gives me the same error:
if (itemType!=null && (roomItemPart!=null || command.contains("alle")) && newState!=null) {
logInfo("rule", "60 sending "+newState+" to "+itemType+"_"+roomItemPart+itemSubType)
if (command.contains("alle")) {
logInfo("rule", "62 command contains alle")
if (roomItemPart==null)
roomItemPart=""
val String itemName = itemType+"_"+roomItemPart+itemSubType
val State finalState = newState
logInfo("rules","70 searching for "+itemName)
gVC?.allMembers.filter(s | s.name.contains(itemName) && s.acceptedDataTypes.contains(finalState.class)).forEach[item|
logInfo("rules","72 item "+item.name+" found. Sending command "+finalState)
item.sendCommand(finalState)
]
} else {
logInfo("rules", "77 Command om te zenden "+itemType+"_"+roomItemPart+itemSubType+", "+newState)
sendCommand(itemType+"_"+roomItemPart+itemSubType, newState.toString)
}
}
This is the output:
2016-03-02 19:35:11.203 [INFO ] [org.openhab.model.script.rule ] - 60 sending ON to Lamp_BG_Woonkamer
2016-03-02 19:35:11.206 [INFO ] [org.openhab.model.script.rule ] - 62 command contains alle
2016-03-02 19:35:11.216 [INFO ] [org.openhab.model.script.rules] - 70 searching for Lamp_BG_Woonkamer
2016-03-02 19:35:11.249 [INFO ] [org.openhab.model.script.rules] - 72 item Lamp_BG_Woonkamer_Plafond found. Sending command ON
2016-03-02 19:35:11.250 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Voice control': Could not invoke method: org.openhab.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,java.lang.Number) on instance: null
Same:
if (itemType!=null && (roomItemPart!=null || command.contains("alle")) && newState!=null) {
logInfo("rule", "60 sending "+newState+" to "+itemType+"_"+roomItemPart+itemSubType)
if (command.contains("alle")) {
logInfo("rule", "62 command contains alle")
if (roomItemPart==null)
roomItemPart=""
val String itemName = itemType+"_"+roomItemPart+itemSubType
val State finalState = newState
logInfo("rules","70 searching for "+itemName)
gVC?.allMembers.filter(s | s.name.contains(itemName) && s.acceptedDataTypes.contains(finalState.class)).forEach[item|
logInfo("rules","72 item "+item.name+" found. Sending command "+finalState)
sendCommand(item.name, finalState.toString)
]
} else {
logInfo("rules", "77 Command om te zenden "+itemType+"_"+roomItemPart+itemSubType+", "+newState)
sendCommand(itemType+"_"+roomItemPart+itemSubType, newState.toString)
}
}
Same error.
2016-03-02 19:41:19.903 [INFO ] [org.openhab.model.script.rule ] - 60 sending OFF to Lamp_BG_Woonkamer
2016-03-02 19:41:19.905 [INFO ] [org.openhab.model.script.rule ] - 62 command contains alle
2016-03-02 19:41:19.919 [INFO ] [org.openhab.model.script.rules] - 70 searching for Lamp_BG_Woonkamer
2016-03-02 19:41:19.969 [INFO ] [org.openhab.model.script.rules] - 72 item Lamp_BG_Woonkamer_Plafond found. Sending command OFF
2016-03-02 19:41:19.969 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Voice control': Could not invoke method: org.openhab.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,java.lang.Number) on instance: null
When I replace the item variable to a written Item name it does not give me errors. What I tried:
if (itemType!=null && (roomItemPart!=null || command.contains("alle")) && newState!=null) {
logInfo("rule", "60 sending "+newState+" to "+itemType+"_"+roomItemPart+itemSubType)
if (command.contains("alle")) {
logInfo("rule", "62 command contains alle")
if (roomItemPart==null)
roomItemPart=""
val String itemName = itemType+"_"+roomItemPart+itemSubType
val State finalState = newState
logInfo("rules","70 searching for "+itemName)
gVC?.allMembers.filter(s | s.name.contains(itemName) && s.acceptedDataTypes.contains(finalState.class)).forEach[item|
logInfo("rules","72 item "+item.name+" found. Sending command "+finalState)
sendCommand(Lamp_BG_Woonkamer_Plafond, finalState.toString)
]
} else {
logInfo("rules", "77 Command om te zenden "+itemType+"_"+roomItemPart+itemSubType+", "+newState)
sendCommand(itemType+"_"+roomItemPart+itemSubType, newState.toString)
}
}
This runs fine and shows in the log below that the .filter method works fine. Only now it switches a hard coded Item.
2016-03-02 19:31:59.548 [INFO ] [org.openhab.model.script.rule ] - 60 sending OFF to Lamp_BG_Woonkamer
2016-03-02 19:31:59.550 [INFO ] [org.openhab.model.script.rule ] - 62 command contains alle
2016-03-02 19:31:59.559 [INFO ] [org.openhab.model.script.rules] - 70 searching for Lamp_BG_Woonkamer
2016-03-02 19:31:59.595 [INFO ] [org.openhab.model.script.rules] - 72 item Lamp_BG_Woonkamer_Plafond found. Sending command OFF
2016-03-02 19:31:59.601 [INFO ] [org.openhab.model.script.rules] - 72 item Lamp_BG_Woonkamer_Bank found. Sending command OFF
Above gives me the impression that something funky is going on with the variable “item” that is produced by the .filter method. What can be the problem?
Am I missing some import maybe?
Below states what is imported at the beginning of the file.
import org.openhab.core.types.*
import org.openhab.model.script.actions.*
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
The error message “Could not invoke method: […].sendCommand(org.openhab.core.items.Item,java.lang.Number) on instance: null” makes me think that the sendCommand method sees the item variable as null. But the logInfo statement can output the item variable. How can this be?
I don’t get it, other than that I am missing some import. Can it be confirmed that I have imported everything needed?
(Sorry for the lengthy post.)