Skip to main content
Glama
homeassistant-ai

Home Assistant MCP Server

Official

Evaluate Template

ha_eval_template
Read-onlyIdempotent

Render Home Assistant Jinja2 templates or test automation conditions to calculate values from live states and validate logic before use in automations.

Instructions

Execute a Jinja2 template render, or an automation condition check, in Home Assistant.

Renders templates with Home Assistant's template engine (all states, functions and filters available), or checks a condition block the way an automation would and returns true/false.

When to use: any one-shot answer DERIVED from current HA state (an average across sensors, a count of entities matching a condition, a rendered message with live values), and testing a template or condition before embedding it in an automation. One render beats fetching N states and doing the math yourself.

When NOT to use: a plain single-entity value is ha_get_state / ha_search. Templates in automation condition: / trigger: positions or templated action names: prefer native constructs, which are validated at config load, where a template only errors at runtime and a non-truthy render is silently false — see ha_get_skill_guide for the anti-pattern list. Test the native condition here with condition.

Results: a render that works but hits something suspect (an undefined variable, a missing attribute) still returns its result with the messages in warnings; strict=true makes those hard errors. A failed render returns Home Assistant's error text and, with the ha_mcp_tools component installed, the template line and source_line it failed on when the error names one.

EXAMPLES:

  • ha_eval_template(template="{{ states.light | selectattr('state', 'eq', 'on') | list | count }}")

  • ha_eval_template(template="Hello {{ name }}", variables={"name": "Alice"})

  • ha_eval_template(condition={"condition": "numeric_state", "entity_id": "sensor.temperature", "above": 20})

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
strictNoTemplate only: fail on undefined variables instead of rendering them as empty (reported in warnings when report_errors is on)
timeoutNoTemplate only: maximum render time in seconds
templateNoJinja2 template to render. Omit when using 'condition'.
conditionNoAutomation condition to test instead of a template, e.g. {'condition': 'numeric_state', 'entity_id': 'sensor.temp', 'above': 20}. Test several at once with {'condition': 'and', 'conditions': [...]}.
variablesNoVariables available to the template or condition, e.g. sample trigger data: {'trigger': {'to_state': {'state': 'on'}}}
report_errorsNoTemplate only: have Home Assistant report render errors and warnings. With false, a failed render is only written to Home Assistant's log.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed12 schema fields changedv8.6.0
    • addedInput schema / properties / condition
      Added value: +{
      +  "anyOf": [
      +    {
      +      "additionalProperties": true,
      +      "type": "object"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "Automation condition to test instead of a template, e.g. {'condition': 'numeric_state', 'entity_id': 'sensor.temp', 'above': 20}. Test several at once with {'condition': 'and', 'conditions': [...]}."
      +}
    • addedInput schema / properties / report_errors / description
      Added value: +"Template only: have Home Assistant report render errors and warnings. With false, a failed render is only written to Home Assistant's log."
    • addedInput schema / properties / strict
      Added value: +{
      +  "default": false,
      +  "description": "Template only: fail on undefined variables instead of rendering them as empty (reported in warnings when report_errors is on)",
      +  "type": "boolean"
      +}
    • addedInput schema / properties / template / anyOf
      Added value: +[
      +  {
      +    "type": "string"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
    • addedInput schema / properties / template / default
      Added value: +null
    • addedInput schema / properties / template / description
      Added value: +"Jinja2 template to render. Omit when using 'condition'."
    • removedInput schema / properties / template / type
      Removed value: -"string"
    • addedInput schema / properties / timeout / description
      Added value: +"Template only: maximum render time in seconds"
    • addedInput schema / properties / timeout / maximum
      Added value: +60
    • addedInput schema / properties / timeout / minimum
      Added value: +1
    • addedInput schema / properties / variables
      Added value: +{
      +  "anyOf": [
      +    {
      +      "additionalProperties": true,
      +      "type": "object"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "Variables available to the template or condition, e.g. sample trigger data: {'trigger': {'to_state': {'state': 'on'}}}"
      +}
    • removedInput schema / required
      Removed value: -[
      -  "template"
      -]
  2. First observedv7.14.2

TDQS

A4.7/5.0
Behavior4/5

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

Annotations already declare readOnly/idempotent/non-destructive, so the safety burden is covered. The description still adds real behavioral context: warnings on suspect renders, strict turning them into hard errors, failed renders returning HA error text plus line/source_line, and the condition-testing mode. Some of this (warnings, strict) overlaps the schema, but the return-on-partial-failure behavior is genuine added value.

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

Conciseness5/5

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

Front-loaded with the core action, then labeled sections (When to use / When NOT to use / Results / EXAMPLES) make it scannable. Every sentence carries information; nothing is padding.

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?

An output schema exists, so return format need not be explained, and the description covers the remaining gaps: two operating modes, error/warning behavior, timeout/strict semantics via schema, and cross-references to sibling tools. Nothing an agent needs to invoke it correctly is missing.

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

Parameters4/5

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

Schema coverage is 100%, so the baseline is 3. The examples go beyond the schema by showing concrete usage of template, variables (with sample trigger data) and condition (including the 'and' combinator), which clarifies how the parameters interrelate and that template/condition are mutually exclusive.

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?

States a specific verb (execute/render) and two concrete resources (Jinja2 template, automation condition) in Home Assistant, and explicitly contrasts with the plain-value siblings ha_get_state / ha_search. An agent can distinguish this from every sibling without opening a schema.

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?

Contains explicit 'When to use' and 'When NOT to use' sections, names the alternatives (ha_get_state, ha_search, native constructs, ha_get_skill_guide for anti-patterns) and gives the heuristic 'one render beats fetching N states'. This is the full when/when-not/alternatives pattern.

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