> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/hypersim/automation-api-and-scripting/hypersim-api-references/sensor.md).

# Sensor

## Function: editSensor

| **Section**    | **Description**                                                                                                                                                                                                                                                                                                                                                         |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Action**     | Edit device sensor                                                                                                                                                                                                                                                                                                                                                      |
| **Parameters** | <p><strong>blocName</strong> (<em>str</em>) – device name<br><strong>sensorName</strong> (<em>str</em>) – sensor name<br><strong>IOType</strong> (<em>str</em>) – IO Type. ex: AD, DA, DI or DO<br><strong>IONumber</strong> (<em>int</em>) – IO number<br><strong>base</strong> (<em>float</em>) – base value<br><strong>unit</strong> (<em>str</em>) – unit value</p> |
| **Returns**    | Error value (int)                                                                                                                                                                                                                                                                                                                                                       |
| **Raises**     | **AssertionError** – Raises exception on error                                                                                                                                                                                                                                                                                                                          |

### **Example Usage**

{% code overflow="wrap" lineNumbers="true" %}

```python
HyWorksApi.editSensor('R1', 'Ia', 1.0, 'pu', 'DA', 1001)
HyWorksApi.editSensor('R1', 'Ia', base = 1.0, unit = 'pu')
HyWorksApi.editSensor('R1', 'Ia', IOType = 'DA', IONumber = 1001)
```

{% endcode %}

## Function: getLastSensorValues

| **Section**    | **Description**                                                              |
| -------------- | ---------------------------------------------------------------------------- |
| **Action**     | Gets the last current value of a list of sensors while simulation is running |
| **Parameters** | **sensorNames** (*list\[str]*) – list of sensor names as string              |
| **Returns**    | Values in the same order as the sensor names (list\[float])                  |
| **Raises**     | **AssertionError** – Raises exception on error                               |

### **Example Usage**

{% code overflow="wrap" lineNumbers="true" %}

```python
HyWorksApi.getLastSensorValues(['Const1.y', 'Subcircuit1/Gain1.u', "/Subcircuit1/R15.Ia"])
```

{% endcode %}

## Function: getSensorInfo

| **Section**     | **Description**                                                                                                                                          |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Action**      | Get value for the specified key on the specified sensor                                                                                                  |
| **Parameters**  | <p><strong>blocName</strong> (<em>str</em>) – device name<br><strong>sensorName</strong> (<em>str</em>) – sensor name<br><strong>key</strong> (\*str</p> |
| Supported keys: |                                                                                                                                                          |

* 'selected'
* 'userName'
* 'userUnit'
* 'iotype'
* 'ionum'
* 'iofactor'
* 'base'
* 'dataLoggerRecord'
* 'dataLoggerGroup'
* 'dataLoggerTrigger'
* 'exchangerTag'
* 'dataPointName'
* 'dataPointIndex'\*) – key in sensor inf. | | **Returns** | Value of the specified key (str) | | **Raises** | None |

## Function: getSensorsValues

| **Section**    | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Action**     | Retrieves recorded time-series values for one or more sensors, captured during simulation.                                                                                                                                                                                                                                                                                                                                                                                                              |
| **Parameters** | <p><strong>sensorNames</strong> (<em>List\[str]</em>) – list of sensor names<br><strong>timeLength</strong> (<em>float</em>) – duration in seconds of the data to retrieve<br><strong>timeStart</strong> (<em>float</em>) – start time in seconds (Default: 0)<br><strong>acquisitionRate</strong> (<em>float</em>) – sampling rate for the returned data<br><strong>sync</strong> (<em>bool</em>) – whether to synchronize the acquisition rate<br><strong>trig</strong> (<em>bool</em>) – trigger</p> |
| **Returns**    | Tuple of the sensor values and the corresponding time (tuple\[list\[float], list\[float]])                                                                                                                                                                                                                                                                                                                                                                                                              |
| **Raises**     | **AssertionError** – Raises exception on error                                                                                                                                                                                                                                                                                                                                                                                                                                                          |

### **Example Usage**

{% code overflow="wrap" lineNumbers="true" %}

