> For the complete documentation index, see [llms.txt](https://docs.widgelix.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.widgelix.com/asset-templates/editing-an-asset-template.md).

# Editing an Asset Template

The asset template editor: About, uplink and downlink codecs, data fields, tags, list widgets, additional parameters, MQTT and widgets.

To open the template editor, click the template name on the [Asset Templates](/asset-templates/asset-templates-list.md) page, or select **Edit template** in the row menu.

All settings of the template are shown on one page. Use the navigation on the left (**About**, **Uplink data**, **Downlink data**, **Tags**, **List widgets**, **Parameters**, **MQTT**, **Widgets**) to jump to a section.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FfiFVux5N5OEiMew9ymNk%2Fat-edit-about.jpg?alt=media&amp;token=5807f4ee-9a5d-44a8-9d93-749cfba7c83c" alt="Asset template editor"><figcaption><p>Asset template editor, About section</p></figcaption></figure>

## Header actions

| Button              | Action                                                                              |
| ------------------- | ----------------------------------------------------------------------------------- |
| **Back (<)**        | Returns to the Asset Templates list.                                                |
| **Show JSON**       | Shows the whole template as JSON at the bottom of the page. Click again to hide it. |
| **Copy to account** | Copies the template to another organization (account) you have access to.           |
| **Save changes**    | Saves all changes. The button becomes active as soon as you change something.       |

{% hint style="warning" %}
Changes are not saved automatically. Click **Save changes** before leaving the page.
{% endhint %}

## About

General information about the device model:

* **Name**: the template name shown in lists and when adding assets.
* **Manufacturer**: the device manufacturer. Used by the **Manufacturer** filter.
* **Description**: what the device is and what it is used for.
* **Manufacturer website**: a link to the product page.
* **Connectivity**: the supported protocols, e.g. `LoRaWAN`, `Sigfox`. Shown as badges in the list and used by the **Protocol** filter.
* **Map Marker**: the icon used for assets of this template on maps and in lists. Click the button to choose another icon.
* **Image**: a picture of the device. Click the image area to upload or replace it, **×** removes it.

## Uplink data

The **uplink decoder** converts the raw payload sent by the device into named values.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FtAZitapgqYkkosOkMa84%2Fat-edit-uplink.jpg?alt=media&amp;token=2a20f2ae-ed95-4184-bca2-4526456aca06" alt="Uplink decoder"><figcaption><p>Uplink decoder with test payload</p></figcaption></figure>

* **Code**: the decoder in JavaScript. It must contain a `decode(payload, data)` function that returns an object with the decoded values. `payload` is the payload as a HEX string; `data.meta` contains network metadata such as `type`, `rssi`, `snr`, `gatewayEui`, `fPort` and `fCnt`. Click **Fullscreen** to edit long decoders.
* **Test payload**: paste a HEX payload and click **Run**. The decoded result appears in **Output**.

```javascript
function decode(payload, data) {
  for (var bytes = [], c = 0; c < payload.length; c += 2) {
    bytes.push(parseInt(payload.substr(c, 2), 16))
  }
  return {
    temperature: ((bytes[0] << 8) | bytes[1]) / 10,
    humidity: bytes[2]
  }
}
```

### Data fields

Data fields define which decoded values Widgelix stores and shows. The counter next to the title shows the number of fields.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2F5uemas3Rm3A1jrMcO2AM%2Fat-edit-fields.jpg?alt=media&amp;token=0096f5be-e8dd-4086-9f58-e9ff0fd960be" alt="Uplink data fields"><figcaption><p>Uplink data fields</p></figcaption></figure>

| Column      | Description                                                  |
| ----------- | ------------------------------------------------------------ |
| **Name**    | The key exactly as returned by the decoder, e.g. `channelA`. |
| **Units**   | Unit of measurement, e.g. `Volts`, `°C`, `%`.                |
| **Min/Max** | Optional expected range, used e.g. by gauges and charts.     |
| **×**       | Removes the field.                                           |

* **Add field**: adds an empty row.
* **Load from payload**: paste a decoded JSON object, and all its keys are added as fields at once. Then set units and ranges manually.
* **Take device id from payload**: read the device ID from a decoded field instead of the network metadata.
* **Take position from payload**: read latitude and longitude from decoded fields, for devices with GPS.

## Downlink data

The **downlink encoder** converts a JSON command into the binary payload sent to the device. This section is optional.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FskBBnpd48VMeXboEKeJt%2Fat-edit-downlink.jpg?alt=media&amp;token=3fb32d57-19da-4d20-af0c-8ad33f1bdbed" alt="Downlink encoder"><figcaption><p>Downlink encoder, data fields and tags</p></figcaption></figure>

* **Code**: the encoder in JavaScript. It receives the JSON command and returns the payload as a HEX string.
* **Test payload**: paste a JSON command and click **Run** to see the encoded HEX in **Output**.
* **Data fields**: the parameters of the command. Enter a **Name** and an optional **Comment**, then click **+ Add**. These fields are used by the [Downlink Button](/get-started/widgets/downlink-button.md) widget and on the asset [Downlinks](/assets/asset-page/downlinks.md) tab.

## Tags

Tags let you group and tell apart assets of this template by their attributes. In the template you define the tag names; the values are then set on each asset.

Typical examples:

* **Location**: `floor`, `room`, `address`.
* **Installation place**: where the sensor is mounted, e.g. `installed in` with values like *supply duct*, *server rack*, *north wall*.
* **Measured object**: what exactly the sensor measures, e.g. `measures` with values like *boiler 2*, *main line*, *freezer A*.

To add a tag, click **Add tag**, enter its name and press `Enter`. The counter shows how many tags the template has.

Tag values are set on the asset [Meta](/assets/asset-page/meta.md) tab. You can then filter the [Assets list](/assets/assets-list.md) by a tag value and show one tag under the asset name (see **Meta tag** in List widgets below).

### Personalized alerts in Actions

Every tag of the template is available as a **placeholder** in [Actions](/actions-formerly-rule-engine/introduction.md) messages. When an action fires, the placeholder is replaced with the tag value of the asset that triggered it.

This lets you set up **one action for hundreds of devices at once**: instead of creating a separate rule for every sensor, you create one action for the whole template, and each alert still tells the recipient exactly which device it is, where it is installed and what it measures.

{% hint style="success" %}
Example message: `[Device_Name] on floor [floor], room [room] reported [Value] °C`

Result: *Sensor 117 on floor 3, room 305 reported 28.4 °C*
{% endhint %}

See [Action Types & Placeholders](/actions-formerly-rule-engine/action-types-and-placeholders.md) for the full list of placeholders.

## List widgets

Defines what the [Assets list](/assets/assets-list.md) shows for every asset of this template.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2F5Cr78nCXIIu4G7tMQVXb%2Fat-edit-list-widgets.jpg?alt=media&amp;token=04b1f847-ca2f-43e9-acef-7e21b27f00f5" alt="List widgets"><figcaption><p>List widgets</p></figcaption></figure>

* **Fields to show**: up to 3 data fields shown in the **Last values** column.
* **Sparkline**: a trend of the last 24 uplinks under a field. Bars suit discrete values (states, detections, counts).
* **Battery indicator**: shows the battery level in the **Battery** column.
* **Meta tag**: a tag shown under the asset name when its value is set on the asset, e.g. `room: 1020`.
* **Preview**: shows how a sample asset will look in the list.

See [List Widgets](/assets/list-widgets.md) for details.

## Additional parameters

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FDKUz49xB1ggsSYyVZ5uR%2Fat-edit-params.jpg?alt=media&amp;token=8330271b-1d44-47f4-afd5-c5e65a592f18" alt="Additional parameters and MQTT"><figcaption><p>Additional parameters and MQTT</p></figcaption></figure>

* **Take radio parameters from payload**: RSSI and SNR are read from the decoded payload instead of the network metadata. Enter the field names for RSSI and SNR.
* **Take battery parameters from payload**: the battery level is read from the decoded payload and converted to percent. Enter the battery field name and, where requested, the battery type, capacity and power consumption per cycle.

## MQTT

**Enable MQTT connectivity**: publish uplinks of assets of this template and accept downlinks over the platform MQTT broker.

## Widgets

The widgets shown on the [Dashboard](/assets/asset-page/dashboard.md) tab of every asset of this template. In the editor, widgets show `NaN` because there is no live data.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2F76xJeIRU1s7x6ae11auK%2Fat-edit-widgets.jpg?alt=media&amp;token=e1552541-347c-4a9a-9fa9-d6776354fb7b" alt="Template widgets in edit mode"><figcaption><p>Widgets in edit mode</p></figcaption></figure>

Turn on the **Edit** switch to change the layout:

* **+ Add Widget**: adds a widget. See [Widgets](/get-started/widgets.md) for all widget types and their settings.
* **⚙** on a widget: opens its settings.
* Drag a widget to move it, drag its bottom right corner to resize it.

Turn the **Edit** switch off when you are done and click **Save changes**.

## Deleting a template

In the left navigation, under **Danger zone**, click **Delete template** and confirm. The template is removed from the organization. This cannot be undone.

{% hint style="info" %}
If you only have **Viewer** rights, you cannot edit or delete asset templates.
{% endhint %}
