maximumSince doesnt work as expected

Hi,

I would like to display Max and Min temperatures of a year and therefore created two Items:

Number OutdoorTempMax
Number OutdoorTempMin

Simple rule:

    rule "Update Max Outdoor temp"
    when
    	Item OutdoorTemp changed or
    	System started
    then	
    	postUpdate(OutdoorTempMax, OutdoorTemp.maximumSince(now.minusDays(365)).state)
    end

    rule "Update Min Outdoor temp"
    when
    	Item OutdoorTemp changed or
    	System started
    then	
    	postUpdate(OutdoorTempMin, OutdoorTemp.minimumSince(now.minusDays(365)).state)
    end

rrd4j.persist

            OutdoorTemp: strategy = everyChange, everyMinute, restoreOnStartup
    	OutdoorTempMax : strategy = everyChange, restoreOnStartup
    	OutdoorTempMin : strategy = everyChange, restoreOnStartup

But everything I see for Max and Min ist the current temperature.
Even when the temperature changes, both (Max/Min) change too and displaying the current temp.
All values are stored well as I can see them in a chart.
Any idea what IĀ“m doing wrong here?

I donā€™t see anything wrong in your Code.

Are you sure your persitence is working?

  • Did you install RRD4J?
  • Did you choose RRD4J as your persistence service in Paper UI?
  • Do the past values get drawn in a sitemap when using Chart item=OutdoorTempMin period=Y
  • rrd4j - Persistence Services | openHAB

Do your rules actually run? Test this with a logInfo. Try printing the output of OutdoorTemp.minimumSince(now.minusDays(365)).state to the logs.

These are not going to work very well, for rrd4j with default archiving strategy you must have everyMinute as per the docs.

Doesnā€™t matter for your rule, as you are not trying to retrieve those two.

What is your default database? You have not directed the minimumSince() method to look in rrd4j explicitly.

What is your OH version? Time handling differs in OH3.

IĀ“m running OH 2.5.10

yes, RRD4J is installed and is also the default persistence service IĀ“m using.
Past values are drawn well for periods month/year.

Update: After a restart of OH values are updated well, so I assume this was the problem.
Thank you guys!

BTW: is it possible to have date/timestamp of the Max/Min event?
e.g. Max 33 on 2020-07-20

after another OH restart both Max/Min values are overwritten by the current temperature again
I really donĀ“t understand why :frowning:

Have you fixed their strategies yet?
Edited strategies do not come into effect until the next restart.

There might be some interaction between having these both restore-on-startup and calculated by system started rule, you donā€™t really need both, but I canā€™t see an issue really.

OLD:

OutdoorTemp: strategy = everyChange, everyMinute, restoreOnStartup
OutdoorTempMax : strategy = everyChange, restoreOnStartup
OutdoorTempMin : strategy = everyChange, restoreOnStartup

NEW:

OutdoorTemp: strategy = everyChange, everyMinute    	

Restarted OHā€¦ nothing changed. Min/Max values still showing the current temp value. crazy!

Iā€™d check the value that gets stored by the rules using a logInfo.
How do you check what values are persisted for max and min?

ItĀ“s tracked well with logInfo:
MaxTemp: 6.0, etc
but this is exactly the current temperature IĀ“m getting for item OutdoorTemp, but itĀ“s not the MAX.

I can draw charts for last two years, so Max and Min are present.

Sounds odd to me!

Did some test at my system using:

logInfo ("TestMaximumsince","Maximum was: " + OutsideTemperature.maximumSince(now.minusDays(365)).state + "Ā°C at " + OutsideTemperature.maximumSince(now.minusDays(365)).timestamp)
logInfo ("TestMaximumsince","Minimum was: " + OutsideTemperature.minimumSince(now.minusDays(365)).state + "Ā°C at " + OutsideTemperature.minimumSince(now.minusDays(365)).timestamp)
logInfo ("TestMaximumsince","Maximum was: " + OutsideTemperature.maximumSince(now.minusDays(30)).state + "Ā°C at " + OutsideTemperature.maximumSince(now.minusDays(30)).timestamp)
logInfo ("TestMaximumsince","Minimum was: " + OutsideTemperature.minimumSince(now.minusDays(30)).state + "Ā°C at " + OutsideTemperature.minimumSince(now.minusDays(30)).timestamp)
logInfo ("TestMaximumsince","Maximum was: " + OutsideTemperature.maximumSince(now.minusHours(24)).state + "Ā°C at " + OutsideTemperature.maximumSince(now.minusHours(24)).timestamp)
logInfo ("TestMaximumsince","Minimum was: " + OutsideTemperature.minimumSince(now.minusHours(24)).state + "Ā°C at " + OutsideTemperature.minimumSince(now.minusHours(24)).timestamp)

