Evaluate Template
ha_eval_templateRender 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
| Name | Required | Description | Default |
|---|---|---|---|
| strict | No | Template only: fail on undefined variables instead of rendering them as empty (reported in warnings when report_errors is on) | |
| timeout | No | Template only: maximum render time in seconds | |
| template | No | Jinja2 template to render. Omit when using 'condition'. | |
| condition | No | 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': [...]}. | |
| variables | No | Variables available to the template or condition, e.g. sample trigger data: {'trigger': {'to_state': {'state': 'on'}}} | |
| report_errors | No | Template only: have Home Assistant report render errors and warnings. With false, a failed render is only written to Home Assistant's log. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||