Persistence and python in openHAB5

Hello everyone,

i try to get used to the new python script binding in openHAB5, but having some issues with the persistence class.

Goal is to cleanup a sql database which is connected via JDBC (set as default) via the following script:

from openhab import rule, Registry
from openhab.triggers import ItemStateUpdateTrigger, ItemCommandTrigger, when
from datetime import datetime, timedelta

@rule("Test", description="Test")
@when("Item TestTrigger received update")
def Test(module, input):
    time_Delta = datetime.now() - timedelta(hours=24)
     Registry.getItem("TestItem").getPersistence().removeAllStatesUntil(time_Delta.astimezone())

This throws an error in the logs:

2025-08-03 14:16:27.735 [WARN ] [nce.extensions.PersistenceExtensions] - Querying persistence service with open begin and/or end not allowed: begin null, end 2025-08-02T14:16:27.717+02:00, now 2025-08-03T14:16:27.735567812+02:00[Europe/Berlin]


Not sure why, tho.

According to the documentation it should be sufficient to pass one timestamp to the class, and the “end” timestamp in the log is exactly what i was expecting.

So what argument am i missing for the “begin” timestamp?

Best regards
Alex

I checked it right now and it seams no to be a python scripting bug.

The related java code in openhab core is

if ((begin == null && end == null) || (begin != null && end == null && begin.isAfter(now))
                    || (begin == null && end != null && end.isBefore(now))) {
                LoggerFactory.getLogger(PersistenceExtensions.class).warn(
                        "Querying persistence service with open begin and/or end not allowed: begin {}, end {}, now {}",
                        begin, end, now);
                return;
            }

the important part for your usecase is (begin == null && end != null && end.isBefore(now))

and the java doc says Removes from persistence the future items for a given <code>item</code> until a certain point in time.

For me it looks like, you can only delete states in the future.

After double checking the docs, you are right.
I intended the class to delete all data older than the given timestamp, but this cannot work.

Not sure about the usecase of the class, beside time travellers, but after switching to removeAllStatesBetween() everything is working.

Thanks!

Weather forecasts, future energy prices, stuff like that. The predictions may change so the old needs to be removed and new added.