Virtual sensors produce data based on scripts, made in the script editor.
We recommend you first make your sensors in the normal way, before creating scripts. Scripts can then be accessed on the machine page in the Admin app. The drop down panel shows any existing scripts (1.). By clicking on these the script editor is opened. Alternatively you can click on the (2.) icon and click on the "Add script" menu option, to add a new script.
When creating a new script, the script editor will appear as shown in the image below.
(3.) The drop down switcher allows you to easily move from one script to another. If you've made changes you'll be warned to save these before switching.
(4.) When you start a new script, you should assign a title and description. Keep these short and unique. In the description, briefly explain what the script is for.
(5a.) Here you need to select the associated sensor(s). As shown in the image below (5b.) you need to tick the checkbox of the output sensor(s). A script requires at least 1 output sensor, which can be either a virtual sensor or a manual sensor. Input sensors can be of any type.
A sensor alias is automatically generated, based on your sensor names. You can change this, but it can only start with a letter, not a number. The alias is how you should refer to the sensor in the script itself.
To start editing a new script (6a.) or an existing one (6b.) you need to click in the editor area. For more information about the script language refer to this article: The script language. See the script examples as a reference as well: Script examples.
As you can see from the difference between (7a.) above and (7b.) below, the buttons are enabled and disabled based on the edit status of the script. Once you have written some script, or edited an existing one the "Cancel" and "Save buttons" become available.
Clicking the "Cancel" button cancels any unsaved changes. Clicking "Save" will save the script. Saving allows you to leave the script editor and return to continue editing the script another time. It does not activate the script. Once a script has been saved and has no errors, it can be activated by pushing the "Activate" button.
The "Test" button is always available and clicking it will test the script for errors. If errors are found, a dialog box will indicate on which line the error has been found. Correct these errors and then test it again, until no errors are found. You must remove all errors before your script can be activated.
The script version history is an archive of all the active versions of the script (8.). This way, sensor data can be viewed in the light of what the script was doing at any given time.
Once a script has been activated, it will receive a time stamp in the version history. Any previously active scripts will become inactive and move down the list. Historic script versions can be viewed by clicking on them, but cannot themselves be deleted, edited, or reactivated. However, when viewing a previous script version, it can be edited and then saved and activated as a new version.
Scripts can be activated and deactivated using the toggle button in the top right of the screen (9.).
The menu button in the top right (10.) gives the option to "Edit Script", which is another way to activate the script text area in edit mode. There is also the option "Duplicate script", which will create a new script based on the current one. It will copy the sensors, and script text, but requires a new name and description.
Lastly, there is the option to "Delete script".