I‘m using openHABian with a influxDB for persistence of my temperature sensors. In OH2.5 I created a rule to get the min and max values of the day. Attached the rule:
rule "Set daily max and min temperature für Außen"
when
Item Outside_Garten_Temperature changed or
Time cron "0 0 0 * * ?" or
System started
then
var Number Min = -99
var Number Max = -99
var String tmp
var SimpleDateFormat df = new SimpleDateFormat( "HH:mm" )
if (Outside_Garten_Temperature.state instanceof DecimalType) {
Min = (Outside_Garten_Temperature.minimumSince(now.withTimeAtStartOfDay, "influxdb").state as DecimalType)
tmp = (Math::round(Min.floatValue*10.0)/10.0) + " °C (" + df.format(Outside_Garten_Temperature.minimumSince(now.withTimeAtStartOfDay, "influxdb").timestamp) + " Uhr)"
postUpdate(Outside_Garten_Temperature_Min, tmp)
Max = Outside_Garten_Temperature.maximumSince(now.withTimeAtStartOfDay, "influxdb").state as DecimalType
df = new SimpleDateFormat( "HH:mm" )
tmp = (Math::round(Max.floatValue*10.0)/10.0) + " °C (" + df.format(Outside_Garten_Temperature.maximumSince(now.withTimeAtStartOfDay, "influxdb").timestamp) + " Uhr)"
postUpdate(Outside_Garten_Temperature_Max, tmp)
}
Script execution of rule with UID ‘rule’ failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.actions.Log.logInfo(java.lang.String,java.lang.String,java.lang.Object) on instance: null in rule
After a lot of hours testing and reading I found the solution and the rule works again
rule "Set daily max and min temperature für Außen"
when
Item Outside_Garten_Temperature changed or
Time cron "0 0 0 * * ?" or
System started
then
var Number Min_value = -99
var Number Max_value = -99
var String tmp
val time_formatter = java.time.format.DateTimeFormatter.ofPattern("HH:mm")
if (Outside_Garten_Temperature.state instanceof DecimalType) {
Min_value = (Outside_Garten_Temperature.minimumSince(now.with(LocalTime.of(0,0,0,0)), "influxdb").state as DecimalType)
var Min_time = Outside_Garten_Temperature.minimumSince(now.with(LocalTime.of(0,0,0,0)), "influxdb").timestamp
tmp = (Math::round(Min_value.floatValue*10.0)/10.0).toString() + "°C (" + Min_time.format(time_formatter) + " Uhr)"
postUpdate(Outside_Garten_Temperature_Min, tmp)
Max_value = (Outside_Garten_Temperature.maximumSince(now.with(LocalTime.of(0,0,0,0)), "influxdb").state as DecimalType)
var Max_time = Outside_Garten_Temperature.maximumSince(now.with(LocalTime.of(0,0,0,0)), "influxdb").timestamp
tmp = (Math::round(Max_value.floatValue*10.0)/10.0).toString() + "°C (" + Max_time.format(time_formatter) + " Uhr)"
postUpdate(Outside_Garten_Temperature_Max, tmp)
}
end
Hi,
I have a similar problem with my old OH2.5 rule in OH3 which calculates the power consumption.
OH2.5 old rule which worked in OH2.5:
rule "Stromzaehler EZD Bezug Heute Wh"
when
Item EZD_Wirken_A_plus_Wh received update
then
EZD_Bezug_Heute_Wh.postUpdate (((EZD_Wirken_A_plus_Wh.deltaSince(now.withTimeAtStartOfDay, "influxdb")).floatValue)/1000)
end
The problem is here:
deltaSince(now.withTimeAtStartOfDay
So I tried to replace this with:
deltaSince(now.with(LocalTime.of(0,0,0,0))
OH3 rule which gives an error:
rule "Stromzaehler EZD Bezug Heute Wh"
when
Item EZD_Wirken_A_plus_Wh received update
then
EZD_Bezug_Heute_Wh.postUpdate (((EZD_Wirken_A_plus_Wh.deltaSince(now.with(LocalTime.of(0,0,0,0)), "influxdb")).floatValue)/1000)
end
Unfortunately it does not work. The log does not show any error but my visual code marks this as an error:
Those shouldn’t mess anything up. VSCode is convinced that ‘now’ is a DateTime type. You might try a “fresh” now object ZonedDateTime.now.with(LocalTime.of(0,0,0,0))
etc.
Well, I have 2 Raspberries.
The old one is with OH2.5, and the new one with OH3.
I added the directories of both to VSCode to have access to the Config and Logfiles.
Got it. I had to change the IP in the settings of VBCode to the new raspberry.
Now a new problem came up.
Old rule:
rule "Mika_is_home"
when
Item cFboxMacOnlineM changed from CLOSED to OPEN
then
var Number hour = now.getHourOfDay()
if (hour >= 7 && hour <= 21 ) {
// Echo talks
if (Echo_Volume.state!=UNDEF && Echo_Volume.state!=NULL) {
Echo_Volume.sendCommand('25')
Thread::sleep(2000) // 2 second wait
Echo_TTS.sendCommand("Wilkommen zu Hause Mika.")
Thread::sleep(2000) // 2 second wait
}
hour = null
}
end