2021-01-25 13:24:18.661 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘tempcarp-1’ failed: ‘toDateMidnight’ is not a member of ‘java.time.ZonedDateTime’; line 22, column 65, length 18 in tempcarp
Text label=“Temperatur” icon=“temperature” {
Text item=Date icon=“calendar”
Text item=Temperatur_Udebygninger_Carportnord label=“Temperatur Udvendig [%.1f °C]”
Text item=Temperatur_Udebygninger_Carport label=“Temperatur Carport [%.1f °C]”
Text item=Temperature_Terrasse label=“Terrasse temperature [%.2f °C]” icon=“temperature”
Text item=Humidity_Terrasse label=“Terrasse Humidity [%.1f %%]” icon=“humidity”
Text item=Temperatur_Udebygninger_Carportnord_Min label=“Min temperatur Udvendig [%s]”
Text item=Temperatur_Udebygninger_Carportnord_Max label=“Max temperatur Udvendig [%s]”
Text item=Temperatur_Udebygninger_Carport_Min label=“Min temperatur carport [%s]”
Text item=Temperatur_Udebygninger_Carport_Max label=“Max temperatur carport [%s]”
Text item=Temperature_Terrasse_Min label=“Min temperatur Terrasse [%s]”
Text item=Temperature_Terrasse_Max label=“Max temperatur Terrasse [%s]”
}
items
Number Temperature_Vaerksted “Temperatur værksted [%.2f °C]” { channel=“mqtt:topic:mybroker:mything:Temperature_VaerkstedChannel” }
Number Humidity_Vaerksted “Humidity [%.1f %%]” { channel=“mqtt:topic:mybroker:mything:Humidity_VaerkstedChannel” }
Number Temperature_Terrasse “Temperatur Terrasse [%.2f °C]” (gHistory) { channel=“mqtt:topic:mybroker:mything2:Temperature_TerasseChannel” }
String Temperature_Terrasse_Min “- Min. Temp [%.1f °C]”
String Temperature_Terrasse_Max “- Max. Temp [%.1f °C]”
Number Humidity_Terrasse “Humidity [%.1f %%]” (gHistory) { channel=“mqtt:topic:mybroker:mything2:Humidity_TerasseChannel” }
So, your device linked Items work fine, but the ones that should be calculated by rule do not?
Sounds like your rule is not working.
Have you fixed the rule error?
import java.text.SimpleDateFormat
import java.time.format.DateTimeFormatter
import org.eclipse.smarthome.core.library.types.DecimalType
import org.joda.datetime.DateTime.*
rule “Temperatur Min-og Max values Carportnord”
when
Time cron “0/60 * * * * ?”
then
var Number Min
var Number Max
var String tmp
var SimpleDateFormat df = new SimpleDateFormat( “HH:mm” )
if (Temperatur_Udebygninger_Carportnord.state instanceof DecimalType) {
Min = (Temperatur_Udebygninger_Carportnord.minimumSince(now.with(LocalTime.MIN), “rrd4j”).state as DecimalType)
tmp = (Math::round(Min.floatValue10.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
df = new SimpleDateFormat( “HH:mm” )
tmp = (Math::round(Max.floatValue10.0)/10.0) + " °C (" + df.format(Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MAX), “rrd4j”).timestamp) + “)”
postUpdate(Temperatur_Udebygninger_Carportnord_Max, tmp)
}
end
2021-01-25 20:58:16.358 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘tempudv.rules’ has errors, therefore ignoring it: [21,13]: missing ‘)’ at ‘postUpdate’
[24,13]: missing ‘)’ at ‘df’
rule is now
import java.text.SimpleDateFormat
import java.time.format.DateTimeFormatter
//import org.eclipse.smarthome.core.library.types.DecimalType
//import org.joda.datetime.DateTime.*
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.floatValue10.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
df = new SimpleDateFormat( “HH:mm” )
tmp = (Math::round(Max.floatValue10.0)/10.0) + " °C (” + df.format(Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MAX), “rrd4j”).timestamp) + “)”
postUpdate(Temperatur_Udebygninger_Carportnord_Max, tmp)
}
end
Okay, it is telling you it bumped into postUpdate when it expected to find a ) bracket.
In the line before the postUpdate, there are three opening brackets ((( but only two closing brackets )).
The bracket hidden inside a string “)” does not count for this.
but i stil have no data in my sitemap but i get this in the log
==> /var/log/openhab/events.log <==
2021-01-26 06:43:01.023 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Temperatur_Udebygninger_Carport’ changed from -1.37 to -1.43
==> /var/log/openhab/openhab.log <==
2021-01-26 06:43:01.597 [INFO ] [org.openhab.core.model.script.test ] - TempUC -2.81
2021-01-26 06:43:01.602 [INFO ] [org.openhab.core.model.script.test ] - Min -5.0
2021-01-26 06:43:01.603 [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-26T06:43:01.603275+01:00[Europe/Copenhagen] in tempudv
Rule
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.floatValue10.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 )
df = new SimpleDateFormat( “HH:mm” )
tmp = (Math::round(Max.floatValue10.0)/10.0) + " °C (” + df.format(Temperatur_Udebygninger_Carportnord.maximumSince(now.with(LocalTime.MAX, “rrd4j”).timestamp) + “)”)
postUpdate(Temperatur_Udebygninger_Carportnord_Max, tmp)
}
end
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
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.
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.