Hello, I’m having trouble getting a FOR loop to run when using variables, I have assured all my variables are ints and tried importing different libraries and had no luck
Rule:
import org.eclipse.xtext.xbase.lib.IntegerExtensions.operator_lessThan
rule "backDoorObjectFound"
when
Item Zoneminder_ObjectsFound changed
then
// Raw JSON
//var rawObjects = Zoneminder_ObjectsFound.state.toString
// Sample data
var rawObjects = '{"state":"alarm","eventtype":"event_start","detection":[{"label":"chair","type":"object","box":[281,38,465,460],"confidence":"90.33%"},{"label":"chair","type":"object","box":[-4,26,342,458],"confidence":"65.65%"}],"name":"patioDoors:(12836) [a] detected:chair:90% Forced Web","eventid":"12836","monitor":"2","hookvalue":"0"}'
//logInfo("CDS", rawObjects)
// Get num of objects detected
var int objects = transform("JSONPATH", "$.detection.length()", rawObjects) //works
//var int objects = 2 // Some reason wont work
logInfo("CDS-len", objects) //works
var int i
var String key
var String value
for (i=1; i < objects ; i++) { //Error here
var fitleredObjects = transform("JSONPATH", "$.detection[i].label", rawObjects)
logInfo("CDS", fitleredObjects)
}
//logInfo("CDS-len", )
//logInfo("CDS-len", transform("JSONPATH", "$.detection.length", rawObjects))
//var fitleredObjects = transform("JSONPATH", "$.detection[0].label", rawObjects)
//var fitleredObjects = transform("JSONPATH", "$.*", rawObjects)
//logInfo("CDS", fitleredObjects)
//sendPushbulletNote("OD", fitleredObjects)
end
Log:
Rule 'backDoorObjectFound': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.IntegerExtensions.operator_lessThan(int,int) on instance: null
Anyone got any ideas? The loop works if the objects var is a programmed number .e.g 2.
- Platform information:
- OS: Linux Ubuntu
- Java Runtime Environment: build 1.8.0_201-b09
- openHAB version: 2.4.0-1