Aller au contenu principal

Initializers

The initializers section sets initial values for variable nodes. These values are embedded in the generated NodeSet2.xml and loaded by the OPC UA server on startup.

Initializers can be placed either inside an instance (scoped to that instance) or at the top level of the model (using full paths).


Setting initial values

Setting initial values
instances:
- browseName: Sensor1
typeDefinition: SensorType
organizedBy: /ua:Objects
initializers:
- variable: Temperature
value: 22.5
- variable: Pressure
value: 1013.25

Accessing properties of an AnalogItemType variable

Use . to reach the properties (e.g. EURange, EngineeringUnits) of a variable node:

AnalogItemType property path
instances:
- browseName: Sensor2
typeDefinition: SensorType
organizedBy: /ua:Objects
initializers:
- variable: Level
value: 75.0
- variable: Level.ua:EngineeringUnits
value: "%"

Engineering units shorthand

For AnalogItemType-based variables, engineeringUnits accepts a plain unit string — no need to write out the full UNECE record:

Engineering units shorthand
instances:
- browseName: Sensor3
typeDefinition: SensorType
organizedBy: /ua:Objects
initializers:
- variable: Level
value: 42.0
engineeringUnits: "%"
- variable: Temperature
value: 23.5
engineeringUnits: "°C"

Top-level initializers (full path syntax)

Top-level initializers: uses the full InstanceName/VariableName path. Useful for keeping instance declarations and initial values in clearly separate sections:

Top-level initializers
initializers:
- variable: Sensor1/Temperature
value: 18.0
- variable: Sensor1/Pressure
value: 1005.0

Duplicate path detection

The LSP server detects duplicate variable: paths within the same initializers: block and reports a DSL-E error. Each variable path must appear at most once.


📄 Full working example — initializers.model.yaml
# yaml-language-server: $schema=../../../../schemas/nodeset2.schema.json
#
# Living documentation example for: s66_initializers.md
# Validate: opcua-modeler generate --input initializers.model.yaml
#
namespaceUri: http://example.com/doc-examples/initializers/
namespaces:
- di
version: 1.0.0

objectTypes:
- browseName: SensorType
components:
- browseName: Temperature
dataType: ua:Double
- browseName: Pressure
dataType: ua:Double
- browseName: Level
dataType: ua:Double
typeDefinition: ua:AnalogUnitRangeType

instances:
- browseName: Sensor1
typeDefinition: SensorType
organizedBy: /ua:Objects
initializers:
- variable: Temperature
value: 22.5
- variable: Pressure
value: 1013.25

- browseName: Sensor2
typeDefinition: SensorType
organizedBy: /ua:Objects
initializers:
- variable: Level
value: 75.0
- variable: Level.ua:EngineeringUnits
value: "%"

- browseName: Sensor3
typeDefinition: SensorType
organizedBy: /ua:Objects
initializers:
- variable: Level
value: 42.0
engineeringUnits: "%"
- variable: Temperature
value: 23.5
engineeringUnits: "°C"

