> For the complete documentation index, see [llms.txt](https://docs.akenza.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.akenza.io/device-management/rule-engine/logic-blocks/rule-logic.md).

# Comparison

Compare device data to a constant or to the last sample of a device.

The **Comparison** logic block compares values from device data samples. It needs no code and consists of two sections:

* **Data sources** define which values the block reads.
* **Conditions** define how those values are compared.

<figure><img src="https://2165942204-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MMKXTFIN5ZlLOjBlfC4%2Fuploads%2FlKCfj9Bta12VJjuN1L9z%2Fscreely-1685032940954.png?alt=media&amp;token=4d88b708-6c1e-44cb-b452-2274a2b1e277" alt="A comparison logic block with a data source and a condition comparing it to a constant value"><figcaption><p>A comparison logic block</p></figcaption></figure>

## Data sources

A data source selects a **topic** of the incoming data samples and the **data key** to read from them. Only samples with that topic trigger the block. Use `*` to match all topics.

If the data flow of the device has a [device type](/device-management/your-data-flow/device-type.md) with a schema, you can choose the data key from the schema. Otherwise, enter the topic and data key by hand.

A comparison needs at least one data source. Add more if the conditions need more values. The same device can be assigned to several data sources, one for each key you want to evaluate.

{% hint style="info" %}
To find the topic and data key of a sample, open the **Message Logs** on the [device detail view](/device-management/create-new-device/devices.md).
{% endhint %}

<figure><img src="https://2165942204-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MMKXTFIN5ZlLOjBlfC4%2Fuploads%2F4brHHuTGm24JZzYF2sPT%2Fscreely-1685032863646.png?alt=media&amp;token=444d1f0f-8f11-458b-b636-715305dfde8a" alt="The message logs of a device showing the topic and the data keys of a sample"><figcaption><p>Topic and data keys in the message logs</p></figcaption></figure>

## Conditions

A condition compares a data source, with a comparison operator, to either:

* a **constant number**, or
* the **latest sample** of another data source.

Click the blue text to switch between `is` and `is not`. Use the **plus** button to nest another comparison inside a condition.

Conditions are independent of each other. Each condition that evaluates to true triggers the actions linked to it.

{% hint style="info" %}
If a comparison is not enough, use a [Custom Logic](/device-management/rule-engine/logic-blocks/custom-logic.md) block.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.akenza.io/device-management/rule-engine/logic-blocks/rule-logic.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
