Max min temp issues after updating to 3.0

Some more logInfo() would have been useful to establish progress and sensible value being returned, you can see how to do this, but let’s go with what we’ve got.

Let’s have a tidy up here, you only need to do the maximumSince once.

Max = Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MAX, “rrd4j”).state as DecimalType )
df = new SimpleDateFormat( “HH:mm” )
tmp = (Math::round(Max.floatValue</em> 10.0)/10.0) + " °C (” + df.format(Max.timestamp) + “)”)

Now it’s bit clearer to see what is going on in this part.

First thing I see is wrong quotemark types. That may be an artefact of copy-pasting, I can’t tell because you have not used code fences, but let’s fix it.

Next thing is the df=, you already did that at the beginning of the rule and it has not changed, so no need to do it again just leave it out.

Max = Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MAX, “rrd4j”).state as DecimalType )
tmp = (Math::round(Max.floatValue</em> 10.0)/10.0) + " °C (" + df.format(Max.timestamp) + ")")

Next thing is this

tmp = (Math::round(Max.floatValue10.0)/10.0) ...

What’s the floatValue10.0? Is that a copy-paste error? Is this really where the previous brackets error came from?
Let’s guess it’s supposed to be

tmp = (Math::round(Max.floatValue/10.0) + " °C (" + df.format(Max.timestamp) + ")")

Alright, so something going wrong to do with DateTime

so that has to be failing in
df.format(Max.timestamp)

The log also shows us the string that we get from persistence timestamp
2021-01-26T06:43:01.603275+01:00[Europe/Copenhagen]

That looks like a zonedDateTime to me, and I think you’ll need a different formatter to get your “HH:MM”. I really don’t know.
Change of times was one of the OH3 changes, due to Java 11 changes.

I have change to this

import java.text.SimpleDateFormat

rule "Temperatur Min-og Max values Carportnord"

when

        Item Temperatur_Udebygninger_Carportnord received update

then

        var Number Min

        var Number Max

        var String tmp

        var SimpleDateFormat df = new SimpleDateFormat( "HH:MM" ) 

        if (Temperatur_Udebygninger_Carportnord.state instanceof DecimalType) {

                logInfo("test", "TempUC " + Temperatur_Udebygninger_Carportnord.state.toString)

            Min = (Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN), "rrd4j").state as DecimalType)

            logInfo("test", "Min " + Min.toString)

            tmp = (Math::round(Min.floatValue*10.0)/10.0) + " °C (" + df.format(Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN, "rrd4j").timestamp) + ")")

            postUpdate(Temperatur_Udebygninger_Carportnord_Min, tmp)

                Max = Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MAX, “rrd4j”).state as DecimalType )

                tmp = (Math::round(Max.floatValue/10.0) + " °C (" + df.format(Max.timestamp) + ")")

                postUpdate(Temperatur_Udebygninger_Carportnord_Max, tmp)

        }

end

and now i get this in the log

2021-01-27 05:48:26.982 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘tempudv.rules’
2021-01-27 05:48:27.004 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘tempudv.rules’ has errors, therefore ignoring it: [21,96]: no viable alternative at input ‘“’
[21,97]: mismatched input ‘rrd4j’ expecting ‘)’
[21,126]: mismatched input ‘)’ expecting ‘end’

the " was not rigtht at the “rrd4j”
so now i have this error in the log

2021-01-27 07:30:39.023 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘tempudv-1’ failed: An error occurred during the script execution: Could not invoke method: java.time.ZonedDateTime.with(java.time.temporal.TemporalField,long) on instance: 2021-01-27T07:30:39.023015+01:00[Europe/Copenhagen] in tempudv

the rule code is now

import java.text.SimpleDateFormat

rule "Temperatur Min-og Max values Carportnord"

when

        Item Temperatur_Udebygninger_Carportnord received update

