> For the complete documentation index, see [llms.txt](https://docs.uniot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uniot.io/platform/sandbox/visual-editor/logic.md).

# Logic

Logic blocks enable decision-making in your scripts. Use these blocks to compare values, create conditional behaviors, combine multiple conditions, and control program flow based on device states.

## value

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-ea21c2f83a5bbde2d9fe167aaa0dad698a1ca52b%2Flogic_value.svg?alt=media" alt=""><figcaption></figcaption></figure></div>

A boolean constant that represents true or false. Use this block to provide boolean values to conditions, comparisons, or variables.

**Parameters:**

* **Value** (Boolean): Select `true` or `false`

**Returns:**

* **Boolean**: `#t` for true, `()` for false (Lisp values)

**Example:**

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-0c0e1b8fb11b498148b670aa6b918fa470f8ee46%2Flogic_value_example.svg?alt=media" alt=""><figcaption><p>Set initial values</p></figcaption></figure></div>

## if

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-94f3e5bfa641fd9d0b069dc7af1be25f36cd4da6%2Flogic_if.svg?alt=media" alt=""><figcaption></figcaption></figure></div>

Executes code conditionally based on whether a condition is true. This is the fundamental building block for creating decision-based behavior in your scripts.

**Parameters:**

* **Condition** (Boolean): The condition to evaluate

**Example:**

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-2e3f75f06b77fba2976d8ea59988f567ca1af57e%2Flogic_if_example.svg?alt=media" alt=""><figcaption><p>Send event if button was clicked</p></figcaption></figure></div>

### Adding else if and else Clauses

The basic `if` block can be extended with additional conditions and fallback logic. Click the gear icon to open the configuration panel:

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-6f5ef564b9501807ec2f06b1cf40c5dbf9aa14dd%2Flogic_if_settings.svg?alt=media" alt=""><figcaption></figcaption></figure></div>

Drag `else if` and `else` blocks from the left panel to build your conditional logic. You can add multiple `else if` clauses but only one `else` clause. Reorder or remove clauses as needed, then click the gear icon to close:

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-742242e3be7602de9f141da5afddedd440a36164%2Flogic_if_settings2.gif?alt=media" alt=""><figcaption></figcaption></figure></div>

## comparison

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-90187fd998e8bbe8ad893155726564e2d267c12d%2Flogic_comparison.svg?alt=media" alt=""><figcaption></figcaption></figure></div>

Compares two values using mathematical or equality operators. Use this to check sensor thresholds, compare states, or validate ranges.

**Parameters:**

* **Left Value** (Number): The first value to compare
* **Operator**: Choose from `=` (equal), `≠` (not equal), `<` (less than), `>` (greater than), `≤` (less or equal), `≥` (greater or equal)
* **Right Value** (Number): The second value to compare

**Returns:**

* **Boolean**: `#t` (true) if the comparison is satisfied, `()` (false) otherwise

**Example:**

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-5a401ae4fb2a7884d3ad4d170c0711ae7d6aa7b1%2Flogic_comparison_example.svg?alt=media" alt=""><figcaption><p>Check humidity and send event when it is too high</p></figcaption></figure></div>

## and

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-3005907f8c18e2134ca43f37000768592db7d262%2Flogic_operation_and.svg?alt=media" alt=""><figcaption></figcaption></figure></div>

Returns true only if both conditions are true. Use this to combine multiple requirements that must all be satisfied.

**Parameters:**

* **Input A** (Boolean): The first condition
* **Input B** (Boolean): The second condition

**Returns:**

* **Boolean**: `#t` (true) if both inputs are true, `()` (false) otherwise

**Example:**

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-c1eaea0bc261ceaa757589b75b527a0da36fbf88%2Flogic_operation_and_example.svg?alt=media" alt=""><figcaption><p>Multiple condition check</p></figcaption></figure></div>

## or

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-724e3c9edb44195dfea0cb4028a2892beb8bf867%2Flogic_operation_or.svg?alt=media" alt=""><figcaption></figcaption></figure></div>

Returns true if at least one condition is true. Use this when any of several conditions should trigger an action.

**Parameters:**

* **Input A** (Boolean): The first condition
* **Input B** (Boolean): The second condition

**Returns:**

* **Boolean**: `#t` (true) if at least one input is true, `()` (false) otherwise

**Example:**

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-87506bffecbb43aa28aebf96b080dd85ce2809f5%2Flogic_operation_or_example.svg?alt=media" alt=""><figcaption><p>Humidity alert</p></figcaption></figure></div>

## not

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-389be8db6dd876886890738e8ad8f41d1b7f12fa%2Flogic_not.svg?alt=media" alt=""><figcaption></figcaption></figure></div>

Inverts a boolean value, turning true into false and false into true. Use this to reverse conditions or check for the opposite of a state.

**Parameters:**

* **Input** (Boolean): The boolean value to invert

**Returns:**

* **Boolean**: `#t` (true) becomes `()` (false), and vice versa

**Example:**

<div align="left"><figure><img src="https://1776027180-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsSE1iwGRAGqUrb5YXfFa%2Fuploads%2Fgit-blob-1dc6da4c57b8272b9a1f8e1a19f80e074b1aab77%2Flogic_not_example.svg?alt=media" alt=""><figcaption><p>Toggle state by button click</p></figcaption></figure></div>
