Skip to content

The Template Subsystem

The template subsystem provides powerful tools for normalizing data in batches against a set of patterns.

At its core, templates are simply CSV files containing a list of input rules to match against points in the database, and a set of output rules about attributes to apply to the matching points.

Example Template

The simplest way to start understanding templates is with an example:

$in.device_id $in.object_id $out.class $out.name
260001 av.1 Zone_Air_Temperature_Sensor Room Temperature
260001 av.2 Zone_Airflow_Sensor Room {device_prop_object_name} Airflow
260001 /bv.(?<id>[3-4])/ Proprietary Zone Status {id}

Rows in the header starting with $in contain match rules against attributes in the input layer. In this example, the first two rules contain exact matches against input attributes -- for instance, the first line matches any point where device_id is exactly 260001 and the object_id is av.1. The third example contains a regular expression rule with a named capture group, which matches both bv.3 and bv.4.

Rows in the header beginning with $out are output rules and alter attributes on the output layer. While there are no restrictions on which names can be used, there are certain convensions listed in the appendix.

String interpolation is performed on output rules, where values enclosed by braces ({}) are replaced by matching variables. Variables may reference either attributes of the input object, or named capture groups from regular expressions in the input rules.

Template Execution

In general, the template engine will track changes made to templates and rerun them as needed so that attributes in the output layer always reflect the latest template. Additionally, the template engine will watch changes to the input layer when the template is active and rerun the template each time points change.

Using the Template Editor

The NF console contains support for building and running templates directly in the console. Templates can be created using the Object Selection interface to find a set of objects such as a single device, and then using the context menu there to create a template.

The template editor includes a "preview" functionality -- hitting the "play" button next to each row runs that rule on the input layer and displays up to 3 matching rows in the preview pane, to help understand any variable substitutions.

The Template Editor

Appendix 1: Output Attribute Naming Conventions

Attribute name Description Example Value
class Brick class name Zone_Air_Temperature
label Value of RDF label A string description
haystack Comma-separated list of Haystack marker tags zone,air,temp,sensor
equipRef A NF URL referring to the equipment object nf://f591b85e-0761-11ed-a8f7-73fd0c8dcdeb