initializers:
- variable: Sensor1/Temperature
value: 18.0
- variable: Sensor1/Pressure
value: 1005.0
📄 Generated NodeSet2.xml — initializers.model.Nodeset2.xml
initializers.model.Nodeset2.xml
<?xml version="1.0"?>
<UANodeSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd" xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd" xmlns:ns1="http://example.com/doc-examples/initializers/Type.xsd">
<NamespaceUris>
<Uri>http://example.com/doc-examples/initializers/</Uri>
</NamespaceUris>
<Models>
<Model ModelUri="http://example.com/doc-examples/initializers/" Version="1.0.0" PublicationDate="2026-05-26T09:24:00.000Z">
<RequiredModel ModelUri="http://opcfoundation.org/UA/" Version="1.05.06" PublicationDate="2025-11-08T00:00:00.000Z"/>
</Model>
</Models>
<Aliases>
<Alias Alias="Double">i=11</Alias>
<Alias Alias="HasComponent">i=47</Alias>
<Alias Alias="HasModellingRule">i=37</Alias>
<Alias Alias="HasProperty">i=46</Alias>
<Alias Alias="HasSubtype">i=45</Alias>
<Alias Alias="HasTypeDefinition">i=40</Alias>
<Alias Alias="Organizes">i=35</Alias>
<Alias Alias="Range">i=884</Alias>
</Aliases>
<!--ReferenceTypes-->
<!--ObjectTypes-->
<!--ObjectType - 1:SensorType {{{{ -->
<UAObjectType NodeId="ns=1;i=1000" BrowseName="1:SensorType">
<DisplayName>SensorType</DisplayName>
<References>
<Reference ReferenceType="HasSubtype" IsForward="false">i=58</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=1001</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=1002</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=1003</Reference>
</References>
</UAObjectType>
<UAVariable NodeId="ns=1;i=1001" BrowseName="1:Temperature" ParentNodeId="ns=1;i=1000" AccessLevel="3" DataType="Double">
<DisplayName>Temperature</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="HasModellingRule">i=78</Reference>
</References>
</UAVariable>
<UAVariable NodeId="ns=1;i=1002" BrowseName="1:Pressure" ParentNodeId="ns=1;i=1000" AccessLevel="3" DataType="Double">
<DisplayName>Pressure</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="HasModellingRule">i=78</Reference>
</References>
</UAVariable>
<UAVariable NodeId="ns=1;i=1003" BrowseName="1:Level" ParentNodeId="ns=1;i=1000" AccessLevel="3" DataType="Double">
<DisplayName>Level</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=2368</Reference>
<Reference ReferenceType="HasModellingRule">i=78</Reference>
<Reference ReferenceType="HasProperty">ns=1;i=1004</Reference>
</References>
</UAVariable>
<UAVariable NodeId="ns=1;i=1004" BrowseName="EURange" ParentNodeId="ns=1;i=1003" AccessLevel="3" DataType="Range">
<DisplayName>EURange</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
<Reference ReferenceType="HasModellingRule">i=78</Reference>
</References>
<Value>
<ExtensionObject xmlns="http://opcfoundation.org/UA/2008/02/Types.xsd">
<TypeId>
<Identifier>i=885</Identifier>
</TypeId>
<Body>
<Range>
<Low>-1</Low>
<High>1</High>
</Range>
</Body>
</ExtensionObject>
</Value>
</UAVariable>
<!--ObjectType - 1:SensorType }}}}-->
<!--VariableTypes-->
<!--Other Nodes-->
<!--Object - 1:Sensor1 {{{{ -->
<UAObject NodeId="ns=1;i=1005" BrowseName="1:Sensor1">
<DisplayName>Sensor1</DisplayName>
<References>
<Reference ReferenceType="Organizes" IsForward="false">i=85</Reference>
<Reference ReferenceType="HasTypeDefinition">ns=1;i=1000</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=1006</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=1007</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=1008</Reference>
</References>
</UAObject>
<UAVariable NodeId="ns=1;i=1006" BrowseName="1:Temperature" ParentNodeId="ns=1;i=1005" AccessLevel="3" DataType="Double">
<DisplayName>Temperature</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
<Value>
<uax:Double>18</uax:Double>
</Value>
</UAVariable>
<UAVariable NodeId="ns=1;i=1007" BrowseName="1:Pressure" ParentNodeId="ns=1;i=1005" AccessLevel="3" DataType="Double">
<DisplayName>Pressure</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
<Value>
<uax:Double>1005</uax:Double>
</Value>
</UAVariable>
<UAVariable NodeId="ns=1;i=1008" BrowseName="1:Level" ParentNodeId="ns=1;i=1005" AccessLevel="3" DataType="Double">
<DisplayName>Level</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=2368</Reference>
<Reference ReferenceType="HasProperty">ns=1;i=1009</Reference>
</References>
</UAVariable>
<UAVariable NodeId="ns=1;i=1009" BrowseName="EURange" ParentNodeId="ns=1;i=1008" AccessLevel="3" DataType="Range">
<DisplayName>EURange</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
</References>
<Value>
<ExtensionObject xmlns="http://opcfoundation.org/UA/2008/02/Types.xsd">
<TypeId>
<Identifier>i=885</Identifier>
</TypeId>
<Body>
<Range>
<Low>-1</Low>
<High>1</High>
</Range>
</Body>
</ExtensionObject>
</Value>
</UAVariable>
<!--Object - 1:Sensor1 }}}} -->
<!--Object - 1:Sensor2 {{{{ -->
<UAObject NodeId="ns=1;i=1010" BrowseName="1:Sensor2">
<DisplayName>Sensor2</DisplayName>
<References>
<Reference ReferenceType="Organizes" IsForward="false">i=85</Reference>
<Reference ReferenceType="HasTypeDefinition">ns=1;i=1000</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=1011</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=1012</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=1013</Reference>
</References>
</UAObject>
<UAVariable NodeId="ns=1;i=1011" BrowseName="1:Temperature" ParentNodeId="ns=1;i=1010" AccessLevel="3" DataType="Double">
<DisplayName>Temperature</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
</UAVariable>
<UAVariable NodeId="ns=1;i=1012" BrowseName="1:Pressure" ParentNodeId="ns=1;i=1010" AccessLevel="3" DataType="Double">
<DisplayName>Pressure</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
</UAVariable>
<UAVariable NodeId="ns=1;i=1013" BrowseName="1:Level" ParentNodeId="ns=1;i=1010" AccessLevel="3" DataType="Double">
<DisplayName>Level</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=2368</Reference>
<Reference ReferenceType="HasProperty">ns=1;i=1014</Reference>
</References>
</UAVariable>
<UAVariable NodeId="ns=1;i=1014" BrowseName="EURange" ParentNodeId="ns=1;i=1013" AccessLevel="3" DataType="Range">
<DisplayName>EURange</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
</References>
<Value>
<ExtensionObject xmlns="http://opcfoundation.org/UA/2008/02/Types.xsd">
<TypeId>
<Identifier>i=885</Identifier>
</TypeId>
<Body>
<Range>
<Low>-1</Low>
<High>1</High>
</Range>
</Body>
</ExtensionObject>
</Value>
</UAVariable>
<!--Object - 1:Sensor2 }}}} -->
<!--Object - 1:Sensor3 {{{{ -->
<UAObject NodeId="ns=1;i=1015" BrowseName="1:Sensor3">
<DisplayName>Sensor3</DisplayName>
<References>
<Reference ReferenceType="Organizes" IsForward="false">i=85</Reference>
<Reference ReferenceType="HasTypeDefinition">ns=1;i=1000</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=1016</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=1017</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=1018</Reference>
</References>
</UAObject>
<UAVariable NodeId="ns=1;i=1016" BrowseName="1:Temperature" ParentNodeId="ns=1;i=1015" AccessLevel="3" DataType="Double">
<DisplayName>Temperature</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
</UAVariable>
<UAVariable NodeId="ns=1;i=1017" BrowseName="1:Pressure" ParentNodeId="ns=1;i=1015" AccessLevel="3" DataType="Double">
<DisplayName>Pressure</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
</UAVariable>
<UAVariable NodeId="ns=1;i=1018" BrowseName="1:Level" ParentNodeId="ns=1;i=1015" AccessLevel="3" DataType="Double">
<DisplayName>Level</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=2368</Reference>
<Reference ReferenceType="HasProperty">ns=1;i=1019</Reference>
</References>
</UAVariable>
<UAVariable NodeId="ns=1;i=1019" BrowseName="EURange" ParentNodeId="ns=1;i=1018" AccessLevel="3" DataType="Range">
<DisplayName>EURange</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
</References>
<Value>
<ExtensionObject xmlns="http://opcfoundation.org/UA/2008/02/Types.xsd">
<TypeId>
<Identifier>i=885</Identifier>
</TypeId>
<Body>
<Range>
<Low>-1</Low>
<High>1</High>
</Range>
</Body>
</ExtensionObject>
</Value>
</UAVariable>
<!--Object - 1:Sensor3 }}}} -->
</UANodeSet>