Spanish Total.js
Deutsch
Dokumentation Für KI-Agenten
Inhalt

Outputs and history

Define the values a device measures, how they are shown and how their history is kept.

.md Website

Diese Seite ist noch nicht übersetzt. Du liest das Original.

Auf dieser Seite

Each item of exports.outputs becomes a sensor of every device of the driver:

exports.outputs = [
    { id: 'temperature', type: 'number', name: 'Temperature', format: '{0} °C', decimals: 1, stats: 'hourly' },
    { id: 'humidity', type: 'number', name: 'Humidity', format: '{0} %', decimals: 0, stats: 'hourly' },
    { id: 'battery', type: 'number', name: 'Battery', format: '{0} %', decimals: 0, stats: 'daily' }
];

exports.offline = '2 hours';

The properties of an output

  • id: identifies the output in the driver. Send values to it by this id.
  • name: the name of the sensor. People can rename it in the Dictionary or for one device.
  • type: number, string, boolean or date.
  • format: how the value is shown. {0} is the value. A key of the device configuration in braces, such as {unit}, is replaced by its value.
  • decimals: the number of decimals shown for numbers.
  • stats: how the history is summarised: none, minutely, hourly, daily, monthly or yearly.
  • offline: how long the sensor stays online without a new value, for example '2 hours'. Without it, the output uses exports.offline.
  • category: the category of the sensor. Without it, the category is the id of the output. Categories appear in the Dictionary.

Statistics

For every value, the stream keeps the minimum, the maximum and the number of values of the interval in stats and of every longer interval. An output with stats: 'minutely' fills the minutely, hourly, daily, monthly and yearly history; hourly starts at hours. The interval can be changed for each device in the device detail.

When the timeline of a sensor is on, the stream also keeps every single value.

Send a value

instance.newmessage(21.4).send('temperature');

Write a value without statistics

instance.lastvalue(output, value) sets the last value of a sensor without adding it to the statistics:

instance.lastvalue('battery', 85);

Read the last value

instance.readvalue(output) returns a promise with the last stored value of a sensor of this device, its previous value and the time:

instance.message = async function($) {
    var last = await instance.readvalue('counter');
    // last = { value: 5, prev: null, ts: Date } or undefined
    var difference = last ? $.data.counter - last.value : 0;
    instance.newmessage($.data.counter).send('counter');
    $.destroy();
};

Numbers come back as numbers and booleans as booleans.

Hergestellt in Europa