Cant get minimumSince() to work

Hey all,
I’m running OH2 stable and trying to setup some minimumSince() rules which give me a hard time. I’m trying to get the lowest temperature in the last 24 hours. My item is persisted properly with various persistance methods for testing purpose.
Here’s the rule with corresponding log entries followed by a screenshot of influxdb/grafana data from the same time (now-24h) to show all data is available.

rule:

rule "lowest outside temp"
when
    Item aussen_Temperature_Sensor changed
then
    logInfo("test_minimumsince", "actual value        (mysql)    : " + aussen_Temperature_Sensor.state, "mysql")
    logInfo("test_minimumsince", "lowest value in 24h (rrd4j)    : " + aussen_Temperature_Sensor.minimumSince(now.minusDays(1)).state, "rrd4j")
    logInfo("test_minimumsince", "lowest value in 24h (influxdb) : " + aussen_Temperature_Sensor.minimumSince(now.minusDays(1)).state, "influxdb")
    logInfo("test_minimumsince", "lowest value in 24h (mysql)    : " + aussen_Temperature_Sensor.minimumSince(now.minusDays(1)).state, "mysql")
end

log:

    2017-02-14 14:46:38.632 [INFO ] [thome.model.script.test_minimumsince] - actual value        (mysql)    : 8.40
    2017-02-14 14:46:38.633 [INFO ] [thome.model.script.test_minimumsince] - lowest value in 24h (rrd4j)    : 8.40
    2017-02-14 14:46:38.634 [INFO ] [thome.model.script.test_minimumsince] - lowest value in 24h (influxdb) : 8.40
    2017-02-14 14:46:38.635 [INFO ] [thome.model.script.test_minimumsince] - lowest value in 24h (mysql)    : 8.40

Grafana data:

Mysql data (shortened):

    mysql> select ItemId from Items WHERE ItemName = "aussen_Temperature_Sensor";
    +--------+
    | ItemId |
    +--------+
    |     11 |
    +--------+
    mysql> select * from Item11 where Time >= NOW() - INTERVAL 1 DAY;
    +---------------------+-------+
    | Time                | Value |
    +---------------------+-------+
    | 2017-02-13 15:02:00 |  10.1 |
    | 2017-02-13 15:03:00 |  10.1 |
    | 2017-02-13 15:03:31 |  10.6 |
    ...
    | 2017-02-14 07:51:00 |   0.3 |
    | 2017-02-14 07:52:00 |   0.3 |
    | 2017-02-14 07:53:00 |   0.3 |
    | 2017-02-14 07:54:00 |   0.3 |
    | 2017-02-14 07:55:00 |   0.3 |
    | 2017-02-14 07:55:09 |   0.2 |
    | 2017-02-14 07:56:00 |   0.2 |
    | 2017-02-14 07:57:00 |   0.2 |
    | 2017-02-14 07:58:00 |   0.2 |
    | 2017-02-14 07:59:00 |   0.2 |
    | 2017-02-14 08:00:00 |   0.2 |
    | 2017-02-14 08:01:00 |   0.2 |
    ...
    | 2017-02-14 14:46:00 |     8 |
    | 2017-02-14 14:46:38 |   8.4 |
    | 2017-02-14 14:47:00 |   8.4 |
    | 2017-02-14 14:48:00 |   8.4 |
    | 2017-02-14 14:49:00 |   8.4 |
    +---------------------+-------+
    1656 rows in set (0.02 sec)

Expected return value for minimumSince() should be 0.2.
I guess I’ve done a misconfiguration, but cant find it. Any hint is appreaciated.
Thanks much.

Maybe this helps you, this is one of my rules:

rule "Temperature Average 7 Tage"
when
    Item HeatPump_Temperature_3 received update
then
    HeatPump_Temp_Outside_Avrg_7d.postUpdate(HeatPump_Temperature_3.averageSince(now.minusDays(7), "rrd4j"))
end

And here ias another one.

