Max min temp issues after updating to 3.0

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.

We have no way of finding out. This is up to you. What is in your openhab.log ? You’ve got a logInfo(), for example. What does that say? What about those postUpdate(), do you see any changes in your events.log ?

Do you think you might be having exactly the same issue that you’ve already read about in this thread, now.with(LocalTime.MAX) is in the future and persistence service cannot see into the future?

You need to take care with brackets as well,
xxx.minimumSince(now.with(LocalTime.MIN, "rrd4j")
makes no sense, .now.with() doesn’t want a second parameter.
Try
xxx.minimumSince(now.with(LocalTime.MIN), "rrd4j")
so that “rrd4j” is a parameter for minimumSince() instead

2021-09-05 16:11:00.562 [INFO ] [org.openhab.core.model.script.test ] - TempUC 16.9
2021-09-05 16:11:00.666 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘Meteo-1’ failed: ‘state’ is not a member of ‘org.openhab.core.library.types.DecimalType’; line 15, column 24, length 9 in Meteo

That’s a bit of clue, have you fixed the brackets in that line yet? What does it look like now?

this is already with brackets

Okay, I’m out. I appreciate there is a language barrier, but you have to give more info.

The point about brackets is that is important where you put them. They were in the wrong place. The next person to help you would like to know where they are now.

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