Templates are useful for creating multiple assets with the same configuration. Generally, templates are created and used in ExoSense, but there is a way to create assets associated with a template via GraphQL so that you are able to automate the creation of these templated assets.
To do this we will be using the createAssetFromT
mutation. Below is a sample you can use to get started:
mutation createAssetFromT($newAsset: Asset2Create, $templateId: ID, $templateVersionId: ID, $group_id: ID!, $channelMapping: [ChannelMapping]) {
createAssetFromT(newAsset: $newAsset, templateId: $templateId, templateVersionId: $templateVersionId, group_id: $group_id, channelMapping: $channelMapping) {
id
name
}
}
We will need to get the channelMapping
array set to get the signals to actually populate with device data, otherwise you will end up with an asset with no real data coming in on any of the signals.
Here is an example of the variables for reference:
{
"newAsset": {
"description": "Asset from GQL",
"name": "GQL Asset"
},
"templateId": "{TemplateID}",
"group_id": "{groupID}",
"channelMapping": [
{
"from": "{signal_name}",
"to": "{connector_ID}.{Device ID}.data_in.{channel}"
},
...
]
}
The description
and name
can be whatever you’d like them to be.
The templateId
is the ID of the template that we are using to create the asset.
The group_id
is where you’d like the asset to be placed after it is created.
For the channelMapping
array, the from: "{signal_name}"
should be the root signal name (not any transforms/linkages) from the template. Referencing the image below, we would be using Discharge Pressure_s
and Suction Pressure_s
to replace the {signal_name}
.
For the “to” section of the channelMapping, this is where you would enter the device that should be the source of the data for the asset we’re creating. The {connector_ID}
is the ID for your source device that the asset should be using. The {Device ID}
is the Device ID of the source device for the asset. The {data_in}
should remain unchanged. Finally, the {channel}
is the device’s channel IDs for the asset’s respective channels.
I hope this guide was helpful but please feel free to comment below or reach out to support@exosite.com with any questions!