rule "Update Sole-RL Temperatur Min-Werte tgl ohne Rundung"
    when
        Item HeatPump_Temperature_7 received update
    then
		var Number Min
        var String tmp
        var SimpleDateFormat df = new SimpleDateFormat( "dd.MM., HH:mm" ) 

        if (HeatPump_Temperature_7.state instanceof DecimalType) {
            Min = (HeatPump_Temperature_7.minimumSince(now.minusDays(7), "db4o").state as DecimalType)
            tmp = (Math::round(Min.floatValue*10.0)/10.0) + " °C (" + df.format(HeatPump_Temperature_7.minimumSince(now.minusDays(7), "db4o").timestamp) + " )"
            postUpdate(HeatPump_Sole_RL_Min_ungerundet, tmp)
        }
end

Both work in OH1 and OH2.

Maybe “rrd4j” is on the wrong position? Or you have to use () before .state as DecimalType ?

1 Like

Oh, now i saw the wrong part:

logInfo("test_minimumsince", "actual value        (mysql)    : " + aussen_Temperature_Sensor.state, "mysql")
    logInfo("test_minimumsince", "lowest value in 24h (rrd4j)    : " + aussen_Temperature_Sensor.minimumSince(now.minusDays(1)).state, "rrd4j")
    logInfo("test_minimumsince", "lowest value in 24h (influxdb) : " + aussen_Temperature_Sensor.minimumSince(now.minusDays(1)).state, "influxdb")
    logInfo("test_minimumsince", "lowest value in 24h (mysql)    : " + aussen_Temperature_Sensor.minimumSince(now.minusDays(1)).state, "mysql")

The last part in each line “rrd4j” … is not the declaration, from what persistence the information should come, it´s a simple text, which you print in the log. But in this case, you have to add a “+” before the “rrd4j”.

So look to my examples in the above post.

1 Like

Hey @halloween,
thanks much for having a look at my rule and you spotted it quite right. I reconfigured my rule to have a temp variable containing the value first and print it afterwards got me going.

For completness sake, here’s the fixed test rule and log output.

rule:

rule "lowest outside temp"
when
    Item aussen_Temperature_Sensor changed
then
    //Actual
    var Number actual
    actual = (aussen_Temperature_Sensor.state as DecimalType)
    logInfo("test_minimumsince", "actual value             (mysql)    : " + actual)
    // MySQL
    var Number min_mysql
    min_mysql = (aussen_Temperature_Sensor.minimumSince(now.minusDays(1), "mysql").state as DecimalType)
    logInfo("test_minimumsince", "calculated min_mysql     (mysql)    : " + min_mysql)
    // InfluxDB
    var Number min_influfdb
    min_influfdb = (aussen_Temperature_Sensor.minimumSince(now.minusDays(1), "influxdb").state as DecimalType)
    logInfo("test_minimumsince", "calculated min_influfdb  (influfdb)    : " + min_influfdb)
    //RRD4J
    var Number min_rrd4j
    min_rrd4j = (aussen_Temperature_Sensor.minimumSince(now.minusDays(1), "rrd4j").state as DecimalType)
    logInfo("test_minimumsince", "calculated min_rrd4j     (rrd4j)    : " + min_rrd4j)
end

log:

2017-02-14 16:00:21.859 [INFO ] [thome.model.script.test_minimumsince] - actual value             (mysql)    : 13.50
2017-02-14 16:00:21.882 [INFO ] [thome.model.script.test_minimumsince] - calculated min_mysql     (mysql)    : 0.200000000000000011102230246251565404236316680908203125
2017-02-14 16:00:22.208 [INFO ] [thome.model.script.test_minimumsince] - calculated min_influfdb  (influfdb)    : 0.2
2017-02-14 16:00:22.219 [INFO ] [thome.model.script.test_minimumsince] - calculated min_rrd4j     (rrd4j)    : 0.200000000000000011102230246251565404236316680908203125

Again, thanks a lot!