Module: OpenHAB::Core::Items::Persistence

Included in:
Item
Defined in:
lib/openhab/core/items/persistence.rb

Overview

Items extensions to support openHAB's Persistence feature.

Examples:

The following examples are based on these items

Number        UV_Index
Number:Power  Power_Usage "Power Usage [%.2f W]"

Getting persistence data from the system default persistence service

UV_Index.average_since(1.hour.ago)      # returns a DecimalType
Power_Usage.average_since(12.hours.ago) # returns a QuantityType that corresponds to the item's type

Querying a non-default persistence service

UV_Index.average_since(1.hour.ago, :influxdb)
Power_Usage.average_since(12.hours.ago, :rrd4j)

Time of day shortcuts

# Persistence methods accept any object that responds to #to_zoned_date_time, which includes
# LocalTime, LocalDate, and Ruby's Time, Date, and DateTime.
# This allows for easy querying of start of day
logger.info Power_Usage.average_since(LocalTime::MIDNIGHT)
logger.info Power_Usage.average_since(LocalDate.now)
# Ruby's Date can be used too
logger.info Power_Usage.average_since(Date.today)

# Yesterday
logger.info Power_Usage.average_between(Date.today - 1, Date.today)
# or
logger.info Power_Usage.average_between(LocalDate.now - 1, LocalDate.now)

# When passing the local time, today's date is assumed
logger.info Power_Usage.average_between(LocalTime.parse("4pm"), LocalTime.parse("9pm"))
# or
logger.info Power_Usage.average_between(Time.parse("4pm"), Time.parse("9pm"))

# Beware that Date, LocalDate, and LocalTime arithmetics will produce the same type, so
Power_Usage.average_between(LocalTime.parse("4pm") - 1.day, LocalTime.parse("9pm") - 1.day)
# Will still give you TODAY's data between 4pm and 9pm
# To get yesterday's data, use Time.parse, i.e.
Power_Usage.average_between(Time.parse("4pm") - 1.day, Time.parse("9pm") - 1.day)

Comparison using Quantity

