0

我想在 openHAB2 中编写一个规则,它增加所有组项的计数器。这几项:

Group counters
Number cnt1 (counters)
Number cnt2 (counters)

我的规则尝试:

rule "Increase value .1 per minute"
when 
    Time cron "0 * * * * ?" or
    System started
then
    // Initialize. Necessary?
    counters?.members.forEach(counter|
        postUpdate(counter, 0.0)
    )
    counters?.members.forEach(counter|
        postUpdate(counter, 0.1 + counter.state)
    }
end

但这不起作用。例外: Error during the execution of startup rule 'Increase value .1 per minute': Could not invoke method: org.eclipse.xtext.xbase.lib.DoubleExtensions.operator_plus(double,byte) on instance: null

我试图探索 counter.state 的类型,并用logInfo(counter.state.class)它正确地记录日志...DecimalType

4

1 回答 1

2

似乎隐式类型转换似乎不起作用。如果您将规则更改为:

rule "Increase value .1 per minute"
when 
    Time cron "0 * * * * ?" or
    System started
then
    // Initialize. Necessary?
    counters?.members.forEach(counter|
        if (counter.state == null) {
            postUpdate(counter, 0.0)
        }
    )
    counters?.members.forEach(counter|
        postUpdate(counter, 0.1 + (counter.state as DecimalType))
    }
end

它应该工作。希望这可以帮助,

托马斯 E.-E.

于 2015-03-13T10:01:22.390 回答