OH 2.5.11 to OH3 migration - System Started, MAPDB and iphone app problems

I’m just giving OH3 a try and after a bit of work I’ve got it alive and stable after a considerable time searching the forums. All my bindings seem present but all my restore on startup values from MAPDB are gone despite it loading the new version of MAPDB, and System started no longer works at startup or when a file is edited. Also my iphone won’t connect.
Is System started likely to be fixed anytime soon?
Is there a workaround for MAPDB so the values can be preserved?
My iphone authenticates via NGINX on the same box, what do I need to do to OH3 to allow it to work?
Fortunately I added a spare hard disk so I’ve swapped back to OH 2.5.11 for now

That is a problem, I guess we are talking about xxx.rules files here?

This kind of thing can be timing related, have you an unusually large configuration or powerful/puny host?

A closed issue, I do not think one is currently open for this -

That is by design in OH3, System started is supposed to do what it says.

related -

You have not provided near enough information to actually answer any of your questions fully. With the information provided:

There are two potential issues here. I’ve seen some reports that System started rules do not work in Rules DSL .rules files, but I thought that was fixed.
The second issue is what rossko57 points to. System started now properly triggers when the system starts, not merely when a .rules file is loaded.

Need more information. MapDB works and works well for me. I don’t think you can bring over the MapDB from your 2.5 instance to the 3.0 instance so you’ll need to repopulate those Items.

Anything more will require seeing how you’ve set up the .persist file and what you’ve done to try to test it.

OH 3 implements it’s own authentication and authorization. You need to modify the config. See OH3 with NGINX Reverse Proxy and Authentication and look at the full thread because there are different options.

Old DSL xxx.rules files on a dedicated PC - i3 / 8GB / SSD.with hundreds of Items. Basic testing done on a single small rules file that I previously used to load the rest of the files once a known item had been reset by persistence. This rule no longer seems to run. I’ll experiment later today to see if I can get anything to run. I wasn’t aware System started no longer runs when a rule is reloaded, and the thread is very informative.

Thanks for the clarification - adding something similar to the migration instructions could help others following on. In my case this is sufficient to break a few rules due to NULL not being expected

Again thanks, for some reason I didn’t find that one earlier when I was testing

Once I’ve made my morning coffee I’ll reboot back into OH 3 and see what I can get working

Thanks for the help, I’ve now got the iphone app working and have manually repopulated most of the items. Changed a lot of executeCommandline statements and edited many timer and date time parts of the rules.
Now my most glaring problem is how to work with date and time addition and subtraction. I’ve read all I can find concerning changes to Time and date settings but I can’t work out how to add and subtract time. Previously I stored the wanted time as an String Item and at the start of day or after a reboot I used parse to create a new DateTime variable based upon todays date with the time taken from the stored String item. I then used things like

if (wantedTimer.beforeNow) {logInfo("timers","its in the past") }

Unfortunately beforeNow and afterNow doesn’t seem to work. Neither does plusDays, so this doesn’t work

lastFullCharge = parse(LastFullCharge.state.toString)
nextFullCharge = lastFullCharge.plusDays(14)
logInfo("Timers", "Full charge due at " +nextFullCharge)

Can anyone suggest what these functions have been replaced with in OH3?

ZonedDateTime (Java SE 11 & JDK 11 ) documents everything you can do with a ZonedDateTime. Even your OH 2.5 approach sounds overly complicated.

For the first part (moving a ZonedDateTime to today) I’ve a library function that does that because I need to do that for my Time of Day implementation.

  /** Moves the passed in ZonedDateTime to today. */
  context.toToday = function(when) {
    var now = ZonedDateTime.now();
    var dt = toDateTime(when);
    return dt.withYear(now.getYear()).withMonth(now.getMonthValue()).withDayOfMonth(now.getDayOfMonth());

That’s JavaScript and that toDateTime call is to another function that converts just about anything you can think of to a proper ZonedDateTime. So in Rules DSL the relevant parts to move a ZonedDateTime to today are.

wantedTimer = wantedTimer.withYear(now.getYear()).withMonth(now.getMonth()).withDay(now.getDay())

That’s it. No complicated parsing of some String or conversion from one thing to the next.

And, as you can see at the link, there is indeed a plusDays() on ZonedDateTime. If that’s not working for you then parse is not returning a ZonedDateTime so you don’t want to mess with it anyway.

And, as you can see at the link and in lots of examples on the forum, there is an isBefore and isAfter set of methods that let you compare two ZonedDateTimes to each other. And you always have a ZonedDateTime for now in the rule so


I figured there would be a way :wink: However I’m still not there sadly.

var ZonedDateTime nextRuntime = (ZonedDateTime.now().plusDays(2))
logInfo("test", "nextRuntime "+ nextRuntime)

Seems to give a valid date time in the log


but the item isn’t updated. I’ve tried as a String Item and as a DateTime Item

What type of Item is RoombaNextRuntime?

I’ve tried both a String Item abs a DateTime item. In OH 2.5 it was a String IIRC but I’ll have to check

Then you need to send the command as a String. nextRuntime.toString()).

If it’s a DateTime then we need to coerce the ZonedDateTime into a format that is acceptable. The easiest way to do that is to create a new DateTimeType.

RoombaNextRuntime.sendCommand(new DateTimeType(nextRuntime))

I just got that to work using a couple of String Items and

var newTime = (ZonedDateTime.now().plusDays(2))

Now I need to get the date back from “RoombaNextRuntime,” which seems to work with

var LastRoombaStartedTime = parse(RoombaLastRuntime.state.toString)


 if (LastRoombaStartedTime.afterNow())

Doesn’t, and I can’t see it as a supported command in ZonedDateTime (Java SE 11 & JDK 11 ), so presumably this needs to be some other type of date time?

The intention is to ultimately set a timer if the date is after now

This set of rules starts the Roomba every couple of days after we leave the house, and then using Pushover sends a message to clean the Bin when we return

I don’t know where that parse comes from but I’m pretty sure it doesn’t return a ZonedDateTime. Use ZonedDateTime.parse(RoomaLastRuntime.state.toString).

Though why parse it back and forth? Just let it be a DateTime Item then you can

RoomNextRuntime.postUpdate(new DateTimeType(newTime))

and then to test it


Notice, there is not afterNow method. As I described above, you need to use isAfter and isBefore and pass it now which is an implicit variable which is, as the name implies, now.

I just changed the items to DateTime and modified the rule to read

RoombaLastRuntime.postUpdate(new DateTimeType())
var newTime = (ZonedDateTime.now().plusDays(2))
RoombaNextRuntime.postUpdate(new DateTimeType(newTime))

This gives me 2 dates items in the format 2021-01-23T10:59:16.219493+1300
Unfortunately the rule that works with one of these values doesn’t seem happy. I pasted in your suggestion

VSCode doesn’t seem happy with retrieving the values from an Item with that line

 The method getZonedDateTime() is undefined for the type State

and in the log I get

'getZonedDateTime' is not a member of 'org.openhab.core.types.State'

That may just be a VSCode weirdness. But you can make it go away by casting the state to a DateTimeType.

if((RoombaLastRuntime.state as DateTimeType).getZonedDateTime().isAfter(now)){

That worked and I can now set a timer. Thanks for the help, hopefully there’s enough there to allow me to work a lot of the rest. I’ll rewrite all of this one to simplify things. Only 61 errors left in vscode :slight_smile: