# Thing Model

A thing model is a digital description of device capabilities with three element types — properties, services, and events — unifying data semantics between devices and the platform. Both device-reported and platform-delivered payloads are keyed by thing model identifiers.

## Page Guide

- **What This Page Covers**: The three thing-model elements and data types, the define-and-publish flow, identifier rules and value conventions, and common troubleshooting.
- **Use Cases**: For users who have created a product and need to define the device data model before connecting devices.
- **Prerequisites**: A product has been created; work in the Thing Model tab on the product detail page.
- **Acceptance Criteria**: The thing model is published, identifiers match the device-side code, and reported data displays correctly on the platform.

## Three Elements

| Type | Description | Example |
|------|-------------|---------|
| **Property** | Device state data (read/write or read-only) | temperature, humidity, switch state |
| **Service** | Operations the device can execute | restart, set temperature |
| **Event** | Notifications from device | alarm, fault |

## Data Types

| Type | Description |
|------|-------------|
| int | 32-bit integer |
| float | Single-precision floating point |
| double | Double-precision floating point |
| bool | Boolean (0/1) |
| enum | Enumeration with predefined values |
| text | String |
| date | Date and time |
| struct | Structure with nested sub-properties |
| array | Array |

## Define the Model

1. Go to Product Detail > **Thing Model** tab
2. Click **Add** and choose Property / Service / Event
3. Enter the identifier (in English, used in MQTT topics), name, and data type
4. Set the value range, step, unit, and so on
5. Click **Publish** to activate the thing model

::: warning
Connected devices must reconnect to load updated thing models.
:::

Take a "temperature" property as an example: identifier `temperature`, data type float, range -40~125, unit ℃, read-only. The device reports by identifier:

```json
[{
  "id": "temperature",
  "value": "25.6",
  "remark": ""
}]
```

## Identifier Rules

* All identifiers are unique within a product; use letters and digits and avoid special characters
* Sub-property identifiers of a struct (object type) use the `parentId_childId` format
* Array identifiers start with `array_index` (a two-digit index, e.g. `array_00_power_switch`), and array length must not exceed 100

## Value Conventions

* `value` is always passed as a string
* bool uses `"0"` / `"1"`
* enum uses the predefined enumeration keys
* array values are separated by commas

## Thing Model Templates

The platform includes built-in templates for common models (such as temperature & humidity, light, and switches); you can pick a template for quick import when creating a product.

## Related Documentation

* [Product Management](https://www.fastbee.cn/doc/en/open/v2/manual/product.md)
* [Device Management](https://www.fastbee.cn/doc/en/open/v2/manual/device.md)
* [MQTT Access](https://www.fastbee.cn/doc/en/open/v2/quickstart/mqtt.md)

## FAQ

### Why doesn't the updated thing model take effect on the device?

After modifying a thing model, you must click **Publish** again for it to take effect. Connected devices need to reconnect (or restart) to load the latest model. If it still doesn't work, check whether the device is bound to the product.

### Why is reported property data not shown on the platform?

Check that the `id` in the reported payload exactly matches the thing model identifier (case-sensitive), and that the data type can be converted by the platform — for example, bool only accepts 0/1.

### What is the difference between properties, functions, and events?

A property describes device state (such as temperature or switch status) and can be read-write or read-only; a function is an operation command sent from the platform to the device (such as reboot); an event is a notification proactively reported by the device (such as an alarm). The three differ in MQTT topics and payload structure.
