---
title: "Referencia inštancie"
project: IoT Platform
version: 1.0
section: development
language: sk
translation: missing
license: Total.js Enterprise
url: https://totaljs.es/docs/sk/iot/1-0/development/instance-api/
updated: 2026-11-20T06:56:18.114Z
---

# Referencia inštancie

> The handlers, functions and properties of a device in exports.make.

The instance is one device of the driver. `exports.make` receives it, and you define its handlers there:

```js
exports.make = function(instance, config) {

	instance.message = function($) {
		$.destroy();
	};

};
```

Entries of type **event** are functions that you define and the stream calls. Entries of type **method** are functions that the stream provides.

## API

### instance.message = function($) {}

Type: `event`

Receives the data and the commands of the device.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `$` | `Object` | yes |  | Správa. |

`$.data` is the data, `$.input` the id of the input. End every message with `$.destroy()`.

Example: Send a value to an output
```js
instance.message = function($) {
	if ($.data.temperature != null)
		instance.newmessage($.data.temperature).send('temperature');
	$.destroy();
};
```

### instance.notify = function(req) {}

Type: `event`

Receives the requests sent to the notify address of the device.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `req` | `Object` | yes |  | The request with `method`, `body`, `query`, `headers`, `ip` and `url`. |

The address is `/notify/stream-<device id>/` on the stream. See [Receiving data](../receiving-data/).

Example: Pass posted data on
```js
instance.notify = function(req) {
	if (req.method === 'POST')
		instance.message(instance.newmessage(req.body));
};
```

### instance.newmessage(data)

Type: `method`

Creates a message.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `data` | `Object` | yes |  | The data of the message. |

Returns: `Object` Správa.

Send it to an output with `.send(output)`, or hand it to the device with `instance.message(msg)`.

Example: Send a value
```js
instance.newmessage(21.4).send('temperature');
```

### instance.lastvalue(output, value)

Type: `method`

Sets the last value of a sensor without adding it to the statistics.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `output` | `String` | yes |  | The id of the output. |
| `value` | `Object` | yes |  | The value. |

Example: Set the battery level
```js
instance.lastvalue('battery', 85);
```

### await instance.readvalue(output)

Type: `method`

Reads the last stored value of a sensor of this device.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `output` | `String` | yes |  | The id of the output. |

Returns: `Promise` An object `{ value, prev, ts }`, or `undefined` when the sensor has no value yet.

Numbers, booleans and dates come back in their type.

Example: Compare with the last value
```js
var last = await instance.readvalue('counter');
var difference = last ? $.data.counter - last.value : 0;
```

### instance.throw(message)

Type: `method`

Creates an alert for the device.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `message` | `String` | yes |  | The text of the alert. |

The alert appears on the **Alerts** screen. See [Alerts and debugging](../alerts-and-debugging/).

Example: A low battery
```js
instance.throw('Battery low: ' + data.battery + ' %');
```

### instance.debug(a, [b], [c], [d])

Type: `method`

Writes a line to logs/debugger.log of the stream.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `a` | `Object` | yes |  | The first value. |
| `b` | `Object` | no |  | More values. |

The stream writes the collected lines once a minute.

Example: Log a command
```js
instance.debug('Interval changed to', $.data.minutes, 'minutes');
```

### instance.storage.insert(table, data)

Type: `property`

Inserts a row into a storage table of the driver.

See [Storage](../storage/).

Example: Keep a reading
```js
instance.storage.insert('readings', { sn: data.sn, temperature: 21.4 });
```

### instance.id

Type: `property`

The id of the device.

The id shown in the device detail and on the status page of the stream.

### instance.component

Type: `property`

The id of the driver of the device.

### instance.meta

Type: `property`

The device: `sn`, `name`, `locality`, `lat`, `lng` and `reference`.

`instance.meta.sn` is the **Device identifier**.

### instance.config

Type: `property`

The configuration of the device, the same object as `config` in `exports.make`.

### instance.module

Type: `property`

The driver. `instance.module.options` holds its options.
