Rule processing a group of items isn't doing a comparison

As part of above I listed a script that I was having trouble firing. Hopefully sorted. So I started looking at the actual code.

I have one real battery (sitting at about 84% and two that should never drop off 100).

I’m using this, which I thought is to cycle through the 3 batties:
g_battery.allMembers.forEach[g |
logInfo(“BatteryMonitor”,"Item " + g.name + " state: " + g.state as DecimalType)
var DecimalType currentBattery = (g.state as DecimalType)
logInfo(“BatteryMonitor”,"Item " + g.name + " state: " + currentBattery + " threshold: " + lowBatteryThreshold)
if (currentBattery < lowBatteryThreshold)
{
report = report + "Item " + g.name + " state: " + g.state as DecimalType) + " Low Battery"
logInfo(“BatteryMonitor”,“Low Battery”)
}

                ]

But for some reason, even though I’ve set the threshold to 90F all three post that Low Battery log message. is that g_battery.allMembers.forEach[g | not what I want for a loop?

Here’s the logging:
2017-01-10 22:01:28.627 [INFO ] [.o.model.script.BatteryMonitor] - Received Command
2017-01-10 22:01:28.687 [INFO ] [.o.model.script.BatteryMonitor] - Found some item(s) under threshold
2017-01-10 22:01:29.102 [INFO ] [.o.model.script.BatteryMonitor] - Report produced: Battery levels (Threshold:90.0):
bm1_battery: 84.3294117647
apc600_battery: 100
apc1000_battery: 100
2017-01-10 22:01:29.325 [INFO ] [.o.model.script.BatteryMonitor] - Item bm1_battery state: 84.3294117647
2017-01-10 22:01:29.331 [INFO ] [.o.model.script.BatteryMonitor] - Item bm1_battery state: 84.3294117647 threshold: 90.0
2017-01-10 22:01:29.336 [INFO ] [.o.model.script.BatteryMonitor] - Low Battery
2017-01-10 22:01:29.338 [INFO ] [.o.model.script.BatteryMonitor] - Item apc600_battery state: 100
2017-01-10 22:01:29.338 [INFO ] [.o.model.script.BatteryMonitor] - Item apc600_battery state: 100 threshold: 90.0
2017-01-10 22:01:29.339 [INFO ] [.o.model.script.BatteryMonitor] - Low Battery
2017-01-10 22:01:29.339 [INFO ] [.o.model.script.BatteryMonitor] - Item apc1000_battery state: 100
2017-01-10 22:01:29.340 [INFO ] [.o.model.script.BatteryMonitor] - Item apc1000_battery state: 100 threshold: 90.0
2017-01-10 22:01:29.340 [INFO ] [.o.model.script.BatteryMonitor] - Low Battery
2017-01-10 22:01:29.388 [INFO ] [.o.model.script.BatteryMonitor] - Message: Battery levels (Threshold:90.0):
bm1_battery: 84.3294117647
apc600_battery: 100
apc1000_battery: 100
2017-01-10 22:01:29.411 [INFO ] [g.openhab.io.net.exec.ExecUtil] - executed commandLine ‘/etc/openhab/configurations/scripts/boxcar.sh Battery levels (Threshold:90.0):
bm1_battery: 84.3294117647
apc600_battery: 100
apc1000_battery: 100’

Please use code fences to preserve the indentation of your posted code

```
your code goes here
```

I see nothing incorrect in the code so I’m going to grasp at some straws:

  • Try casting currentBattery to Number instead. DecimalType is a Number so this should not matter.
  • Try using Number for lowBatteryThreshold instead of int
  • Try using val int currBattery = (g.state as Number).intValue

Hmm, I thought I had. I wonder if sometimes it gets confused with the brackets in the code.

So yes I think before I got your reply, I did try changing the threshold to a number and I forced the g.state into a number also.

I have been able to get it to go and now it gives me the correct info when I force it to run off a switch.

Weirdly I think this is still an issue: Rule triggered by time doesn't fire