> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Use a LoT Notebook

> Learn how to use LoT Notebooks to run, document and debug your LoT code.

<Frame caption="LoT Notebook workspace in VS Code: editor, Coreflux Explorer, Project, and Data Viewer">
  <img src="https://mintcdn.com/coreflux/XSOUAWqOWS4Y2_FQ/images/extension/extension-lotnb.png?fit=max&auto=format&n=XSOUAWqOWS4Y2_FQ&q=85&s=9e0cb958c924dad253919f3ff09f828a" alt="VS Code with a LoT notebook open showing markdown and LoT code cells, Coreflux Explorer and project tree on the left, Data Viewer below, and MQTT connection in the status bar" width="1920" height="1032" data-path="images/extension/extension-lotnb.png" />
</Frame>

## The Notebook Workflow

LoT Notebooks combine **Documentation in Markdown** and **LoT code** in a **single file**, so you can both run your code and keep your documentation together, using the notebook as **living documentation** for your project.

<Tip>
  **Picture a smart kitchen:** **Markdown** is the recipe on the page, each **LoT code** cell is how you run each step of the recipe, and the **Data Viewer** shows you the results of each step.
</Tip>

***

## Install and connect

<Steps>
  <Step title="Install the extension">
    <Frame caption="Extensions marketplace: search for Coreflux and install LoT Notebooks">
      <img src="https://mintcdn.com/coreflux/XSOUAWqOWS4Y2_FQ/images/extension/extension-installation.gif?s=3a2aa4cdbaf895e94e9954d6c45b7abf" alt="Animated walkthrough: VS Code Extensions view, search for coreflux, install Coreflux LoT, Coreflux icon appears in the Activity Bar" width="1280" height="688" data-path="images/extension/extension-installation.gif" />
    </Frame>

    1. Open VS Code.
    2. Open the Extensions view in the sidebar (or use the shortcut `Ctrl+Shift+X` on Windows/Linux, `Cmd+Shift+X` on macOS).
    3. Search for **LoT Notebooks** by **Coreflux** and install it.
  </Step>

  <Step title="Connect to the broker">
    <Frame caption="Connect to the broker: pick credentials or connect from the Data Viewer">
      <img src="https://mintcdn.com/coreflux/XSOUAWqOWS4Y2_FQ/images/extension/extension-broker-connect.gif?s=faf63084741fb786ec1807145f691a89" alt="VS Code: connect to MQTT broker via LoT extension; status bar shows MQTT connected" width="1280" height="688" data-path="images/extension/extension-broker-connect.gif" />
    </Frame>

    1. Click the **MQTT** connection status in the bottom-left of VS Code, or click **Connect to Broker** in the **Data Viewer** (Coreflux sidebar).
    2. Enter your broker **URL**, **username**, and **password**.

    <Accordion title="Example URL and default login credentials">
      Use a full URL such as `mqtt://localhost:1883` or `mqtts://your-host:8883` for TLS.

      | Setting  | Example (local defaults)                      |
      | -------- | --------------------------------------------- |
      | URL      | `mqtt://localhost:1883`                       |
      | Username | `root`                                        |
      | Password | `coreflux` (change immediately in production) |
    </Accordion>

    When you are connected, the status bar shows a green **MQTT: Connected**. If any issues occur, the status bar will become red.

    <Note>
      The extension securely stores your credentials. You only need to configure them once per workspace.
    </Note>
  </Step>
</Steps>

***

## Create a new project

<Frame caption="Creating a new LoT Notebook from the Coreflux PROJECT view">
  <img src="https://mintcdn.com/coreflux/XSOUAWqOWS4Y2_FQ/images/extension/extension-lotnb-create-new.gif?s=6f76d28d7999e12459a044e460d414bc" alt="Animated walkthrough: creating a new .lotnb file from the Coreflux PROJECT section in VS Code" width="1920" height="1032" data-path="images/extension/extension-lotnb-create-new.gif" />
</Frame>

1. In the Activity Bar, open the **Coreflux** view. Under **PROJECT**, use **New File** to create a notebook and save it in your workspace (use **New Folder** first if you want a dedicated project folder).
2. In the notebook, add **Markdown** and **LoT** cells from the toolbar as needed.

***

## Add LoT code to a LoT Notebook

<Frame caption="Insert a LoT code cell and add LoT in the notebook editor">
  <img src="https://mintcdn.com/coreflux/XSOUAWqOWS4Y2_FQ/images/extension/extension-create-basic-action.gif?s=f0a99e24fb50a62f34539d706812f912" alt="Animated walkthrough: insert a code cell in a LoT Notebook and add LoT definition text in VS Code" width="1920" height="1032" data-path="images/extension/extension-create-basic-action.gif" />
</Frame>

