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
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 ?
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”.
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