[SOLVED] "Division undefined" in rule

Hey folks,

I’ve an issue in the following rule:

// Oven State Machine

rule "Oven Consumption State Machine"
when
    Item Qubino_Oven_MeteredWallPlug_SensorPower changed
then
    if ((Qubino_Oven_MeteredWallPlug_SensorPower.averageSince(now.minusMinutes(5)) as Number) == 0.0) Oven_OpState.postUpdate("offline")
    else if (Qubino_Oven_MeteredWallPlug_SensorPower.state < 0.5) Oven_OpState.postUpdate("standby")
    else if (Qubino_Oven_MeteredWallPlug_SensorPower.state > 1) Oven_OpState.postUpdate("running")
end

the error is this:

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Oven Consumption State Machine': Division undefined

Any clue?

I really appreciate your support

Andrea

Are you missing the { } in the rule or just a typo?

mmmm where?

These places:

rule "Oven Consumption State Machine"
when
    Item Qubino_Oven_MeteredWallPlug_SensorPower changed
then
    if ((Qubino_Oven_MeteredWallPlug_SensorPower.averageSince(now.minusMinutes(5)) as Number) == 0.0){
		 Oven_OpState.postUpdate("offline")
		 }
    else if (Qubino_Oven_MeteredWallPlug_SensorPower.state < 0.5){
		 Oven_OpState.postUpdate("standby")
		 }
    else if (Qubino_Oven_MeteredWallPlug_SensorPower.state > 1){
		 Oven_OpState.postUpdate("running")
		 }
end

Mmm is this necessary? frankly speaking I was thinking nope

Their placed in the rule after the if statement and contain what the rule should do when the statement is true.

Short answer, yep their needed.

Maybe a far fetched idea, but averageSince works only if you (a) have persistence and (b) persist your items with everyMinute strategy. Maybe check your persistence strategy for this.

@lipp_markus I was just looking back at the first statement, and wondering how this might pan out.:thinking:

Number Qubino_Oven_MeteredWallPlug_SensorPower "Power in real-time [%.2f W]" (gFF_Kitchen, gPowerMeters, gIPowerRealTime, gChart, gHistory)

gChart is rrd4j persistence strategy (everyMinute)
gHistory is influxdb persistence strategy (everyHour)
I have also mapdb persistence for default persistence strategy (restoreOnStartup)

Well frankly the first statement is something not working as expected.

Unfortunately, as explained here:

the Qubino wall plug is reporting 0.00 and 0.10/0.20 when the device is in standby (was not expecting 0.00). So calculating the average in the last 5 minutes (expecting different from 0), I’m trying to differentiate “offline” from “standby”.

Any suggestion?

Still going on a hunch…unless rrd4j is your default service, you may pull the wrong database (mapdb persists only always one value, and everyHour would not give you the data you need for your calculation)

So maybe this is not the right tool for reach the goal … actually I don’t know how to say “use the rrd4j strategy for that computation” instead of mapdb or influxdb

Qubino_Oven_MeteredWallPlug_SensorPower.averageSince(now.minusMinutes(5), "rrd4j")
2 Likes

So idea should be:

// Oven State Machine

rule "Oven Consumption State Machine"
when
    Item Qubino_Oven_MeteredWallPlug_SensorPower changed
then
    if ((Qubino_Oven_MeteredWallPlug_SensorPower.averageSince(now.minusMinutes(5), "rrd4j") as Number) == 0.0) {
        Oven_OpState.postUpdate("offline")
    }
    else if (Qubino_Oven_MeteredWallPlug_SensorPower.state < 0.5) {
        Oven_OpState.postUpdate("standby")
    }
    else if (Qubino_Oven_MeteredWallPlug_SensorPower.state > 1) {
        Oven_OpState.postUpdate("running")
    }
end
1 Like

If using rrd4j, like mentioned above, make sure to have everyMinute in the strategy.

1 Like

gChart* : strategy = everyMinute

That will work.:sunglasses:

If needed you can add others as well e.g. everyHour, everyUpdate, etc… important thing is to make sure that everyMinute is included.

2 Likes

Any suggestion how my rule should work better?
I mean, how to solve the issue above (I see “offline” sometimes, even if the device is ON and in standby)?

You can try to add some logInfo statements to debug the situation
check the output of:

logInfo("Testing", "Qubino last 5min avg is:" + (Qubino_Oven_MeteredWallPlug_SensorPower.averageSince(now.minusMinutes(5), "rrd4j").toString)

that is quite embarrassing :slight_smile:
It seems the issue was because the averageSince was not working properly due to wrong persistence :slight_smile:

Thank you guys :slight_smile:

1 Like