then

        var Number Min

        var Number Max

        var String tmp

        var SimpleDateFormat df = new SimpleDateFormat( "HH:MM" ) 

        if (Temperatur_Udebygninger_Carportnord.state instanceof DecimalType) {

                logInfo("test", "TempUC " + Temperatur_Udebygninger_Carportnord.state.toString)

            Min = (Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN), "rrd4j").state as DecimalType)

            logInfo("test", "Min " + Min.toString)

            tmp = (Math::round(Min.floatValue*10.0)/10.0) + " °C (" + df.format(Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN, "rrd4j").timestamp) + ")")

            postUpdate(Temperatur_Udebygninger_Carportnord_Min, tmp)

                Max = Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MAX, "rrd4j").state as DecimalType )

                tmp = (Math::round(Max.floatValue/10.0) + " °C (" + df.format(Max.timestamp) + ")")

                postUpdate(Temperatur_Udebygninger_Carportnord_Max, tmp)

        }

end

Yes, you need to find out how to format a zonedDateTime type object (the .timestamp from your persistence) into the “HH:MM” that you want. I don’t know that.

Ok, I’ll try to see if I can find something about how I do it

I think you can do something like this

using DateTimeFormatter but I don’t know how to use it.

Guessing:

val hmformat = java.time.format.DateTimeFormatter.ofPattern("HH:mm");
...  .timestamp.format(hmformat) + ...

Like this, but is it not working can you see if I have errors in the code,

2021-01-27 12:52:17.609 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘tempudv-1’ failed: The name ‘df’ cannot be resolved to an item or type; line 21, column 71, length 2 in tempudv

//import java.text.SimpleDateFormat
//import java.util.Date



rule "Temperatur Min-og Max values Carportnord"
when
        Item Temperatur_Udebygninger_Carportnord received update
then
        var Number Min
        var Number Max
        var String tmp
        //var SimpleDateFormat df = new SimpleDateFormat( "HH:MM" ) 
        val hmformat = java.time.format.DateTimeFormatter.ofPattern("HH:mm")


        if (Temperatur_Udebygninger_Carportnord.state instanceof DecimalType) {
                logInfo("test", "TempUC " + Temperatur_Udebygninger_Carportnord.state.toString)
            Min = (Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN), "rrd4j").state as DecimalType)
            logInfo("test", "Min " + Min.toString)
            tmp = (Math::round(Min.floatValue*10.0)/10.0) + " °C (" + df.format(Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN, "rrd4j").timestamp.format(hmformat) + ")"))
            postUpdate(Temperatur_Udebygninger_Carportnord_Min, tmp)

                Max = Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MAX, "rrd4j").state as DecimalType )
                tmp = (Math::round(Max.floatValue/10.0) + " °C (" + df.format(Max.timestamp.format(hmformat) + ")"))
                postUpdate(Temperatur_Udebygninger_Carportnord_Max, tmp)
        }
end	

You have to read these messages, it is telling you what the problem is.

Because you’ve rightly removed variable df

you can no longer use df in your rule

and must remove all reference to it.

Let’s just do something simple and see if it works.

val hmformat = java.time.format.DateTimeFormatter.ofPattern("HH:mm")

var record =  (Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN), "rrd4j")
logInfo("test", "Min state " + record.state.toString)
logInfo("test", "Min stamp " + record.timestamp.format(hmformat))

sorry a lot, but I’m not a programmer just a happy fitter who is not so good at English so I do not write so much about what I think could be the mistake and where I get stuck, I should probably make myself more understandable about this

Here I have // the lines where DF is included

and here is what the log now says

2021-01-27 14:26:22.691 [INFO ] [org.openhab.core.model.script.test ] - Min state -2.43
2021-01-27 14:26:22.692 [INFO ] [org.openhab.core.model.script.test ] - Min stamp 02:00
2021-01-27 14:26:22.692 [INFO ] [org.openhab.core.model.script.test ] - TempUC 1.31
2021-01-27 14:26:22.694 [INFO ] [org.openhab.core.model.script.test ] - Min -2.43
2021-01-27 14:26:22.696 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘tempudv-1’ failed: An error occurred during the script execution: Could not invoke method: java.time.ZonedDateTime.with(java.time.temporal.TemporalField,long) on instance: 2021-01-27T14:26:22.696025+01:00[Europe/Copenhagen] in tempudv

