# 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-1ea3d3e17ca773e59b6a66b94ea28cef1c269b99%2Flogic_value.png?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-b535450c24bcacf682bb74eef4288b68e71e0d95%2Flogic_value_example.png?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-e81d6dc94ef7c1eab18c4385f52741d0bb08d6b2%2Flogic_if.png?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-737b12c2a406667aeb31c07e2bf417413406adfe%2Flogic_if_example.png?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-d9bba888cd4234f17a962c760cdc2efc883a38e5%2Flogic_if_settings.png?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-726c1e336edf194ff1573c7f7467662a0155fd6f%2Flogic_comparsion.png?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-900159ff04d1e38447927939589f9e22ec2054cb%2Flogic_comparison_example.png?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-ba01c938f3fc5f88c67e45e6c8e13bfe94cb0d58%2Flogic_operation_and.png?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-a610ab90c7094266411a1cca67dfc4fa8c4da2c5%2Flogic_operation_and_example.png?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-4be4d138223994fd19137729b14df127d919b31d%2Flogic_operation_or.png?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-ef803d6a4b82d42516d80bb81c008907b52e0eac%2Flogic_operation_or_example.png?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-65223efaa928863fa5161fa31bc9d23acc7a2428%2Flogic_not.png?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-bf9440074dc06d5b002a18bd2cbf3c45b94e3339%2Flogic_not_example.png?alt=media" alt=""><figcaption><p>Toggle state by button click</p></figcaption></figure></div>