```python
signals = HyWorksApi.getSensorsValues(["I1.I", "I2.I", "I3.I", "Bus_pert.Va", "Bus_pert.Vb", "Bus_pert.Vc"], timeLength=0.1, trig=True)
```

{% endcode %}

## Function: loadSensors

| **Section**    | **Description**                                         |
| -------------- | ------------------------------------------------------- |
| **Action**     | Load sensor file to current model                       |
| **Parameters** | **filePath** (*str*) – path to sensor file (.sig, .csv) |
| **Returns**    | Error value (bool)                                      |
| **Raises**     | **AssertionError** – Raises exception on error          |

## Function: selectAllSensors

| **Section**    | **Description**                                |
| -------------- | ---------------------------------------------- |
| **Action**     | Select all sensors for device                  |
| **Parameters** | **blocName** (*str*) – device name             |
| **Returns**    | Error value (int)                              |
| **Raises**     | **AssertionError** – Raises exception on error |

## Function: selectSensor

| **Section**    | **Description**                                                                                                                                                                   |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Action**     | Select device sensor                                                                                                                                                              |
| **Parameters** | <p><strong>blocName</strong> (<em>str</em>) – device name<br><strong>sensorName</strong> (<em>str</em>) – sensor name<br><strong>selected</strong> (<em>bool</em>) – selected</p> |
| **Returns**    | Error value (int)                                                                                                                                                                 |
| **Raises**     | **AssertionError** – Raises exception on error                                                                                                                                    |

## Function: setSensorDataLogger

| **Section**    | **Description**                                                                                                                                                                                                                                                                                                                         |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Action**     | Set sensor parameter through datapoints                                                                                                                                                                                                                                                                                                 |
| **Parameters** | <p><strong>blocName</strong> (<em>str</em>) – device name<br><strong>sensorName</strong> (<em>str</em>) – sensor name<br><strong>record</strong> (<em>bool</em>) – record signal<br><strong>groupName</strong> (<em>str</em>) – signal group name<br><strong>trigger</strong> (<em>bool</em>) – set signal as trigger for the group</p> |
| **Returns**    | Error value (int)                                                                                                                                                                                                                                                                                                                       |
| **Raises**     | **AssertionError** – Raises exception on error                                                                                                                                                                                                                                                                                          |

### **Example Usage**

{% code overflow="wrap" lineNumbers="true" %}

```python
HyWorksApi.setSensorDataLogger('sine1', 'y', True, 'SIGNAL_GROUP_1', False)
HyWorksApi.setSensorDataLogger('sine2', 'y', True, 'SIGNAL_GROUP_2', True)
HyWorksApi.setSensorDataLogger('sine3', 'y', False, 'SIGNAL_GROUP_3', False)
```

{% endcode %}

## Function: setSensorDataPoint

| **Section**    | **Description**                                                                                                                                                                                                                                                                                                                 |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Action**     | Set sensor parameter through datapoints                                                                                                                                                                                                                                                                                         |
| **Parameters** | <p><strong>blocName</strong> (<em>str</em>) – device name<br><strong>sensorName</strong> (<em>str</em>) – sensor name<br><strong>exchangerTag</strong> (<em>str</em>) – exchanger tag<br><strong>dataPointName</strong> (<em>str</em>) – data point name<br><strong>dataPointIdx</strong> (<em>str</em>) – data point index</p> |
| **Returns**    | Error value (int)                                                                                                                                                                                                                                                                                                               |
| **Raises**     | **AssertionError** – Raises exception on error                                                                                                                                                                                                                                                                                  |

### **Example Usage**

{% code overflow="wrap" lineNumbers="true" %}

```python
HyWorksApi.setSensorDataPoint('Const_Amplitude', 'y', 'Signal Generator', 'Sine Waves/Sine Wave 1/Amplitude', '0')
HyWorksApi.setSensorDataPoint('Const_Frequency', 'y', 'Signal Generator', 'Sine Waves/Sine Wave 1/Frequency', '0')
HyWorksApi.setSensorDataPoint('Gain', 'u', 'Signal Generator', 'Sine Waves/Sine Wave 1/Output', '0')
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/hypersim/automation-api-and-scripting/hypersim-api-references/sensor.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
