[SOLVED] Can't get Rule from OH 1.9 working in OH2.4

  • Platform information:
    • Hardware: CPUArchitecture/RAM/storage
    • OS: what OS is used and which version
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:
  • Issue of the topic: please be detailed explaining your issue
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

Hello community,

I’m a long time user of OH, was long stuck in 1.x. Now my migration to 2.4 is almost done.
This community was a lot of help, thanks for that.
But here is a problem I can’t get my head around and solve on my own (with heavy usage of the i-net).

The following line is working in my live-system on 1.9:

heating_delay_WZ_avg.sendCommand(heating_delay_WZ.averageSince(now.minusDays((average_length.state as DecimalType).intValue)))

were “heating_delay_WZ” and “heating_delay_WZ_avg” and “average_length” are all items of type number.

What this line is intended to do: average_length is a parameter, wich I sometimes adjust via a setpoint in my sitemap. If average_length receives a command, some recalculations have to be done. For example the above line of code. The average of heating_delay_WZ has to be recalculated with a new range of time.

Now in OH 2.4 some things are obviously different and I have trouble with DateTime vs DateTimeType, etc.

Can someone help me with the correct code in OH for this?

I really appreciate your help.
Thanks a lot.

Thomas

I see nothing wrong with it:
Any error code?

Try:

val Number heatingDelayAvg = heating_delay_WZ.averageSince(now.minusDays((average_length.state as DecimalType).intValue))
logInfo("DELAY: ", heatingDelayAvg.toString)
heating_delay_WZ_avg.sendCommand(heatingDelayAvg)

I get this:

2019-01-26 13:55:37.326 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'average_length über Setpoint verändert': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.String) on instance: null

Seems to me, heatingDelayAvg resulted in “null”

Have you defined your default database in the paperUI?

If you mean persistence, yes it is set.
But i don’t do anything in paperui, I do everything in the conf files.
My standard persistence is rrd4j.

Maybe I am off base, but if you are running a new install, are your data going back long enough? You can get these errors when there is simply no data point in rrd4j. One more thoughts, (with apologies if I am stating the obvious), rrd4j is compressing older data (one of rrd4j’s goals is to keep the database size fixed), depending on how far back you try to retrieve data, this may cause problems as data points are collapsed into, depending on your setup, in, e.g., hourly, daily, weekly or monthly averages. This makes it hard to retrieve data from fixed time points.

Thanks for all your help.
It’s working now.
That same line is doing absolutely what should now.

I think, there was something wrong in other parts of the rules-File, which I fixed today also.
It seems, those problems made the hole system “whobbly”. It was slow and the log some kind of lager minutes behind.
Since I corrected the faulty code, the system runs like a charm.

So, again thanks. And sorry for the “false problem”.

Thomas