Skip to main content
Glama

Add an LVGL widget to a page

esphome_lvgl_add_widget
Destructive

Add an LVGL widget to an ESPHome page and save the full YAML config. Creates a .bak backup; use for widget insertion without manual editing.

Instructions

Add an LVGL widget to a page on an ESPHome device and save the whole config.

Appends {widget_type: properties} to the page's widgets list, then rewrites the entire device YAML file via yaml.dump — comments, blank lines and YAML anchors/aliases elsewhere in the file are NOT preserved. A <file>.bak copy of the previous content is written first so the original formatting can be recovered manually. Lambda callbacks (on_click, on_value_changed) are not supported here — add them manually via esphome_get_config/esphome_write_config. Calling this twice with the same arguments adds two separate widgets.

Use when: adding one widget to an existing LVGL page without hand-editing the full YAML. Not for: removing a widget — use esphome_lvgl_delete_widget; not for lambda callbacks or other structural edits — use esphome_get_config/esphome_write_config. After adding, run esphome_lvgl_validate/esphome_validate_config, then esphome_compile_device and esphome_upload_device to deploy. Returns: {"success": True, "name": ..., "bytes": ..., "backup": ..., "added": <widget_type>, "to_page": <page_id>} on success. Errors: {"error": "..."} when the file can't be found/parsed, when there is no lvgl: section, when page_id doesn't exist, or when the save itself fails ({"success": False, "error": ...}). Limits: rewrites and overwrites the whole file; only the pre-write content is recoverable, via the .bak copy.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
page_idYesLVGL page ID to add the widget to, from `esphome_lvgl_get_pages`.
propertiesYesWidget properties, e.g. {'id': ..., 'x': ..., 'y': ..., 'width': ..., 'height': ..., 'text': ..., 'value': ..., 'styles': ...}.
device_nameYesDevice name, with or without the '.yaml' suffix, e.g. 'kitchen_display'.
widget_typeYesLVGL widget type, e.g. 'label', 'button', 'slider', 'arc', 'switch', 'spinbox', 'img', 'line', 'meter'.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv0.25.1
    • addedInput schema / properties / device_name / description
      Added value: +"Device name, with or without the '.yaml' suffix, e.g. 'kitchen_display'."
    • addedInput schema / properties / page_id / description
      Added value: +"LVGL page ID to add the widget to, from `esphome_lvgl_get_pages`."
    • addedInput schema / properties / properties / description
      Added value: +"Widget properties, e.g. {'id': ..., 'x': ..., 'y': ..., 'width': ..., 'height': ..., 'text': ..., 'value': ..., 'styles': ...}."
    • addedInput schema / properties / widget_type / description
      Added value: +"LVGL widget type, e.g. 'label', 'button', 'slider', 'arc', 'switch', 'spinbox', 'img', 'line', 'meter'."
  2. Addedv0.18.2

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well beyond the destructive/non-idempotent annotations: discloses that the entire YAML is rewritten via yaml.dump with comments, blank lines and anchors lost, that a .bak backup is written first, that lambda callbacks are unsupported, and that a second identical call appends a second widget. This is exactly the operational detail an agent needs before a destructive write.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The critical data-loss warning is front-loaded in the first paragraph, followed by clean Use-when/Not-for/Returns/Errors/Limits blocks. It is longer than strictly necessary, but every block carries distinct information and no sentence is wasted.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers the full lifecycle for a destructive mutation: side effects, recovery path, unsupported cases, the exact success payload, the error conditions, and the recommended validate/compile/upload follow-up. An agent can call this correctly without consulting any other source.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all four parameters including property examples and device_name suffix behavior. The description adds only the `{widget_type: properties}` append shape, which is marginal given the schema's coverage — baseline 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Names a specific verb+resource ('Add an LVGL widget to a page on an ESPHome device') and states the persistence side effect ('save the whole config'). It distinguishes itself from sibling esphome_lvgl_delete_widget by naming it directly.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicit 'Use when' / 'Not for' sections name the alternatives for each excluded case (esphome_lvgl_delete_widget, esphome_get_config/esphome_write_config) and even chain the follow-up validation and deploy tools. Nothing is left to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools