Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Write Python scripts

Script definition

When a new script is created in the Eliona system, a function header is generated automatically. This header contains two parameters:

  • id: The unique ID of the script.

  • eliona: An object through which the user can interact with the Eliona system.

The function header looks like this:

# you may add imports only inside the function
# don't change or delete the function definition
def UserFunction(id, eliona):
	# add your code here

Importing modules

All necessary modules must be imported within the function. It is important that modules are imported only within the function and that no global imports are used.

Example:

def UserFunction(id, eliona):
    import random
    # Further lines of code follow

Methods of the Eliona object

The elionaThe object provides a range of methods that allow users to interact with the Eliona system. Here are the most important methods along with their parameters and descriptions:

Method
Parameter
Description

GetHeap

gai: str, subtype: str, attribute: str

Retrieves the current value of an attribute or the entire data JSON of an asset from the heap.

SetHeap

gai: str, subtype: str, data: dict, source: str

Sends data to the Calculator to process it and store it in the heap.

GetAssetIDByGAI

gai: str

Returns the numeric asset ID for the specified GAI.

GetAll

ids: list[intstr], subtype: str

Retrieves all data for a list of assets identified by their IDs and a subtype.

SQLQuery

query: str

Executes any SQL query and returns the results as a list of tuples.

MakeSource

id: int

Generates a source string for heap operations based on the function ID.

OpenFile

name: str, mode: str

Opens a file in the Eliona working directory (analogous to Python’s open()).

AddAssetTag

gai: str, tag: str

Adds a tag to an asset (if it is not already present).

RemoveAssetTag

gai: str, tag: str

Removes a tag from an asset (if present).

GetTrendRecords

asset_id: int, subtype: str, attr: str, begin: datetime

Retrieves historical measurements as a list of TrendRecord(ts, value) from the specified time onward.

WriteTrendRecords

asset_id: int, subtype: str, attr: str, `recs: TrendRecord

Writes one or more TrendRecordrecords to the system.

GetAggregate

agg: Aggregate, asset_id: int, subtype: str, attr: str,raster: str, start: datetime,end: datetime = now()

Calculates aggregated values (Avg, Sum, Cusum) in a fixed grid over a period.

GetLastAggregate

agg: Aggregate, asset_id: int, subtype: str, attr: str, raster: str

Returns the most recent cumulative aggregate in the selected grid (including last_ts).


Example scripts

GetHeap

Description: Retrieves the current value of an attribute or the entire JSON of an asset from the heap.

Parameters:

  • gai: str (required) – GAI of the asset, e.g. "K86_WP01"

  • subtype: str (required) – data subtype, e.g. "input"

  • attribute: str (required) – attribute name, e.g. "outside temperature"

Code example:

Example output:


SetHeap

Description: Sends a dictionary of values to the Calculator to process them and store them in the heap.

Parameters:

  • gai: str (required)

  • subtype: str (required)

  • data: dict (required) – e.g. {"outside temperature": 23.5}

  • source: str (required) – typically eliona.MakeSource(id)

Code example:


GetAssetIDByGAI

Description: Returns the numeric asset ID for the specified GAI.

Parameters:

  • gai: str (required)

Code example:


GetAll

Description: Retrieves all data points of a specific subtype for a list of assets and returns them as a dictionary (GAI → data).

Parameters:

  • ids: list[int|str] (required) – e.g. ["K86_WP01", 1073]

  • subtype: str (required)

Code example:


SQLQuery

Description: Executes any SQL query and returns the results as a list of tuples.

Parameters:

  • query: str (required)

Code example:

Example output:


MakeSource

Description: Creates a source string (e.g. "ssr:123") for heap operations based on the function ID.

Parameters:

  • id: int (required)

Code example:


OpenFile

Description: Opens a file in the Eliona working directory (analogous to Python’s open()).

Parameters:

  • name: str (required) – file name, e.g. "log.txt"

  • mode: str (required) – e.g. "w", "r"

Code example:


AddAssetTag

Description: Adds a tag to an asset if it has not already been assigned.

Parameters:

  • gai: str (required)

  • tag: str (required)

Code example:


RemoveAssetTag

Description: Removes a tag from an asset if present.

Parameters:

  • gai: str (required)

  • tag: str (required)

Code example:


GetTrendRecords

Description: Loads a list of historical measurements (TrendRecord(ts, value)) from the specified start time.

Parameters:

  • asset_id: int (required)

  • subtype: str (required)

  • attr: str (required)

  • begin: datetime (required)

Code example:


WriteTrendRecords

Description: Writes one or more TrendRecordrecords to the system.

Parameters:

  • asset_id: int (required)

  • subtype: str (required)

  • attr: str (required)

  • recs: TrendRecord | list[TrendRecord] (required)

Code example:


GetAggregate

Description: Calculates aggregated values (average, sum, cumulative sum) in a fixed grid over a period.

Parameters:

  • agg: Aggregate (required) – e.g. eliona_types.Aggregate.Avg

  • asset_id: int (required)

  • subtype: str (required)

  • attr: str (required)

  • raster: str (required) – ISO 8601 duration, e.g. "PT1H" for hourly

  • start: datetime (required)

  • end: datetime (optional, default: now())

Code example:

Example output structure:


GetLastAggregate

Description: Returns the most recent cumulative aggregate in the selected grid (including last_ts).

Parameters:

  • agg: Aggregate (required)

  • asset_id: int (required)

  • subtype: str (required)

  • attr: str (required)

  • raster: str (required)

Code example:

Example output structure:


Simple script for manipulating data

This example shows how a script generates a random value and writes it to an asset's heap:

Description:

  • The script imports the module random.

  • A dictionary data is created that contains a key power_val which is assigned a random value between 10 and 100.

  • The generated value is written using the method SetHeap into the heap of the asset TestInactIn .


Retrieve and modify data

In this example, the value of an attribute is retrieved from an asset, modified, and stored in another asset:

Description:

  • The script imports the module datetime.

  • The current value of the attribute power_val is retrieved from the heap of the asset TestInactIn .

  • This value is tripled and written as energy_val to the same asset.


Advanced functions and SQL queries

With the method SQLQuery any SQL queries can be executed directly from the script:

Description:

  • The SQL query retrieves all information about the asset with the GAI TestInactIn .

  • The result can then be processed further.

Last updated

Was this helpful?