# Because Power_Usage has a unit, the return value
# from average_since is a QuantityType
if Power_Usage.average_since(15.minutes.ago) > 5 | "kW"
  logger.info("The power usage exceeded its 15 min average)
end

PersistedState

max = Power_Usage.maximum_since(LocalTime::MIDNIGHT)
logger.info("Max power usage today: #{max}, at: #{max.timestamp})

See Also:

Defined Under Namespace

Classes: PersistedState

Constant Summary collapse

HistoricState =
Deprecated.

Use PersistedState instead

PersistedState

Instance Method Summary collapse

Instance Method Details

#all_states_between(start, finish, service = nil) ⇒ Array<PersistedState> #all_states_between(range, service = nil) ⇒ Array<PersistedState>

Returns all the states between two points in time.

Overloads:

  • #all_states_between(start, finish, service = nil) ⇒ Array<PersistedState>

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

  • #all_states_between(range, service = nil) ⇒ Array<PersistedState>

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

Returns:

Since:

  • openHAB 4.0



# File 'lib/openhab/core/items/persistence.rb', line 568

#all_states_since(timestamp, service = nil) ⇒ Array<PersistedState>

Returns all the states from a point in time until now.

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

Since:

  • openHAB 4.0



# File 'lib/openhab/core/items/persistence.rb', line 554

#all_states_until(timestamp, service = nil) ⇒ Array<PersistedState>

Returns all the states between now until the given time.

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 561

#average_between(start, finish, service = nil, reimann_type: nil) ⇒ DecimalType, ... #average_between(range, service = nil, reimann_type: nil) ⇒ DecimalType, ...

Returns the average value of the item's state between two points in time

Overloads:

  • #average_between(start, finish, service = nil, reimann_type: nil) ⇒ DecimalType, ...

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

    • riemann_type (:left, :midpoint, :right, :trapezoidal)

      An optional approximation type for Riemann sum. If nil, :left is used.

  • #average_between(range, service = nil, reimann_type: nil) ⇒ DecimalType, ...

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

    • riemann_type (:left, :midpoint, :right, :trapezoidal)

      An optional approximation type for Riemann sum. If nil, :left is used.

Returns:

  • (DecimalType, QuantityType, nil)

    The average value between start and finish, or nil if no states could be found.

Since:

  • openHAB 5.0 riemann_type parameter added



# File 'lib/openhab/core/items/persistence.rb', line 135

#average_since(timestamp, service = nil, riemann_type: nil) ⇒ DecimalType, ...

Returns the average value of the item's state since the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

  • riemann_type (:left, :midpoint, :right, :trapezoidal) (defaults to: nil)

    An optional approximation type for Riemann sum. If nil, :left is used.

Returns:

  • (DecimalType, QuantityType, nil)

    The average value since timestamp, or nil if no previous states could be found.

Since:

  • openHAB 5.0 riemann_type parameter added



# File 'lib/openhab/core/items/persistence.rb', line 114

#average_until(timestamp, service = nil, riemann_type: nil) ⇒ DecimalType, ...

Returns the average value of the item's state between now until the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

  • riemann_type (:left, :midpoint, :right, :trapezoidal) (defaults to: nil)

    An optional approximation type for Riemann sum. If nil, :left is used.

Returns:

  • (DecimalType, QuantityType, nil)

    The average value until timestamp, or nil if no future states could be found.

Since:

  • openHAB 4.2

  • openHAB 5.0 riemann_type parameter added



# File 'lib/openhab/core/items/persistence.rb', line 124

#changed_between?(start, finish, service = nil) ⇒ true, false #changed_between?(range, service = nil) ⇒ true, false

Whether the item's state changed between two points in time

Overloads:

  • #changed_between?(start, finish, service = nil) ⇒ true, false

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

  • #changed_between?(range, service = nil) ⇒ true, false

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

Returns:

  • (true, false)

    True if the item's state changed between start and finish, False otherwise.



# File 'lib/openhab/core/items/persistence.rb', line 337

#changed_since?(timestamp, service = nil) ⇒ true, false

Whether the item's state has changed since the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (true, false)

    True if the item's state has changed since the given timestamp, False otherwise.



# File 'lib/openhab/core/items/persistence.rb', line 324

#changed_until?(timestamp, service = nil) ⇒ true, false

Whether the item's state has changed between now until the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (true, false)

    True if the item's state has changed until the given timestamp, False otherwise.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 330

#count_between(start, finish, service = nil) ⇒ Integer #count_between(range, service = nil) ⇒ Integer

Returns the number of available data points between two points in time.

Overloads:

  • #count_between(start, finish, service = nil) ⇒ Integer

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

  • #count_between(range, service = nil) ⇒ Integer

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

Returns:

  • (Integer)

    The number of values persisted for this item.



# File 'lib/openhab/core/items/persistence.rb', line 515

#count_since(timestamp, service = nil) ⇒ Integer

Returns the number of available historic data points from a point in time until now.

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (Integer)

    The number of values persisted for this item.



# File 'lib/openhab/core/items/persistence.rb', line 502

#count_state_changes_between(start, finish, service = nil) ⇒ Integer #count_state_changes_between(range, service = nil) ⇒ Integer Also known as: state_changes_between

Returns the number of changes in data points between two points in time.

Overloads:

  • #count_state_changes_between(start, finish, service = nil) ⇒ Integer

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

  • #count_state_changes_between(range, service = nil) ⇒ Integer

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

Returns:

  • (Integer)

    The number of values persisted for this item.



# File 'lib/openhab/core/items/persistence.rb', line 541

#count_state_changes_since(timestamp, service = nil) ⇒ Integer Also known as: state_changes_since

Returns the number of changes in historic data points from a point in time until now.

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (Integer)

    The number of values persisted for this item.



# File 'lib/openhab/core/items/persistence.rb', line 528

#count_state_changes_until(timestamp, service = nil) ⇒ Integer Also known as: state_changes_until

Returns the number of changes in data points between now until the given time.

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (Integer)

    The number of values persisted for this item.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 534

#count_until(timestamp, service = nil) ⇒ Integer

Returns the number of available data points between now until the given time.

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (Integer)

    The number of values persisted for this item.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 508

#delta_between(start, finish, service = nil) ⇒ DecimalType, ... #delta_between(range, service = nil) ⇒ DecimalType, ...

Returns the difference value of the item's state between two points in time

Overloads:

  • #delta_between(start, finish, service = nil) ⇒ DecimalType, ...

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

  • #delta_between(range, service = nil) ⇒ DecimalType, ...

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

Returns:

  • (DecimalType, QuantityType, nil)

    The difference value between start and finish, or nil if no states could be found.



# File 'lib/openhab/core/items/persistence.rb', line 171

#delta_since(timestamp, service = nil) ⇒ DecimalType, ...

Returns the difference value of the item's state since the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (DecimalType, QuantityType, nil)

    The difference value since timestamp, or nil if no previous states could be found.



# File 'lib/openhab/core/items/persistence.rb', line 156

#delta_until(timestamp, service = nil) ⇒ DecimalType, ...

Returns the difference value of the item's state between now until the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (DecimalType, QuantityType, nil)

    The difference value until timestamp, or nil if no future states could be found.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 163

#deviation_between(start, finish, service = nil) ⇒ DecimalType, ... #deviation_between(range, service = nil) ⇒ DecimalType, ...

Returns the standard deviation of the item's state between two points in time

Overloads:

  • #deviation_between(start, finish, service = nil) ⇒ DecimalType, ...

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

    • riemann_type (:left, :midpoint, :right, :trapezoidal)

      An optional approximation type for Riemann sum. If nil, :left is used.

  • #deviation_between(range, service = nil) ⇒ DecimalType, ...

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

Returns:

  • (DecimalType, QuantityType, nil)

    The standard deviation between start and finish, or nil if no states could be found.

Since:

  • openHAB 5.0 riemann_type parameter added



# File 'lib/openhab/core/items/persistence.rb', line 207

#deviation_since(timestamp, service = nil, riemann_type: nil) ⇒ DecimalType, ...

Returns the standard deviation of the item's state since the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

  • riemann_type (:left, :midpoint, :right, :trapezoidal) (defaults to: nil)

    An optional approximation type for Riemann sum. If nil, :left is used.

Returns:

  • (DecimalType, QuantityType, nil)

    The standard deviation since timestamp, or nil if no previous states could be found.

Since:

  • openHAB 5.0 riemann_type parameter added



# File 'lib/openhab/core/items/persistence.rb', line 186

#deviation_until(timestamp, service = nil, riemann_type: nil) ⇒ DecimalType, ...

Returns the standard deviation of the item's state beetween now until the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

  • riemann_type (:left, :midpoint, :right, :trapezoidal) (defaults to: nil)

    An optional approximation type for Riemann sum. If nil, :left is used.

Returns:

  • (DecimalType, QuantityType, nil)

    The standard deviation until timestamp, or nil if no future states could be found.

Since:

  • openHAB 4.2

  • openHAB 5.0 riemann_type parameter added



# File 'lib/openhab/core/items/persistence.rb', line 196

#evolution_rate(start, finish_or_service = nil, service = nil) ⇒ Object

Deprecated.

OH 4.2 this method is deprecated in OH 4.2 and may be removed in a future version



# File 'lib/openhab/core/items/persistence.rb', line 350

#evolution_rate_between(start, finish, service = nil) ⇒ DecimalType? #evolution_rate_between(range, service = nil) ⇒ DecimalType?

Returns the evolution rate of the item's state between two points in time

Overloads:

  • #evolution_rate_between(start, finish, service = nil) ⇒ DecimalType?

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

  • #evolution_rate_between(range, service = nil) ⇒ DecimalType?

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

Returns:

  • (DecimalType, nil)

    The evolution rate between start and finish, or nil if no states could be found.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 387

#evolution_rate_since(timestamp, service = nil) ⇒ DecimalType?

Returns the evolution rate of the item's state since the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (DecimalType, nil)

    The evolution rate since timestamp, or nil if no previous states could be found.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 371

#evolution_rate_until(timestamp, service = nil) ⇒ DecimalType?

Returns the evolution rate of the item's state between now until the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (DecimalType, nil)

    The evolution rate until timestamp, or nil if no future states could be found.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 379

#historic_state(timestamp, service = nil) ⇒ PersistedState?

Deprecated.

In openHAB 4.2, use #persisted_state instead

Returns the the item's state at the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time at which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (PersistedState, nil)

    The item's state at timestamp, or nil if no previous state could be found.



# File 'lib/openhab/core/items/persistence.rb', line 402

#last_change(service = nil) ⇒ ZonedDateTime?

Returns the time the item was last changed.

Parameters:

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

See Also:

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 740

#last_update(service = nil) ⇒ ZonedDateTime?

Returns the time the item was last updated.

Parameters:

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

See Also:



# File 'lib/openhab/core/items/persistence.rb', line 727

#maximum_between(start, finish, service = nil) ⇒ PersistedState? #maximum_between(range, service = nil) ⇒ PersistedState?

Returns the maximum value of the item's state between two points in time

Overloads:

  • #maximum_between(start, finish, service = nil) ⇒ PersistedState?

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

  • #maximum_between(range, service = nil) ⇒ PersistedState?

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

Returns:

  • (PersistedState, nil)

    The maximum value between start and finish, or nil if no states could be found.



# File 'lib/openhab/core/items/persistence.rb', line 433

#maximum_since(timestamp, service = nil) ⇒ PersistedState?

Returns the maximum value of the item's state since the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (PersistedState, nil)

    The maximum value since timestamp, or nil if no previous states could be found.



# File 'lib/openhab/core/items/persistence.rb', line 418

#maximum_until(timestamp, service = nil) ⇒ PersistedState?

Returns the maximum value of the item's state between now until the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (PersistedState, nil)

    The maximum value until timestamp, or nil if no future states could be found.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 425

#median_between(start, finish, service = nil) ⇒ DecimalType, ... #median_between(range, service = nil) ⇒ DecimalType, ...

Returns the median of the item's state between two points in time

Overloads:

  • #median_between(start, finish, service = nil) ⇒ DecimalType, ...

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

  • #median_between(range, service = nil) ⇒ DecimalType, ...

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

Returns:

Since:

  • openHAB 4.3



# File 'lib/openhab/core/items/persistence.rb', line 240

#median_since(timestamp, service = nil) ⇒ DecimalType, ...

Returns the median of the item's state since the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

Since:

  • openHAB 4.3



# File 'lib/openhab/core/items/persistence.rb', line 224

#median_until(timestamp, service = nil) ⇒ DecimalType, ...

Returns the median of the item's state beetween now until the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

Since:

  • openHAB 4.3



# File 'lib/openhab/core/items/persistence.rb', line 232

#minimum_between(start, finish, service = nil) ⇒ PersistedState? #minimum_between(range, service = nil) ⇒ PersistedState?

Returns the minimum value of the item's state between two points in time

Overloads:

  • #minimum_between(start, finish, service = nil) ⇒ PersistedState?

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

  • #minimum_between(range, service = nil) ⇒ PersistedState?

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

Returns:

  • (PersistedState, nil)

    The minimum value between start and finish, or nil if no states could be found.



# File 'lib/openhab/core/items/persistence.rb', line 462

#minimum_since(timestamp, service = nil) ⇒ PersistedState?

Returns the minimum value of the item's state since the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (PersistedState, nil)

    The minimum value since timestamp, or nil if no previous states could be found.



# File 'lib/openhab/core/items/persistence.rb', line 447

#minimum_until(timestamp, service = nil) ⇒ PersistedState?

Returns the minimum value of the item's state between now until the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (PersistedState, nil)

    The minimum value until timestamp, or nil if no future states could be found.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 454

#next_change(service = nil) ⇒ ZonedDateTime?

Returns the first future change time of the item.

Parameters:

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

See Also:

Since:

  • openHAB 4.2



754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
# File 'lib/openhab/core/items/persistence.rb', line 754

%i[last_update next_update last_change next_change].each do |method|
  # @deprecated OH 4.1 remove this guard when dropping OH 4.1
  next unless Actions::PersistenceExtensions.respond_to?(method)

  class_eval <<~RUBY, __FILE__, __LINE__ + 1
    def #{method}(service = nil)                            # def last_update(service = nil)
      service ||= persistence_service                       #   service ||= persistence_service
      result = Actions::PersistenceExtensions.#{method}(    #   result = Actions::PersistenceExtensions.last_update(
        self,                                               #     self,
        service&.to_s                                       #     service&.to_s
      )                                                     #   )
      wrap_result(result)                                   #   wrap_result(result)
    end                                                     # end
  RUBY
end

#next_state(service = nil, skip_equal: false) ⇒ PersistedState?

Return the next state of the item

Parameters:

  • skip_equal (true, false) (defaults to: false)

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

  • service (String) (defaults to: nil)

    the name of the PersistenceService to use

Returns:

  • (PersistedState, nil)

    the previous state or nil if no previous state could be found, or if the default persistence service is not configured or does not refer to a valid service

Since:

  • openHAB 4.2



796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
# File 'lib/openhab/core/items/persistence.rb', line 796

%i[previous_state next_state].each do |method|
  # @deprecated OH 4.1 remove this guard when dropping OH 4.1
  next unless Actions::PersistenceExtensions.respond_to?(method)

  class_eval <<~RUBY, __FILE__, __LINE__ + 1
    def #{method}(service = nil, skip_equal: false)       # def previous_state(service = nil, skip_equal: false)
      service ||= persistence_service                     #   service ||= persistence_service
      result = Actions::PersistenceExtensions.#{method}(  #   result = Actions::PersistenceExtensions.previous_state(
        self,                                             #     self,
        skip_equal,                                       #     skip_equal,
        service&.to_s                                     #     service&.to_s
      )                                                   #   )
      wrap_result(result, quantify: true)                 #   wrap_result(result, quantify: true)
    end                                                   # end
  RUBY
