> 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="/files/oqQeF5g7JzSL0K9KIaqz" 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="/files/BZCbaO6JogAnNjSfRAp9" alt=""><figcaption><p>Set initial values</p></figcaption></figure></div>

## if

<div align="left"><figure><img src="/files/lqqVJRzF2nJEQXGDyThL" 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="/files/O94aoWrBWGowB9FdgIG0" 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="/files/QaLC5ew5oKL7YzC7WrSH" 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="/files/T7BmcXot7A0QRedQyC08" alt=""><figcaption></figcaption></figure></div>

## comparison

<div align="left"><figure><img src="/files/V6SaYqzJFanrKobm9kgj" 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="/files/49SkOB2IO8jkKFOc9UKu" alt=""><figcaption><p>Check humidity and send event when it is too high</p></figcaption></figure></div>

## and

<div align="left"><figure><img src="/files/CDLc8txGFqV5bAZ5iTkx" 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="/files/5bu4kPL9wRP0qstQVXmS" alt=""><figcaption><p>Multiple condition check</p></figcaption></figure></div>

## or

<div align="left"><figure><img src="/files/YDtOrTy9tiyetrlBhcdh" 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="/files/SpPmfmN4v4iXp2mOjMoi" alt=""><figcaption><p>Humidity alert</p></figcaption></figure></div>

## not

<div align="left"><figure><img src="/files/hfHGYi04PTOKUOAHw0He" 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="/files/u8iNpEmr5cGZhOXYb6wr" alt=""><figcaption><p>Toggle state by button click</p></figcaption></figure></div>


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.uniot.io/platform/sandbox/visual-editor/logic.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