rule "Temperatur Min-og Max values Carportnord"
when
        Item Temperatur_Udebygninger_Carportnord received update
then
        var Number Min
        //var Number Max
        var String tmp
        //var SimpleDateFormat df = new SimpleDateFormat( "HH:MM" ) 
        val hmformat = java.time.format.DateTimeFormatter.ofPattern("HH:mm")

        var record =  (Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN), "rrd4j"))

        logInfo("test", "Min state " + record.state.toString)
        logInfo("test", "Min stamp " + record.timestamp.format(hmformat))


        if (Temperatur_Udebygninger_Carportnord.state instanceof DecimalType) {
                logInfo("test", "TempUC " + Temperatur_Udebygninger_Carportnord.state.toString)
            Min = (Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN), "rrd4j").state as DecimalType)
            logInfo("test", "Min " + Min.toString)
            //tmp = (Math::round(Min.floatValue*10.0)/10.0) + " °C (" + df.format(Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN, "rrd4j").timestamp.format(hmformat) + ")"))
            postUpdate(Temperatur_Udebygninger_Carportnord_Min, tmp)

                Max = Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MAX, "rrd4j").state as DecimalType )
                //tmp = (Math::round(Max.floatValue/10.0) + " °C (" + df.format(Max.timestamp.format(hmformat) + ")"))
                postUpdate(Temperatur_Udebygninger_Carportnord_Max, tmp)
        }
end	

hurray, so we’ve guessed how to get the persistence timestamp into the hh:mm form you want. :smiley:

Let’s have a tidy up now.
No imports at all.

rule "Temperatur Min-og Max values Carportnord"
when
        Item Temperatur_Udebygninger_Carportnord received update
then
        val hmformat = java.time.format.DateTimeFormatter.ofPattern("HH:mm")

        if (Temperatur_Udebygninger_Carportnord.state instanceof DecimalType) {
            var Min = Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN), "rrd4j")
                // changed so that Min is the whole database record
            var tmp = (Min.state as DecimalType).format("%.1f") + " °C (" + Min.timestamp.format(hmformat) + ")"
                // changed to make it simpler and more efficient,less database accessing
            postUpdate(Temperatur_Udebygninger_Carportnord_Min, tmp)

                var Max = Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MAX, "rrd4j")
                tmp = (Max.state as DecimalType).format("%.1f") + " °C (" + Max.timestamp.format(hmformat) + ")"
                postUpdate(Temperatur_Udebygninger_Carportnord_Max, tmp)
        }
end

Hi

now i get this error, and i dont have any idea

2021-01-27 20:17:43.760 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘tempudv-1’ failed: Invalid start/end time in fetch request: 1611788399 > 1611775063 in tempudv

rule code

rule "Temperatur Min-og Max values Carportnord"
when
        Item Temperatur_Udebygninger_Carportnord received update
then
        val hmformat = java.time.format.DateTimeFormatter.ofPattern("HH:mm")

        if (Temperatur_Udebygninger_Carportnord.state instanceof DecimalType) {
            var Min = Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN), "rrd4j")
                // changed so that Min is the whole database record
            var tmp = (Min.state as DecimalType).format("%.1f") + " °C (" + Min.timestamp.format(hmformat) + ")"
                // changed to make it simpler and more efficient,less database accessing
            postUpdate(Temperatur_Udebygninger_Carportnord_Min, tmp)

                var Max = Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MAX), "rrd4j")
                tmp = (Max.state as DecimalType).format("%.1f") + " °C (" + Max.timestamp.format(hmformat) + ")"
                postUpdate(Temperatur_Udebygninger_Carportnord_Max, tmp)
        }