1. Open your LoT Notebook in VS Code.
2. From the notebook toolbar, add a **code** cell.
3. Type or paste your LoT code (`DEFINE ACTION`, `DEFINE MODEL`, and so on). For a first example, use the code below.

```lot theme={null}
DEFINE ACTION Heartbeat
ON EVERY 10 SECONDS DO
    PUBLISH TOPIC "system/heartbeat" WITH TIMESTAMP "UTC"
```

***

## What type of cells you can add to LoT Notebooks

LoT Notebooks support three types of cells, each with different behavior:

### Markdown Cells - Documentation

<Frame caption="Markdown cell with rich text and the formatting toolbar">
  <img src="https://mintcdn.com/coreflux/XSOUAWqOWS4Y2_FQ/images/extension/extension-cell-markdown.png?fit=max&auto=format&n=XSOUAWqOWS4Y2_FQ&q=85&s=7f8d6580bd483bfd9e9c53c7e6919d1b" alt="LoT Notebook markdown cell showing a heading and body text with the cell toolbar for formatting and actions" width="1037" height="287" data-path="images/extension/extension-cell-markdown.png" />
</Frame>

Markdown cells are for **documentation only**—they don't execute. Use them to:

* Explain what your code does and why
* Document configuration requirements
* Add diagrams, tables, and formatted text
* Create section headers and navigation

### LoT Code Cells - Runnable Logic

<Frame caption="LoT code cell: syntax highlighting, sync status and upload to broker buttons">
  <img src="https://mintcdn.com/coreflux/XSOUAWqOWS4Y2_FQ/images/extension/extension-cell-LoT.png?fit=max&auto=format&n=XSOUAWqOWS4Y2_FQ&q=85&s=3ced495b4d1137b78534bb83cb0a4651" alt="LoT Notebook LoT cell with TemperatureSimulator action, run button, and status bar showing Upload to broker and LOT cell type" width="1059" height="161" data-path="images/extension/extension-cell-LoT.png" />
</Frame>

LoT cells contain executable **LoT (Language of Things)** code. When you run a LoT cell:

1. The extension parses your code
2. Sends it to the connected broker via MQTT
3. The broker compiles and registers the definition
4. You receive confirmation or error feedback

For what LoT is, how it fits the broker, and more examples, see [Introduction to LoT](/lot-language/introduction).

### Python Cells - Advanced Logic

<Frame caption="Python cell with syntax highlighting, sync status and upload to broker buttons">
  <img src="https://mintcdn.com/coreflux/XSOUAWqOWS4Y2_FQ/images/extension/extension-cell-python.png?fit=max&auto=format&n=XSOUAWqOWS4Y2_FQ&q=85&s=11d0c77c5b03bb46c46c71ae0fcdf3c3" alt="LoT Notebook Python cell with Script Name header, function definitions, run button, and Python label in the status bar" width="1052" height="259" data-path="images/extension/extension-cell-python.png" />
</Frame>

Python cells contain scripts that run inside the broker when called from LoT Actions. The broker's Python runtime executes your functions.

```python theme={null}
# Script Name: DataProcessor
def calculate_average(values):
    """Calculate average from a list of numbers"""
    if not values:
        return 0
    return sum(values) / len(values)

def format_alert(sensor_id, value, threshold):
    """Generate formatted alert message"""
    return f"ALERT: Sensor {sensor_id} exceeded {threshold} with value {value}"
```

<Warning>
  Python scripts require a specific format with `# Script Name: YourScriptName` as the first line. Without this header, the script won't be recognized.
</Warning>

***

## Running LoT

<Frame caption="Deploying a LoT or Python code from the notebook to the broker">
  <img src="https://mintcdn.com/coreflux/XSOUAWqOWS4Y2_FQ/images/extension/extension-deploy-lot.gif?s=aa0c88228b7e0db8f7fe4b07c16eb513" alt="Animated walkthrough: Run on a LoT notebook cell to deploy the definition to the connected Coreflux broker" width="1920" height="1032" data-path="images/extension/extension-deploy-lot.gif" />
</Frame>

When you click the **Run** button on a cell, the Extension builds your code, checks for errors and deploys to the broker.
If successful, a simple Green response will appear. If any error is found, the code is not deployed and a error message will appear with the error details.

***

## What else you can do with the LoT extension

<Frame caption="Data Viewer basics: subscribe to topics and watch live MQTT data">
  <img src="https://mintcdn.com/coreflux/XSOUAWqOWS4Y2_FQ/images/extension/extension-data-viewer-basic.gif?s=7124718aa0d1a06105dd56a905f1a177" alt="Animated walkthrough of the LoT Data Viewer in VS Code: subscribing to topics and viewing live MQTT traffic" width="1920" height="1032" data-path="images/extension/extension-data-viewer-basic.gif" />
</Frame>

Use the **Coreflux** view (Activity Bar) for broker connection, entities, secrets, license, clients, and live MQTT—without a separate client for most tasks.

