[comment]: # translation:outdated

[comment]: # ({new-1910d8fa})
# 7 Prediction functions

All functions listed here are supported in:

-   [Trigger expressions](/manual/config/triggers/expression)
-   [Calculated items](/manual/config/items/itemtypes/calculated)

Some general notes on function parameters:

-   Function parameters are separated by a comma
-   Optional function parameters (or parameter parts) are indicated by
    `<` `>`
-   Function-specific parameters are described with each function
-   `/host/key` and `(sec|#num)<:time shift>` parameters must never be
    quoted

[comment]: # ({/new-1910d8fa})

[comment]: # ({new-4d343eb8})
##### Common parameters

-   `/host/key` is a common mandatory first parameter for the functions
    referencing the host item history
-   `(sec|#num)<:time shift>` is a common second parameter for the
    functions referencing the host item history, where:
    -   **sec** - maximum [evaluation
        period](/manual/config/triggers#evaluation_period) in seconds
        (time [suffixes](/manual/appendix/suffixes) can be used), or
    -   **\#num** - maximum [evaluation
        range](/manual/config/triggers#evaluation_period) in latest
        collected values (if preceded by a hash mark)
    -   **time shift** (optional) allows to move the evaluation point
        back in time. See [more
        details](/manual/config/triggers/expression#time_shift) on
        specifying time shift.

[comment]: # ({/new-4d343eb8})

[comment]: # ({new-e6aa7a7c})
#### Prediction functions

|FUNCTION|<|<|<|
|--------|-|-|-|
|<|**Description**|**Function-specific parameters**|**Comments**|
|**forecast** (/host/key,(sec\|\#num)<:time shift>,time,<fit>,<mode>)|<|<|<|
|<|Future value, max, min, delta or avg of the item.|See [common parameters](#common-parameters).<br><br>**time** - forecasting horizon in seconds (time suffixes can be used); negative values are supported<br><br>**fit** (optional; must be double-quoted) - function used to fit historical data<br><br>Supported `fits`:<br>*linear* - linear function<br>*polynomialN* - polynomial of degree N (1 <= N <= 6)<br>*exponential* - exponential function<br>*logarithmic* - logarithmic function<br>*power* - power function<br><br>Note that:<br>*linear* is default, *polynomial1* is equivalent to *linear*<br><br>**mode** (optional; must be double-quoted) - demanded output<br><br>Supported `modes`:<br>*value* - value (default)<br>*max* - maximum<br>*min* - minimum<br>*delta* - *max*-*min*<br>*avg* - average<br><br>Note that:<br>*value* estimates item value at the moment `now` + `time`<br>*max*, *min*, *delta* and *avg* investigate item value estimate on the interval between `now` and `now` + `time`|Supported value types: float, int<br><br>If value to return is larger than 1.7976931348623157E+308 or less than -1.7976931348623157E+308, return value is cropped to 1.7976931348623157E+308 or -1.7976931348623157E+308 correspondingly.<br><br>Becomes unsupported only if misused in expression (wrong item type, invalid parameters), otherwise returns -1 in case of errors.<br><br>Examples:<br>=> **forecast**(/host/key,**\#10**,**1h**) → forecast item value in one hour based on the last 10 values<br>=> **forecast**(/host/key,**1h**,**30m**) → forecast item value in 30 minutes based on the last hour data<br>=> **forecast**(/host/key,**1h:now-1d**,**12h**) → forecast item value in 12 hours based on one hour one day ago<br>=> **forecast**(/host/key,**1h**,**10m**,"exponential") → forecast item value in 10 minutes based on the last hour data and exponential function<br>=> **forecast**(/host/key,**1h**,**2h**,"polynomial3","max") → forecast the maximum value the item can reach in the next two hours based on last hour data and cubic (third degree) polynomial<br>=> **forecast**(/host/key,**\#2**,**-20m**) → estimate the item value 20 minutes ago based on the last two values (this can be more precise than using last(), especially if item is updated rarely, say, once an hour)<br><br>See also additional information on [predictive trigger functions](/manual/config/triggers/prediction).|
|**timeleft** (/host/key,(sec\|\#num)<:time shift>,threshold,<fit>)|<|<|<|
|<|Time in seconds needed for an item to reach a specified threshold.|See [common parameters](#common-parameters).<br><br>**threshold** - value to reach ([unit suffixes](/manual/appendix/suffixes) can be used)<br><br>**fit** (optional; must be double-quoted) - see forecast()|Supported value types: float, int<br><br>If value to return is larger than 1.7976931348623157E+308, return value is cropped to 1.7976931348623157E+308.<br><br>Returns 1.7976931348623157E+308 if threshold cannot be reached.<br><br>Becomes unsupported only if misused in the expression (wrong item type, invalid parameters), otherwise returns -1 in case of errors.<br><br>Examples:<br>=> **timeleft**(/host/key,**\#10**,**0**) → time until the item value reaches zero based on the last 10 values<br>=> **timeleft**(/host/key,**1h**,**100**) → time until the item value reaches 100 based on the last hour data<br>=> **timeleft**(/host/key,**1h:now-1d**,**100**) → time until the item value reaches 100 based on one hour one day ago<br>=> **timeleft**(/host/key,**1h**,**200**,"polynomial2") → time until the item value reaches 200 based on the last hour data and assumption that the item behaves like quadratic (second degree) polynomial<br>See also additional information on [predictive trigger functions](/manual/config/triggers/prediction).|

[comment]: # ({/new-e6aa7a7c})