end

but i got the min temp now

Typo on my part,you could have worked this out by comparing working Min part with non-working Max part, and using the "Invalid start/end time" clue to look closely at the timey code.

Not
(now.with(LocalTime.MAX, “rrd4j”)
but
(now.with(LocalTime.MAX), “rrd4j”)

I have put the ) after max so is not that one

But ther was nor any var in front of tem = in the max line

tmp = (Max.state as DecimalType).format("%.1f") + " °C (" + Max.timestamp.format(hmformat) + ")"

 var tmp = (Max.state as DecimalType).format("%.1f") + " °C (" + Max.timestamp.format(hmformat) + ")"

But i stil dont have the max value in sitemap

There should not be. We declared tmp with a var earlier,now we’re re-using it.

What’s in your openhab.log now? Please don’t be shy about giving information.

I still have this error whit and whitout the var ind front of tmp max

2021-01-27 20:57:46.872 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘tempudv-1’ failed: Invalid start/end time in fetch request: 1611788399 > 1611777466 in tempudv

when i removed the var in front of tmp max i got this allso

2021-01-27 21:02:38.376 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model ‘tempudv.rules’, using it anyway:
The value of the local variable Min is not used

Then your rule is messed up in some way that I cannot see. May we see the current version?

I just realized what this is about.
Persistence stores records of the past, not the future.

var Max = Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MAX), "rrd4j")

We’re just not allowed to get maximumSince for today’s midnight because that hasn’t happened yet.
That MAX sneaked in somewhere.

var Max = Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MIN), "rrd4j")

since last midnight

Thank you very very much. Now it all works, :slight_smile: :slight_smile:

rule code

rule "Temperatur Min-og Max values Carportnord"
when
        Item Temperatur_Udebygninger_Carportnord received update
then
        val hmformat = java.time.format.DateTimeFormatter.ofPattern("HH:mm")

        if (Temperatur_Udebygninger_Carportnord.state instanceof DecimalType) {
            var Min = Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN), "rrd4j")
                // changed so that Min is the whole database record
            var tmp = (Min.state as DecimalType).format("%.1f") + " °C (" + Min.timestamp.format(hmformat) + ")"
                // changed to make it simpler and more efficient,less database accessing
            postUpdate(Temperatur_Udebygninger_Carportnord_Min, tmp)
            
            var Max = Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MIN), "rrd4j")
                tmp = (Max.state as DecimalType).format("%.1f") + " °C (" + Max.timestamp.format(hmformat) + ")"
                
            postUpdate(Temperatur_Udebygninger_Carportnord_Max, tmp)
        }
end
````
1 Like
rule "Минимальные и максимальные значения температуры"
when
        Item Meteo_Temperature1 received update
then
        val hmformat = java.time.format.DateTimeFormatter.ofPattern("HH:mm")

        if (Meteo_Temperature1.state instanceof DecimalType) {
		logInfo("test", "TempUC " + Meteo_Temperature1.state.toString)
            var Min = Meteo_Temperature1.minimumSince(now.with(LocalTime.MIN, "rrd4j").state as DecimalType)
                // changed so that Min is the whole database record
            var tmp = (Min.state as DecimalType).format("%.1f") + " °C (" + Min.timestamp.format(hmformat) + ")"
                // changed to make it simpler and more efficient,less database accessing
            postUpdate(Meteo_Temperature1_Min, tmp)

            var Max = Meteo_Temperature1.maximumSince(now.with(LocalTime.MAX, "rrd4j").state as DecimalType)
            tmp = (Max.state as DecimalType).format("%.1f") + " °C (" + Max.timestamp.format(hmformat) + ")"
            postUpdate(Meteo_Temperature1_Max, tmp)
        }
end

Hello everyone.The rule does not work. Min.temp. shows Err, and Max. just a dash and a degree Celsius. What could be the problem? OpenHAB 3.2 is installed.