end

#next_update(service = nil) ⇒ ZonedDateTime?

Returns the first future update time of the item.

Parameters:

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

See Also:

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 733

#persist(service = nil) ⇒ void #persist(timestamp, state, service = nil) ⇒ void #persist(time_series, service = nil) ⇒ void

Persist item state to the persistence service

Overloads:

  • #persist(service = nil) ⇒ void

    This method returns an undefined value.

    Persists the current state of the item

    Parameters:

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

  • #persist(timestamp, state, service = nil) ⇒ void

    This method returns an undefined value.

    Persists a state at a given timestamp

    Parameters:

    • timestamp (#to_zoned_date_time)

      The timestamp for the given state to be stored

    • state (Types::State, #to_s)

      The state to be stored

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

    Since:

    • openHAB 4.2

  • #persist(time_series, service = nil) ⇒ void

    This method returns an undefined value.

    Persists a time series

    Parameters:

    • time_series (Types::TimeSeries)

      The time series of states to be stored

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

    Since:

    • openHAB 4.2



672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
# File 'lib/openhab/core/items/persistence.rb', line 672

def persist(*args)
  # @deprecated OH 4.1 this if block content can be removed when dropping OH 4.1 support
  if Core.version < Core::V4_2
    raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..1)" if args.size > 1

    service = args.last || persistence_service
    Actions::PersistenceExtensions.persist(self, service&.to_s)
    return
  end

  first_arg = args.first
  if first_arg.is_a?(TimeSeries)
    if args.size > 2
      raise ArgumentError,
            "wrong number of arguments to persist a time series (given #{args.size}, expected 1..2)"
    end

    service = args[1] || persistence_service
    Actions::PersistenceExtensions.java_send :persist,
                                             [Item.java_class, Types::TimeSeries.java_class, java.lang.String],
                                             self,
                                             first_arg,
                                             service&.to_s
  elsif first_arg.respond_to?(:to_zoned_date_time)
    unless args.size.between?(2, 3)
      raise ArgumentError, "wrong number of arguments to persist a state (given #{args.size}, expected 2..3)"
    end

    timestamp = first_arg.to_zoned_date_time
    state = format_update(args[1])
    service = args[2] || persistence_service
    Actions::PersistenceExtensions.java_send :persist,
                                             [Item.java_class,
                                              ZonedDateTime.java_class,
                                              org.openhab.core.types.State,
                                              java.lang.String],
                                             self,
                                             timestamp,
                                             state,
                                             service&.to_s

  else
    if args.size > 1
      raise ArgumentError,
            "wrong number of arguments to persist the current state (given #{args.size}, expected 0..1)"
    end
    service = first_arg || persistence_service
    Actions::PersistenceExtensions.java_send :persist,
                                             [Item.java_class, java.lang.String],
                                             self,
                                             service&.to_s

  end
end

#persisted_state(timestamp, service = nil) ⇒ PersistedState?

Returns the the item's state at the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time at which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (PersistedState, nil)

    The item's state at timestamp, or nil if no state could be found.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 410

#previous_state(service = nil, skip_equal: false) ⇒ PersistedState?

Return the previous state of the item

Parameters:

  • skip_equal (true, false) (defaults to: false)

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

  • service (String) (defaults to: nil)

    the name of the PersistenceService to use

Returns:

  • (PersistedState, nil)

    the previous state or nil if no previous state could be found, or if the default persistence service is not configured or does not refer to a valid service

See Also:



# File 'lib/openhab/core/items/persistence.rb', line 770

#remove_all_states_between(start, finish, service = nil) ⇒ void #remove_all_states_between(range, service = nil) ⇒ void

This method returns an undefined value.

Removes persisted data points between two points in time.

Overloads:

  • #remove_all_states_between(start, finish, service = nil) ⇒ void

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to remove

    • finish (#to_zoned_date_time)

      The point in time to which to remove

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

  • #remove_all_states_between(range, service = nil) ⇒ void

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to remove

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 635

#remove_all_states_since(timestamp, service = nil) ⇒ void

This method returns an undefined value.

Removes persisted data points since a certain point in time.

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to remove

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 621

#remove_all_states_until(timestamp, service = nil) ⇒ void

This method returns an undefined value.

Removes persisted data points from now until the given point in time.

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to remove

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 628

#riemann_sum_between(start, finish, service = nil, riemann_type: nil) ⇒ DecimalType, ... #riemann_sum_between(range, service = nil, riemann_type: nil) ⇒ DecimalType, ...

Returns the Riemann sum of the states between two points in time.

Overloads:

  • #riemann_sum_between(start, finish, service = nil, riemann_type: nil) ⇒ DecimalType, ...

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

    • riemann_type (:left, :midpoint, :right, :trapezoidal) (defaults to: nil)

      An optional approximation type for Riemann sum. If nil, :left is used.

  • #riemann_sum_between(range, service = nil, riemann_type: nil) ⇒ DecimalType, ...

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

    • riemann_type (:left, :midpoint, :right, :trapezoidal) (defaults to: nil)

      An optional approximation type for Riemann sum. If nil, :left is used.

Returns:

  • (DecimalType, QuantityType, nil)

    The riemann sum between start and finish, or nil if no previous states could be found.

Since:

  • openHAB 5.0



# File 'lib/openhab/core/items/persistence.rb', line 602

#riemann_sum_since(timestamp, service = nil, riemann_type: nil) ⇒ DecimalType, ...

Returns the Riemann sum of the states since a certain point in time.

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

  • riemann_type (:left, :midpoint, :right, :trapezoidal) (defaults to: nil)

    An optional approximation type for Riemann sum. If nil, :left is used.

Returns:

  • (DecimalType, QuantityType, nil)

    The riemann sum since timestamp, or nil if no previous states could be found.

Since:

  • openHAB 5.0



# File 'lib/openhab/core/items/persistence.rb', line 582

#riemann_sum_until(timestamp, service = nil, riemann_type: nil) ⇒ DecimalType, ...

Returns the Riemann sum of the states between now until a certain point in time.

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

  • riemann_type (:left, :midpoint, :right, :trapezoidal) (defaults to: nil)

    An optional approximation type for Riemann sum. If nil, :left is used.

Returns:

  • (DecimalType, QuantityType, nil)

    The riemann sum until timestamp, or nil if no previous states could be found.

Since:

  • openHAB 5.0



# File 'lib/openhab/core/items/persistence.rb', line 592

#sum_between(start, finish, service = nil) ⇒ DecimalType, ... #sum_between(range, service = nil) ⇒ DecimalType, ...

Returns the sum of the item's state between two points in time

Overloads:

  • #sum_between(start, finish, service = nil) ⇒ DecimalType, ...

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

  • #sum_between(range, service = nil) ⇒ DecimalType, ...

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

Returns:



# File 'lib/openhab/core/items/persistence.rb', line 270

#sum_since(timestamp, service = nil) ⇒ DecimalType, ...

Returns the sum of the item's state since the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:



# File 'lib/openhab/core/items/persistence.rb', line 255

#sum_until(timestamp, service = nil) ⇒ DecimalType, ...

Returns the sum of the item's state between now until the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 262

#updated_between?(start, finish, service = nil) ⇒ true, false #updated_between?(range, service = nil) ⇒ true, false

Whether the item's state was updated between two points in time

Overloads:

  • #updated_between?(start, finish, service = nil) ⇒ true, false

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

  • #updated_between?(range, service = nil) ⇒ true, false

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

Returns:

  • (true, false)

    True if the item's state was updated between start and finish, False otherwise.



# File 'lib/openhab/core/items/persistence.rb', line 489

#updated_since?(timestamp, service = nil) ⇒ true, false

Whether the item's state has been updated since the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (true, false)

    True if the item's state has been updated since the given timestamp, False otherwise.



# File 'lib/openhab/core/items/persistence.rb', line 476

#updated_until?(timestamp, service = nil) ⇒ true, false

Whether the item's state will be updated between now until the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

Returns:

  • (true, false)

    True if the item's state will be updated until the given timestamp, False otherwise.

Since:

  • openHAB 4.2



# File 'lib/openhab/core/items/persistence.rb', line 482

#variance_between(start, finish, service = nil, reimann_type: nil) ⇒ DecimalType, ... #variance_between(range, service = nil, reimann_type: nil) ⇒ DecimalType, ...

Returns the variance of the item's state between two points in time

Overloads:

  • #variance_between(start, finish, service = nil, reimann_type: nil) ⇒ DecimalType, ...

    Parameters:

    • start (#to_zoned_date_time)

      The point in time from which to search

    • finish (#to_zoned_date_time)

      The point in time to which to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

    • riemann_type (:left, :midpoint, :right, :trapezoidal)

      An optional approximation type for Riemann sum. If nil, :left is used.

  • #variance_between(range, service = nil, reimann_type: nil) ⇒ DecimalType, ...

    Parameters:

    • range (Range<#to_zoned_date_time>)

      The time range to search

    • service (Symbol, String) (defaults to: nil)

      An optional persistence id instead of the default persistence service.

    • riemann_type (:left, :midpoint, :right, :trapezoidal)

      An optional approximation type for Riemann sum. If nil, :left is used.

Returns:

Since:

  • openHAB 5.0 riemann_type parameter added



# File 'lib/openhab/core/items/persistence.rb', line 305

#variance_since(timestamp, service = nil, riemann_type: nil) ⇒ DecimalType, ...

Returns the variance of the item's state since the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time from which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

  • riemann_type (:left, :midpoint, :right, :trapezoidal) (defaults to: nil)

    An optional approximation type for Riemann sum. If nil, :left is used.

Returns:

Since:

  • openHAB 5.0 riemann_type parameter added



# File 'lib/openhab/core/items/persistence.rb', line 284

#variance_until(timestamp, service = nil, riemann_type: nil) ⇒ DecimalType, ...

Returns the variance of the item's state between now until the given time

Parameters:

  • timestamp (#to_zoned_date_time)

    The point in time until which to search

  • service (Symbol, String) (defaults to: nil)

    An optional persistence id instead of the default persistence service.

  • riemann_type (:left, :midpoint, :right, :trapezoidal) (defaults to: nil)

    An optional approximation type for Riemann sum. If nil, :left is used.

Returns:

Since:

  • openHAB 4.2

  • openHAB 5.0 riemann_type parameter added



# File 'lib/openhab/core/items/persistence.rb', line 294