Skip to main content

read_history_at_time

Given a set of discrete time points, the server returns the value at that time: use_simple_bounds=True use the most recent actual value, or linear False interpolation (the server must support this). Used for "timestamp alignment":

Preliminary / Supporting

Signature​

def read_history_at_time(self,
node_id: str,
times: List[datetime],
use_simple_bounds: bool = True) -> List[OpcUaDataValue]: ...
ParametersDefaultNote
node_id—Target NodeId; Empty string exception ValueError
times—List of discrete time points (UTC datetime); None Throws an exception ValueError; returns the empty list directly []
use_simple_boundsTrueTrue = Use the most recent actual value; False = Linear interpolation (must be supported by the server)

Returns List[OpcUaDataValue], length may beLess thantimes The length (no value is returned for times not covered by the server); when aligning, simply zip use in the order of return. dispose() Free each element using with dv: or.

Usage​

import datetime as dt

# Temperatures at every hour on the hour over the past 24 hours
today_midnight = dt.datetime.now(dt.timezone.utc).replace(
hour=0, minute=0, second=0, microsecond=0)
hours = [today_midnight + dt.timedelta(hours=h) for h in range(25)]

values = ua.read_history_at_time("ns=2;s=Temperature", hours)
for t, dv in zip(hours, values):
with dv:
print(f"{t.strftime('%H:%M')}: {dv.value}")

Difference from dispose()​

APIReturn
read_history_at_timeEach time point corresponds to an interpolated value (not aggregated)
read_history_processedOne aggregate value (Avg / Min / Max / ...) per subinterval

Example: "Pull data for 24 hours, one value per hour":

  • read_history_at_time: Enter 25 data points, one value per data point (the nearest actual value or a linearly interpolated value), up to 25 in total
  • read_history_processed: aggregate=Average, interval=1h, returns the average of 24 intervals

Use Cases​

  • Temporal Alignment: Different sensors have different sampling times; they must be synchronized to the same point in time to be compared.
  • Database Export: On-the-hour sampling
  • Reports: 24 lines per day

Next Step​