ItemPersistence

items. ItemPersistence

Class representing the historic state of an openHAB Item. Wrapping the PersistenceExtensions.

Be warned: This class can throw several exceptions from the underlying Java layer. It is recommended to wrap the methods of this class inside a try_catch block!

Please note: Several methods return null if the default persistence service is no queryable persistence service or the provided serviceId does not refer to an available queryable persistence service.

Methods

averageBetween(begin, end, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the average value of the state of a given Item between two certain points in time.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the point in time from which to start the average

end time.ZonedDateTime | Date

the point in time to which to start the average

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the average value between begin and end as items.PersistedState or null if no states could be found

Type
PersistedState | null

averageSince(timestamp, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the average value of the state of a given Item since a certain point in time.

Source:
Example
var yesterday = new Date(new Date().getTime() - (24 * 60 * 60 * 1000));
var item = items.getItem('KitchenDimmer');
console.log('KitchenDimmer average since yesterday', item.persistence.averageSince(yesterday));
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time from which to search for the average value

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the average value since timestamp as items.PersistedState or null if no previous states could be found

Type
PersistedState | null

averageUntil(timestamp, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the average value of the state of a given Item until a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to which to search for the average value

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the average value until timestamp as items.PersistedState or null if no future states could be found

Type
PersistedState | null

changedBetween(begin, end, serviceIdopt) → {boolean}

Description:
  • Checks if the state of a given Item has changed between two certain points in time.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the point in time to start the check

end time.ZonedDateTime | Date

the point in time to stop the check

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

true if item state changes, false if the item does not change in the given interval, null if begin is after end

Type
boolean

changedSince(timestamp, serviceIdopt) → {boolean}

Description:
  • Checks if the state of a given Item has changed since a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to start the check

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

true if item state has changed, false if it has not changed, null if timestamp is in the future

Type
boolean

changedUntil(timestamp, serviceIdopt) → {boolean}

Description:
  • Checks if the state of a given Item will change by a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to end the check

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

true if item state will change, false if it will not change, null if timestamp> is in the past

Type
boolean

countBetween(begin, end, serviceIdopt) → {number}

Description:
  • Gets the number of available persisted data points of a given Item between two certain points in time.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the beginning point in time

end time.ZonedDateTime | Date

the end point in time

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the number of values persisted for this item, null if begin is after end

Type
number

countSince(timestamp, serviceIdopt) → {number}

Description:
  • Gets the number of available historic data points of a given Item since a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the beginning point in time

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the number of values persisted for this item, null if timestamp is in the future

Type
number

countStateChangesBetween(begin, end, serviceIdopt) → {number}

Description:
  • Gets the number of changes in persisted data points of a given Item between two certain points in time.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the beginning point in time

end time.ZonedDateTime | Date

the end point in time

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the number of state changes for this item

Type
number

countStateChangesSince(timestamp, serviceIdopt) → {number}

Description:
  • Gets the number of changes in historic data points of a given Item since a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the beginning point in time

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the number of state changes for this item

Type
number

countStateChangesUntil(timestamp, serviceIdopt) → {number}

Description:
  • Gets the number of changes in future data points of a given Item until a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the ending point in time

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the number of state changes for this item

Type
number

countUntil(timestamp, serviceIdopt) → {number}

Description:
  • Gets the number of available future data points of a given Item until a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the ending point in time

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the number of values persisted for this item, null if timestamp is in the past

Type
number

deltaBetween(begin, end, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the difference value of the state of a given Item between two certain points in time.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the beginning point in time

end time.ZonedDateTime | Date

the end point in time

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the difference between end and begin as items.PersistedState, or null if there is no persisted state for the given Item for the given points in time

Type
PersistedState | null

deltaSince(timestamp, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the difference value of the state of a given Item since a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time from which to compute the delta

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the difference between now and then as items.PersistedState, or null if there is no persisted state for the given Item at the given timestamp available

Type
PersistedState | null

deltaUntil(timestamp, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the difference value of the state of a given Item until a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to which to compute the delta

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the difference between then and now as items.PersistedState, or null if there is no persisted state for the given Item at the given timestamp available

Type
PersistedState | null

deviationBetween(begin, end, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the standard deviation of the state of the given Item between two certain points in time.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the point in time from which to compute

end time.ZonedDateTime | Date

the end time for the computation

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the standard deviation between both points of time as items.PersistedState, or null if begin is after end, or if there is no persisted state for the given Item between begin and end

Type
PersistedState | null

deviationSince(timestamp, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the standard deviation of the state of the given Item since a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time from which to compute the standard deviation

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the standard deviation between then and now as items.PersistedState, or null if timestamp is in the future, or if there is no persisted state for the given Item at the given timestamp

Type
PersistedState | null

deviationUntil(timestamp, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the standard deviation of the state of the given Item until a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to which to compute the standard deviation

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the standard deviation between now and then as items.PersistedState, or null if timestamp is in the past, or if there is no persisted state for the given Item at the given timestamp

Type
PersistedState | null

evolutionRateBetween(begin, end, serviceIdopt) → {number|null}

Description:
  • Gets the evolution rate of the state of a given Item between two certain points in time.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the beginning point in time

end time.ZonedDateTime | Date

the end point in time

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the evolution rate in percent (positive and negative) in the given interval, or null if there are no persisted states for the given Item at the given interval, or if there is a state, but it is zero (which would cause a divide-by-zero error)

Type
number | null

evolutionRateSince(timestamp, serviceIdopt) → {number|null}

Description:
  • Gets the evolution rate of the state of a given Item since a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time from which to compute the evolution rate

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the evolution rate in percent (positive and negative) between then and now, or null if there is no persisted state for the given Item at the given timestamp, or if there is a state, but it is zero (which would cause a divide-by-zero error)

Type
number | null

evolutionRateUntil(timestamp, serviceIdopt) → {number|null}

Description:
  • Gets the evolution rate of the state of a given Item until a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to which to compute the evolution rate

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the evolution rate in percent (positive and negative) between then and now, or null if there is no persisted state for the given Item at the given timestamp, or if there is a state, but it is zero (which would cause a divide-by-zero error)

Type
number | null

getAllStatesBetween(begin, end, serviceIdopt) → {Array.<PersistedItem>}

Description:
  • Retrieves the persisted Items for a given Item between two certain points in time.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the point in time from which to retrieve the states

end time.ZonedDateTime | Date

the point in time to which to retrieve the states

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the historic items.PersistedItems between the given points in time,

Type
Array.<PersistedItem>

getAllStatesSince(timestamp, serviceIdopt) → {Array.<PersistedItem>}

Description:
  • Retrieves the historic Items for a given Item since a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time from which to retrieve the states

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the items.PersistedItems since the given point in time

Type
Array.<PersistedItem>

getAllStatesUntil(timestamp, serviceIdopt) → {Array.<PersistedItem>}

Description:
  • Retrieves the future Items for a given Item until a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to which to retrieve the states

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the future items.PersistedItems to the given point in time

Type
Array.<PersistedItem>

lastUpdate(serviceIdopt) → {time.ZonedDateTime|null}

Description:
  • Query the last update time of a given Item.

Source:
Parameters:
Name Type Attributes Description
serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

point in time of the last historic update to Item, or null if there are no historic persisted updates

Type
time.ZonedDateTime | null

maximumBetween(begin, end, serviceIdopt) → {PersistedItem|null}

Description:
  • Gets the persisted Item with the maximum value of a given Item between two certain points in time.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the point in time to start the check

end time.ZonedDateTime | Date

the point in time to stop the check

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

a items.PersistedItem with the maximum state value between two points in time, or null if begin is after end

Type
PersistedItem | null

maximumSince(timestamp, serviceIdopt) → {PersistedItem|null}

Description:
  • Gets the historic Item with the maximum value of a given Item since a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to start the check

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

a items.PersistedItem with the maximum state value since the given point in time, or null if timestamp is in the future

Type
PersistedItem | null

maximumUntil(timestamp, serviceIdopt) → {PersistedItem|null}

Description:
  • Gets the future Item with the maximum value of a given Item until a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to end the check

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

a items.PersistedItemm with the maximum state value until the given point in time, or null if timestamp is in the past

Type
PersistedItem | null

minimumBetween(begin, end, serviceIdopt) → {PersistedItem|null}

Description:
  • Gets the state with the minimum value of a given Item between two certain points in time.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the point in time to start the check

end time.ZonedDateTime | Date

the point in time to stop the check

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

a items.PersistedItem with the minimum state value between two points in time, or null if begin is after end

Type
PersistedItem | null

minimumSince(timestamp, serviceIdopt) → {PersistedItem|null}

Description:
  • Gets the historic Item with the minimum value of a given Item since a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to start the check

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

a items.PersistedItem with the minimum state value since the given point in time, or null if timestamp is in the future

Type
PersistedItem | null

minimumUntil(timestamp, serviceIdopt) → {PersistedItem|null}

Description:
  • Gets the future Item with the minimum value of a given Item until a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to end the check

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

a items.PersistedItem with the minimum state value until the given point in time, or null if timestamp is in the past

Type
PersistedItem | null

nextState(skipEqualopt, serviceIdopt) → {PersistedItem|null}

Description:
  • Returns the next state of a given Item.

Source:
Parameters:
Name Type Attributes Description
skipEqual boolean <optional>

optional, if true, skips equal state values and searches the first state not equal the current state

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the items.PersistedItem at the given point in time, or null if no persisted item could be found or null

Type
PersistedItem | null

nextUpdate(serviceIdopt) → {time.ZonedDateTime|null}

Description:
  • Query the next update time of a given Item.

Source:
Parameters:
Name Type Attributes Description
serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

point in time of the first future update to Item, or null if there are no future persisted updates

Type
time.ZonedDateTime | null

persist(timestampopt, stateopt, serviceIdopt)

Description:
  • Persists the state of a given Item.

    Tells the persistence service to store the current state of the Item, which is then performed asynchronously. This has the side effect, that if the Item state changes shortly after .persist has been called, the new state will be persisted. To work around that side effect, you might add java.lang.Thread.sleep to your code:

Source:
Example
items.MyItem.persistence.persist(); // Tell persistence to store the current Item state
java.lang.Thread.sleep(100); // Wait 100 ms to make sure persistence has enough time to store the current Item state
items.MyItem.postUpdate(0); // Now set the Item state to a new value
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date <optional>

the date for the item state to be stored

state string <optional>

the state to be stored

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

persistedState(timestamp, serviceIdopt) → {PersistedItem|null}

Description:
  • Retrieves the persisted state for a given Item at a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time for which the persisted item should be retrieved

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the items.PersistedItem at the given point in time, or null if no persisted item could be found

Type
PersistedItem | null

previousState(skipEqualopt, serviceIdopt) → {PersistedItem|null}

Description:
  • Returns the previous state of a given Item.

Source:
Parameters:
Name Type Attributes Description
skipEqual boolean <optional>

optional, if true, skips equal state values and searches the first state not equal the current state

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the items.PersistedItem at the given point in time, or null if no persisted item could be found or null

Type
PersistedItem | null

removeAllStatesBetween(begin, end, serviceIdopt)

Description:
  • Removes from persistence the persisted items for a given Item between two certain points in time. This will only have effect if the persistence service is a modifiable persistence service.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the point in time from which to remove the states

end time.ZonedDateTime | Date

the point in time to which to remove the states

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

removeAllStatesSince(timestamp, serviceIdopt)

Description:
  • Removes from persistence the historic items for a given Item since a certain point in time. This will only have effect if the persistence service is a modifiable persistence service.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time from which to remove the states

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

removeAllStatesUntil(timestamp, serviceIdopt)

Description:
  • Removes from persistence the future items for a given Item until a certain point in time. This will only have effect if the persistence service is a modifiable persistence service.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to which to remove the states

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

sumBetween(begin, end, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the sum of the states of a given Item between two certain points in time.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the point in time from which to start the summation

end time.ZonedDateTime | Date

the point in time to which to start the summation

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the sum of the state values between the given points in time as items.PersistedState, or null if begin is after end

Type
PersistedState | null

sumSince(timestamp, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the sum of the states of a given Item since a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time from which to start the summation

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the sum of the state values since timestamp as items.PersistedState, or null if timestamp is in the future

Type
PersistedState | null

sumUntil(timestamp, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the sum of the states of a given Item until a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to which to start the summation

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the sum of the state values until timestamp as items.PersistedState, or null if timestamp is in the past

Type
PersistedState | null

updatedBetween(begin, end, serviceIdopt) → {boolean}

Description:
  • Checks if the state of a given Item has been updated between two certain points in time.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the point in time to start the check

end time.ZonedDateTime | Date

the point in time to stop the check

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

true if item state was updated, false if the item has not been updated in the given interval, null if begin is after end

Type
boolean

updatedSince(timestamp, serviceIdopt) → {boolean}

Description:
  • Checks if the state of a given Item has been updated since a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to start the check

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

true if item state was updated, false if the item has not been updated since timestamp, null if timestamp is in the future

Type
boolean

updatedUntil(timestamp, serviceIdopt) → {boolean}

Description:
  • Checks if the state of a given Item will have been updated until a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to end the check

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

true if item state is updated, false if the item is not updated until timestamp, null if timestamp is in the past

Type
boolean

varianceBetween(begin, end, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the variance of the state of the given Item between two certain points in time.

Source:
Parameters:
Name Type Attributes Description
begin time.ZonedDateTime | Date

the point in time from which to compute the variance

end time.ZonedDateTime | Date

the end time for the computation

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the variance between both points of time as items.PersistedState, or null if begin is after end, or if there is no persisted state for the given Item between begin and end

Type
PersistedState | null

varianceSince(timestamp, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the variance of the state of the given Item since a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time from which to compute the variance

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the variance between then and now as items.PersistedState, or null if timestamp is in the future, or if there is no persisted state for the given Item at the given timestamp

Type
PersistedState | null

varianceUntil(timestamp, serviceIdopt) → {PersistedState|null}

Description:
  • Gets the variance of the state of the given Item until a certain point in time.

Source:
Parameters:
Name Type Attributes Description
timestamp time.ZonedDateTime | Date

the point in time to which to compute the variance

serviceId string <optional>

optional persistence service ID, if omitted, the default persistence service will be used

Returns:

the variance between now and then as items.PersistedState, or null if timestamp is in the past, or if there is no persisted state for the given Item at the given timestamp

Type
PersistedState | null

Documentation generated by JSDoc 4.0.2 on Mon May 06 2024 10:01:30 GMT+0000 (Coordinated Universal Time) using the docdash theme.