ha_render_template
Render a Jinja2 template to generate dynamic content from Home Assistant data.
Instructions
Render a Jinja2 template and return the result.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| template | Yes |
Implementation Reference
- src/ha.ts:215-232 (handler)The renderTemplate method in HomeAssistantClient that sends a POST request to HA's /api/template endpoint with the template string and returns the rendered result as text.
async renderTemplate(params: { template: string }) { const baseUrl = normalizeBaseUrl(this.config.url) const url = joinUrl(baseUrl, '/api/template') const res = await fetch(url, { method: 'POST', headers: { 'Authorization': `Bearer ${this.config.token}`, 'Content-Type': 'application/json', }, body: JSON.stringify(params), }) if (!res.ok) throw new Error(`Home Assistant REST error ${res.status} ${res.statusText}`) return await res.text() } - src/index.ts:217-227 (handler)The MCP tool registration for 'ha_render_template' with the handler that calls ha.renderTemplate(input) and returns the result as text content.
server.tool( 'ha_render_template', 'Render a Jinja2 template and return the result.', RenderTemplateInput.shape, async (input) => { const res = await ha.renderTemplate(input) return { content: [{ type: 'text', text: res }], } }, ) - src/tools.ts:51-53 (schema)Zod schema defining the input for render_template: a required 'template' string field.
export const RenderTemplateInput = z.object({ template: z.string().min(1), })