| Capability                            | Why it helps                                                                                |
| ------------------------------------- | ------------------------------------------------------------------------------------------- |
| **See what is running in the Broker** | See what Actions, Models, Routes, and Rules the broker actually has after a deploy.         |
| **Remove LoT code**                   | On Coreflux Explorer, remove one or more LoT entities.                                      |
| **Manage secrets and env vars**       | Configure the secrets within the broker, to manage secure credentials                       |
| **See license usage**                 | Spot **license limits** when deploy fails—before you debug LoT as a syntax issue.           |
| **See connected clients**             | See who is connected; useful when a device or app should be online but is not.              |
| **MQTT Data Viewer**                  | Live topics and payloads in the Data Viewer.                                                |
| **Execution Trace**                   | For a LoT cell, see it's execution history and which topics and variables that run touched. |

For more on the Data Viewer, replay, formatters, and trace, see [How to Debug in LoT Notebooks](/lot-notebooks/debug).

### Develop LoT Notebooks with AI

<Frame caption="GitHub Copilot with a LoT Notebook: chat in context of the open notebook and cells">
  <img src="https://mintcdn.com/coreflux/XSOUAWqOWS4Y2_FQ/images/extension/extension-copilot.gif?s=7fa29fa41a99c3835a27fa55fe1bf46e" alt="Animated walkthrough: VS Code with a LoT notebook open and GitHub Copilot chat focused on a notebook cell" width="1280" height="688" data-path="images/extension/extension-copilot.gif" />
</Frame>

Alongside the extension, you can develop with AI using **Copilot**, just like any programming language. For better results, you can add the **Coreflux MCP** server to the agent, so it can read official docs, and add **AGENTS.md** file for LoT coding practices, so it works like a LoT expert.

To for more details on how to use AI with LoT, check this page: [Developing with LoT Using AI](/ai/developing-with-lot).

### Version control with Git

<Frame caption="Source Control: Git tracks the whole workspace, not just LoT notebooks">
  <img src="https://mintcdn.com/coreflux/XSOUAWqOWS4Y2_FQ/images/extension/extension-project-git-management.png?fit=max&auto=format&n=XSOUAWqOWS4Y2_FQ&q=85&s=fa4ae1c74bc80b882ead08c988631d8c" alt="VS Code Source Control showing pending changes across .lotnb notebooks, docker-compose.yml, markdown, and editor config files in the same repo" width="1920" height="1032" data-path="images/extension/extension-project-git-management.png" />
</Frame>

Use **Git** on your **workspace folder** like any project: commit **`.lotnb`** files aswell as any other files, like documentation, Docker files and supporting files.

***

## Best Practices

<AccordionGroup>
  <Accordion title="Organize with Markdown">
    Use markdown cells liberally to explain your code. Future you (and teammates) will appreciate the context.
  </Accordion>

  <Accordion title="One Definition Per Cell">
    Keep each Action, Model, or Route in its own cell. This makes debugging easier and allows selective execution.
  </Accordion>

  <Accordion title="Test Incrementally">
    Run cells one at a time when developing. This helps isolate issues and understand system behavior.
  </Accordion>

  <Accordion title="Use Descriptive Names">
    Name your Actions, Models, and Routes clearly. They appear in the broker's entity lists and should be self-explanatory.
  </Accordion>
</AccordionGroup>

***

## Troubleshooting

<AccordionGroup>
  <Accordion title="Cell won't run?">
    * Check that you're connected to the broker (look for connection status in status bar)
    * Verify your credentials are correct
    * Ensure the broker is running and accessible
  </Accordion>

  <Accordion title="LoT not deployed — license limits?">
    If running a cell shows an **error** and the broker rejects the definition because you have reached a **license limit** (for example on actions, routes, or another licensed resource), deployment stops and the message under the cell should describe the limit.
    Open the **Coreflux** view in the Activity Bar and check the **Coreflux Explorer** section for your **license** status and usage so you can see what is capped and plan next steps (reduce definitions or adjust your license).
  </Accordion>

  <Accordion title="Python script not recognized?">
    * Confirm the first line is `# Script Name: YourScriptName`
    * Check for syntax errors in the Python code
    * Ensure function names match what you're calling from LoT
  </Accordion>

  <Accordion title="Entity not appearing after deployment?">
    * Check the output for error messages
    * Verify no syntax errors in your LoT code
    * Use the Coreflux Entities panel to refresh the list
  </Accordion>
</AccordionGroup>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Debug in VS Code" icon="bug" href="/lot-notebooks/debug">
    Use cell output, Coreflux Entities, and live MQTT values to fix issues.
  </Card>

  <Card title="Explore Tutorials" icon="graduation-cap" href="/lot-notebooks/tutorials">
    Work through hands-on notebooks covering Actions, Models, Routes, and Python.
  </Card>
</CardGroup>
