Question Regarding Persistence Exclution Strategy

Hello everyone,

I’m trying to configure persistence for my items in OpenHAB, and I came across this line in the documentation regarding persistence strategies:

*, !Time_House_DeyeLastFailure : strategy = everyChange, everyDay, restoreOnStartup

According to this PR, the !Time_House_DeyeLastFailure part should prevent the item from being persisted. However, even with this configuration, Time_House_DeyeLastFailure is still being persisted.

Could anyone explain why this might be happening? Is there something I’m missing in my persistence strategy setup, or does the ! operator work differently than expected?

Thanks in advance for your help!

What version of OH are you running? Did you configure through the UI, or in a text file. If you configure through the UI, there was a bug in 4.3.0, which got solved in 4.3.1 (Fix UI persistence item exclude config by mherwege · Pull Request #4502 · openhab/openhab-core · GitHub).

Is this the only line in your setup? The veto works by line. If there are multiple lines, it may still be included (and persisted) through another line.

@Mherwege OH4.3.1 and congratulation iwas via file

I tested with a simple python script…no persistence if I commented this line

Not sure I understand. What do you do in this python script? Do you change the state of the item, or do you call a persistence action?

this is my python script to check the persistence service

import pymysql

# Datenbankverbindung herstellen
connection = pymysql.connect(
    host='localhost',        # Datenbank-Host
    user='***',    # Ihr MySQL-Benutzername
    password='***',# Ihr MySQL-Passwort
    database='***' # Der Name Ihrer Datenbank
)

try:
    # Cursor für die Datenbankoperationen
    with connection.cursor() as cursor:
        # Zeitbereich definieren
        start_time = '2025-01-12 11:00:00'
        end_time = '2025-01-12 12:00:00'
        
        # Tabellen mit der Spalte `time` finden
        cursor.execute("""
            SELECT TABLE_NAME
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_SCHEMA = DATABASE()
              AND COLUMN_NAME = 'time';
        """)
        tables = cursor.fetchall()
        
        if not tables:
            print("Keine Tabellen mit der Spalte 'time' gefunden.")
        else:
            # Ergebnisse sammeln
            results = []
            for (table_name,) in tables:
                # Abfrage erstellen und ausführen
                query = f"""
                    SELECT COUNT(*) 
                    FROM {table_name}
                    WHERE `time` BETWEEN %s AND %s;
                """
                cursor.execute(query, (start_time, end_time))
                count = cursor.fetchone()[0]
                
                # Nur Tabellen mit mehr als 60 Einträgen speichern
                if count > 60:
                    results.append((table_name, count))
            
            # Ergebnisse anzeigen
            if results:
                print("Tabellen mit mehr als 60 Einträgen im Zeitbereich:")
                for table_name, count in results:
                    print(f"- Tabelle: {table_name}, Einträge: {count}")
            else:
                print("Keine Tabellen mit mehr als 60 Einträgen im Zeitbereich gefunden.")
finally:
    # Verbindung schließen
    connection.close()

than here is the screenshot from my database

Bildschirmfoto vom 2025-01-12 17-00-09

set the timeframe between 16:00 and 17:00 (now its 16:44)

result is

python datatest.py 
Tabellen mit mehr als 60 Einträgen im Zeitbereich:

than I put the line into the persitent file

*, !Time_House_DeyeLastFailure : strategy = everyChange, everyDay, restoreOnStartup

and result is (now its 16:48) the item gets updated very quick

python datatest.py 
Tabellen mit mehr als 60 Einträgen im Zeitbereich:
- Tabelle: item0883, Einträge: 200

this is the complete file

Strategies {
   everyMinute	: "0 * * * * ?"
   everyHour    : "0 0 * * * ?"
   everyDay     : "0 0 0 * * ?"
   default = everyChange
}

Items {

 *: strategy = everyDay, restoreOnStartup
*, !Time_House_DeyeLastFailure : strategy = everyChange, everyDay, restoreOnStartup
 Group_House_SumEnergy* : strategy = everyChange, everyDay, restoreOnStartup
 Group_House_Climate* : strategy = everyChange, everyDay, restoreOnStartup
 Group_House_TotalEnergy* : strategy = everyChange, everyDay, restoreOnStartup
 Group_House_ActualPower* : strategy = everyChange, everyDay, restoreOnStartup
 Group_House_Temperature* : strategy = everyChange, everyDay, restoreOnStartup
 Group_House_Humidity* : strategy = everyChange, everyDay, restoreOnStartup
 //number_grouphousetemperaturechartperiod : strategy = everyChange, everyDay, restoreOnStartup
 //number_grouphousehumiditychartperiod : strategy = everyChange, everyDay, restoreOnStartup
 //ChartPeriod_House_TotalEnergy : strategy = everyChange, everyDay, restoreOnStartup
 switch_automation : strategy = everyChange, everyDay, restoreOnStartup
 switch_Master : strategy = everyChange, everyDay, restoreOnStartup
 Group_Timeline* : strategy = everyChange, everyDay, restoreOnStartup
 number_haspplate01_sensor_gasresistor : strategy = everyChange, restoreOnStartup
 number_airsensor1_co2 : strategy = everyChange, everyDay, restoreOnStartup
 number_airsensor2_pm25 : strategy = everyChange, everyDay, restoreOnStartup
 Energy_House_Deye_TotalEnergy: strategy = everyChange, everyDay, restoreOnStartup
 gOWM_TimeSeries: strategy = everyChange, everyDay, restoreOnStartup, forecast
 Sensor_Garden_Miflora1_Illuminance: strategy = everyChange, everyDay, restoreOnStartup
 Miflora_Sensor2_Light: strategy = everyChange, everyDay, restoreOnStartup
 Sensor_Garden_Miflora3_Illuminance: strategy = everyChange, everyDay, restoreOnStartup
 }

As @Mherwege said, vetoing only applies to the line where the ! occurs. You have the above line in your config meaning every Item will be saved everyDay regardless of what the remaining lines say.

This is an incorrect interpretation. What that means is this Item is prevented from being persisted with the strategies on that line. So it won’t be persisted everyChange, but because of the previous line it will still persist everyDay with restoreOnStartup.

I understood this…But it get persisted every change when I enable the line

*, !Time_House_DeyeLastFailure : strategy = everyChange, everyDay, restoreOnStartup

Is it a member of any of the Groups listed? Group_Timeline perhaps?

If not I don’t have any ideas.

If you enable this line, can you comment out the very first line and see if it makes any difference:

That line is covered by the second line anyway.

This is not solved…

Hey @Mherwege ,

I’m encountering an issue with excluding a group from specific persistence strategies in my .persist file. My setup aims to persist most items regularly while excluding a group called Group_House_NotPersistedEveryChange from being persisted on every change. Despite configuring the exclusion, it doesn’t seem to be working correctly.

Here’s my current .persist file configuration:

// persistence strategies have a name and a definition and are referred to in the "Items" section

Strategies {
   everyMinute  : "0 * * * * ?"
   everyHour    : "0 0 * * * ?"
   everyDay     : "0 0 0 * * ?"
   default = everyChange
}

Items {
  *: strategy = everyDay, restoreOnStartup
  *, !Group_House_NotPersistedEveryChange: strategy = everyChange
}

What I Expected:

  • All items except those in Group_House_NotPersistedEveryChange should persist using the everyChange strategy.
  • Items in Group_House_NotPersistedEveryChange should only persist once a day and restore on startup.

What Happened: It appears that the exclusion (!, Group_House_NotPersistedEveryChange ) is not being respected, and members of the group are still being persisted on every change.

Additional Observation: If I specify an individual item name instead of the group name for exclusion, the configuration works as expected. This leads me to believe that group exclusions may not be functioning properly.

Here is the item configuration

DateTime        Time_House_DeyeLastFailure  "Letzter Fehler"                  (Group_House_Sensors, Group_House_DeyeInverter, Group_House_NotPersistedEveryChange) ["Point"] 

Steps I Tried:

  1. Verified that Group_House_NotPersistedEveryChange is correctly defined and populated in my items configuration.
  2. Restarted OpenHAB after modifying the .persist file.
  3. Checked persistence logs to confirm that changes are still being captured despite the exclusion.

Questions:

  1. Is there a syntax error or conceptual issue with my configuration?
  2. Does OpenHAB support exclusions like !Group_Name in persistence configurations, or is there a better way to achieve this?
  3. Has anyone else successfully implemented a similar setup?

I’d appreciate any insights or advice on getting this working correctly.

Thanks!