Restore first item stored in database

  • 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: 2
  • Issue of the topic

I have installed the MySQL Binding.
I Like to use the First Item Stored in my database is this possible to identify it somehow?

It’s actually called “Add-on” (category: Persistence)

Why do you need to identify the first item that was stored in the DB?
What is your goal?

For calculation propose.
I have some energy consumption measuring devices which add always the amount of the daily energy consumption to the one from yesterday and so on…if I now like to know the amount of the actual consumption of the day I need to subtract the latest value from the sum of values from beginning.

Therefore I want to identify the first recorded date to use the persist function .sumsince()

So you want to identify the first timestamp that an Item’s state was stored for the specific Item (your thread title is way off in this case :slight_smile:)

If the power meter updates the Item state with the consumption delta of each 24hours, you shouldn’t really care when the persistence service started to store data. You can call the sumSince (capital S) for a predefined period of time (e.g. a month). The persistence will return whatever data it finds.

What do the meters report daily (or more frequently)? Delta or cumulative values?

Anyway… you can always use select statements and/or tools like phpMyadmin to look into the MySQL DB.

Cumulative value…

Okay didn’t know this so than it is easy…

Is it also possible to use .sumSince(onyear until one before last value) ???

I don’t think that you can specify in one line the start and end time for the .sumSince… You may need to do this in 2 steps in your rule and then calculate the difference.

it should look something like this in your rule:

val YTDValue = ItemName.sumSince(now.minusYears(1))  // this will give you Year To Date
val CurrentValue = ItemName.state  // this will give you the current state
val YTD2Last = YTDValue - CurrentValue // this will give you the YTD without the current state value


??? then you need to rethink your calculations.
If you do Sum on cumulative you will end up with a huge (wrong) number :slight_smile:

If you want just to visualize the data (not to use them in a rule): go with a tool like Grafana (you can configure there any time period you want)


Because YTD2Last should always have the delta to the last day…