Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Description

This example shows how to convert values of Datapoints between different units e.g.(from Watt to KW). The conversion can be handled with LUA function. The output value can be written to any selected item(Virtual items or VAR\Real items). The function reads the incoming values and converts them into any related measurement

Creating a new LUA function

...

Afterwards, you can select the "nxaDefinitions.lua" to open the main LUA file. Paste in the following code at the end of the file: 


Code Block
languageapplescript
titleLUA
function converter()
	local var=nxa.GetValue(nxa.SourceItemID())
	local cal= var/1000 --conversion factor e.g. (1000 W will convertet to 1 Kw) 
	nxa.SetDestinationValue(cal)
end

After having finished the LUA implementation, save LUA function and restart the LUA engine using the buttons within the toolbar of the LUA script editor.

Image Added

Next, define a server task that is triggert upon changes of the source item, "NETx\XIO\BACnet\NetXBACnet\Electricity_usage\Electricity_usage"  – That is, to send data the LUA function is invoked: the source item value is converted into Kw and sent to the Destination Item "NETx\VAR\Real\Item001".