Returning:
Maximum was: 34.5Ā°C at Sat Aug 08 14:00:00 CEST 2020
Minimum was: -1.2Ā°C at Sat Dec 26 01:00:00 CET 2020
Maximum was: 10.2Ā°C at Tue Dec 22 06:30:00 CET 2020
Minimum was: -1.2Ā°C at Fri Dec 25 07:15:00 CET 2020
Maximum was: 4.6Ā°C at Wed Dec 30 15:44:12 CET 2020
Minimum was: 1.6Ā°C at Tue Dec 29 15:45:00 CET 2020

All returns are as they should be!

Did you check with a REST call for the persisted item-states or a chart wether the persisted data can be called when it is not working?
What would the .timestamp show for a .maximumSince .state with the actual (false) value be?
Could you do the checks as posted above when it is not working?

Note: Iā€™m fishing in the dark, in other words: I have no clue!

The .timestamp part does give the actual date of the HistoricItem.

I think IĀ“ve found the problem. Although default persistance rrd4j was selected via Habmin it disappeared at each restart of OH!
IĀ“ve checked every file under /conf/ and found a ā€œruntime.cfgā€.
There are several entries all commented out with a ā€œ#ā€, apart ā€œdefault persistence serviceā€ which was set to ā€œmapdbā€. A big question for me, as I never touched this file and definitely checked the default persistence within Habmin which was set to rrd4j (and disappeared after restart).

Anywayā€¦ IĀ“m happy it works fine now and I THANK you very much for your effort to help me!

2 Likes

how to display the Max/Min timestamp in the sitemap?

IĀ“ve created an item

DateTime OutdoorTempMinTime

Sitemap entry

Text item=OutdoorTempMinTime label="Min [%1$td %1$tb %1$tR]" icon="time"

and a rule

rule "Update Min Outdoor temp"
when
	Item OutdoorTemp changed or
	System started
then	
	postUpdate(OutdoorTempMin, OutdoorTemp.minimumSince(now.minusDays(365)).state)
	postUpdate(OutdoorTempMinTime, OutdoorTemp.minimumSince(now.minusDays(365)).timestamp)
	logInfo ("TestMaximumsince","Minimum was: " + OutdoorTempMin.minimumSince(now.minusDays(365)).state + "Ā°C at " + OutdoorTemp.minimumSince(now.minusDays(365)).timestamp)
end

For this I get an error:

2021-01-02 09:13:35.089 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Update Min Outdoor temp': Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.postUpdate(org.eclipse.smarthome.core.items.Item,java.lang.String) on instance: null

Any idea how to do it right way?

Iā€™m pretty sure postUpdate() will not accept any old object type - try strings.

postUpdate(OutdoorTempMinTime, OutdoorTemp.minimumSince(now.minusDays(365)).timestamp.toString)

.timestamp() is an alias, I vaguely recall it giving people trouble in some circumstances? .getTimestamp() worked for them.

tried with:

postUpdate(OutdoorTempMinTime, OutdoorTemp.minimumSince(now.minusDays(365)).timestamp.toString)

getting
2021-01-04 08:54:33.901 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert 'Wed Jan 22 13:00:00 CET 2020' to a state type which item 'OutdoorTempMinTime' accepts: [DateTimeType, UnDefType].

getTimestamp instead of timestamp brings the same error message

If you really want to only display it, using a string item should show something like ā€œ2020-12-18T15:15+01:00[Europe/Berlin]ā€ ( at least it shows like that in a logInfo)

replaced Item DateTime with String (Text in sitemap): no errors, but also nothing displayed in the sitemap

Anyway, itĀ“s not really importantā€¦ itĀ“s more like ā€œlessons to learnā€ for me to get more familiar with OH.

Using
postUpdate(Test, CPU_Load.minimumSince(now.minusDays(17)).timestamp.toString) on a string item and sitemap label set to "[%s]" I got the above posted string.

Perfect, works with ā€œ[%s]ā€ now

Thank you!