Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
A local language model can make Home Assistant’s Jinja templates feel approachable by turning a plain-language automation idea into a draft you can inspect and test. It does not know whether your entity IDs, state values, or chosen automation fields match your setup unless you tell it—and it cannot replace validation in Home Assistant. I use it to get past the blank page, then treat every generated expression as code that needs checking.
What does a Home Assistant template do?
A Home Assistant template is a Jinja2 snippet that calculates or formats a result using live entity data. Instead of hard-coding a value, you can ask Home Assistant to evaluate the current states of entities and produce something useful: a count, a condition, a number for a notification, or human-readable text.
As an Amazon Associate I earn from qualifying purchases.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchThat makes templates useful when an automation needs to combine information from several entities or transform it before acting. For example, a notification can report how many lights are on, or a condition can depend on a calculation rather than one sensor’s state. Templates can also support template entities and process incoming data such as JSON.
Home Assistant’s documentation describes its templating as powered by Jinja2, a widely used template engine. It also cautions that templates are code and are among the more technical parts of Home Assistant. That distinction matters: the visual interface is enough for many automations, but a template gives you a way to express logic that the ordinary controls do not conveniently capture.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
When is a template better than a visual automation?
Use the visual automation interface when a straightforward trigger and action already express what you want. Consider a template when the behavior depends on multiple entities, arithmetic, dynamic text, or processing a structured value.
- Keep it visual: a single entity changing to a known state may not need a template.
- Use a template for combined logic: for example, when the condition depends on a count across several lights or doors.
- Use a template for calculated or formatted output: such as turning sensor values into a number or assembling a notification message from current states.
The useful question is not whether a template is more advanced. It is whether the behavior is clearer when expressed as a calculation or transformation. If a visual condition already says exactly what you mean, adding Jinja may make future maintenance harder without adding anything.
Recommended Free Tools
Can a local AI write my Home Assistant automation?
It can draft an expression or automation YAML from a description, but the draft is a starting point, not a verified configuration. A local model can help translate “tell me when three or more doors have been open for five minutes” into pieces of logic. You still need to confirm the entity IDs, the meaning of each state, the fields that accept templates, and what should happen when a sensor is unavailable.
The most useful role I’ve found for a local model is as a drafting and explanation partner. Rather than asking it to “make my smart home work,” give it the exact behavior and the facts it cannot infer. Ask first for the smallest Jinja expression that solves the problem, then request the surrounding automation YAML only after you understand the expression.
A good prompt supplies:
- The desired trigger and outcome in ordinary language, including timing or thresholds.
- Exact entity IDs, device classes, units, and expected state strings.
- The notification target or other action destination, if relevant.
- How to treat unknown or unavailable sensor values.
- A request for YAML, a plain-language explanation of each filter and conversion, and a version that can be tested in Home Assistant’s Template editor.
For example, a useful description would say that a notification should occur when at least three specified door sensors are open for five minutes, name those entities, and say whether any unavailable sensor should be ignored or should prevent the condition from passing. That is more actionable than asking for a generic “open door automation.”
Local execution alone does not establish that a model’s answer is correct, private in every part of a workflow, cheaper, or faster. The practical benefit here is narrower: a model can produce a candidate and explain its reasoning, while Home Assistant’s own tools let you check what that candidate actually returns.
How do I test a generated template before using it?
Paste the expression into Home Assistant’s Template editor before putting it into an automation. The editor displays the result while you type, making it a natural place to check syntax and observe how the expression behaves with the states available in your system.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
- Describe the behavior. Write down the trigger, threshold, timing, and desired action without using YAML.
- Give the model your real inputs. Supply the exact entity IDs, state values, units, and device classes. Ask for an expression first, not an entire automation.
- Read the expression’s explanation. Check what each filter selects, what each conversion does, and which assumptions it makes about missing values.
- Open Settings > Tools > Template. Paste in the draft and inspect the output. Test representative normal states as well as empty, unknown, and unavailable cases.
- Compare the output to the intended behavior. Check boundary cases such as exactly meeting a threshold, no entities matching, or one unavailable sensor among several.
- Confirm the destination field supports templates. Keep entity IDs and structural YAML keys literal where required; do not assume that a template will be evaluated everywhere.
- Only then add the tested expression to the automation. Review the surrounding action and condition YAML as well as the Jinja itself.
A template can be syntactically valid and still be wrong. If the model invents an entity ID, uses a state string that does not match your integration, or counts the wrong entities, the editor may still display a plausible result for some inputs. Validation means checking both that the expression runs and that it represents the behavior you intended.
What are useful Home Assistant Jinja patterns?
These examples illustrate common jobs: selecting entities, converting text states into numbers, and parsing structured data. Adapt them to your entity names and test the result against your actual state values.
How can I count lights that are on?
This expression selects light entities whose state is on, converts the selection to a list, and counts it:
{{ states.light | selectattr('state', 'eq', 'on') | list | count }}
The result is a count, not a list of names. If your goal is to put the names of active lights into a notification, you need a different expression that collects and formats those names. Decide how the message should read when none, one, two, or many lights are on; those cases produce different natural-language output.
How can I count open doors?
Door sensors are commonly represented as binary sensors, so a count can select binary sensors with the door device class and then retain those whose state is on:
{{ states.binary_sensor | selectattr('attributes.device_class', 'eq', 'door') | selectattr('state', 'eq', 'on') | list | count }}
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Before using this pattern, confirm that the entities you want included actually have the expected device class and that on means open for them. A correct filter against the wrong set of sensors still produces the wrong count.
How do I do arithmetic with a sensor state?
Sensor states are text, even when they look numeric. Convert the state before using it in arithmetic or numeric comparisons. For instance, this sets a variable from an outdoor temperature sensor:
{% set temp = states('sensor.outdoor_temperature') | float(0) %}
The fallback 0 keeps a failed conversion from becoming an error, but it can also turn missing data into a misleading temperature. Use it only when zero is a safe fallback for the decision you are making. For another measurement, a missing value might need to be handled explicitly rather than treated as zero.
Free tools Windows power users keep installed
One-click scans. No signup required.
How can I read values from incoming JSON?
When a value arrives as JSON, a template can parse it with from_json and then read a nested value from the resulting structure. The exact property names depend on the JSON you receive, so inspect a representative payload and have the model explain the path it proposes. Check what should happen if the input is empty, malformed, or missing the expected property before using the result in an action.
Why does a template work in the editor but fail in an automation?
A successful result in the Template editor proves that the expression can be evaluated in that context; it does not prove that every automation field accepts templates or that the automation provides the same context. Template support is field-specific. Many text, number, and list fields in actions, conditions, triggers, and scripts can be templated, but entity IDs and structural YAML keys generally cannot.
This is a common point where a plausible AI-generated automation can fail. A model may put a dynamic expression into a field that expects a fixed entity ID, or try to template a YAML key that defines the automation’s structure. Keep those structural parts literal and use templates only in supported value fields.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
There is also a difference between testing the calculation and testing the automation’s behavior. The editor helps you inspect an expression’s output. The automation still has to respond to the right trigger, use the right entities, and place the result in a supported field. If the template itself looks correct, inspect the field receiving it and the surrounding YAML rather than endlessly rewriting the Jinja.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →When should I use a Template trigger?
A Template trigger is useful when no single entity tells Home Assistant what condition to react to. It evaluates a combined expression and fires when that expression changes from false to true.
That is a good fit for a condition involving several entities, such as a count crossing a threshold. It is not automatically a good fit just because the condition can be written in Jinja. Keep the expression focused on the transition you care about, and test what happens as its referenced entities change.
A broad expression can produce noisy behavior if it responds to frequent changes that are unrelated to the outcome you want. Check the false-to-true transition, not just the final value shown in the editor. For a multi-sensor rule, test cases where the count is below, equal to, and above the threshold, and include the unavailable-state behavior you chose.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.How do I make a template safe when a sensor is unknown?
Make the missing-data behavior explicit. Home Assistant entity states are text, and a sensor may be unknown or unavailable; an expression that assumes a valid number or state can fail or quietly produce a misleading result.
For numeric conversion, Jinja filters such as | float(0) and | int(0) provide fallbacks. They are appropriate only if zero is a safe stand-in for the decision at hand. For example, treating an unavailable temperature as zero could trigger an alert that implies a real measurement. In that case, distinguish a missing state from a valid numeric value before calculating or notifying.
For state-based logic, check for missing values or use an appropriate default rather than assuming every referenced entity is present. Tell the model whether an unavailable sensor should be ignored, block the automation, or be reported in the message. Those choices have different meanings; “handle errors” is not precise enough to select one.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
How can I reuse the same Jinja logic across automations?
Move repeated logic into a macro in a .jinja file under Home Assistant’s custom_templates directory. The directory sits beside configuration.yaml, and files can be organized in subfolders. After editing a custom template, run the homeassistant.reload_custom_templates action to load the changes without restarting Home Assistant.
Keep a shared macro small and give its arguments clear names. Document the expected states and fallback behavior next to the code so the next automation does not rely on assumptions hidden in the original prompt.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
One context detail is easy to miss: imported macros do not automatically see caller variables such as trigger or this. Pass the values as macro arguments, or use an import with context when that is what you need. A generated macro that refers to one of those variables without receiving it may work differently from the expression tested in isolation.
What should I check when generated automation logic is wrong?
Debug the smallest relevant piece instead of replacing the whole automation at once. Check the entity data, the expression’s intermediate assumptions, and the field where the output is used.
- It returns zero or an empty result: verify the entity IDs, device classes, and exact state strings being selected.
- A numeric comparison behaves strangely: convert the text state to a number before comparing it.
- It fails only when a sensor is unavailable: decide on an explicit missing-data policy and use a fallback only if its meaning is safe.
- The expression works in the editor but not in the automation: confirm that the destination field supports templates and that the automation uses the same relevant inputs.
- A Template trigger fires too often: narrow the expression and check which referenced state changes can move it from false to true.
When asking the model to revise a failed draft, include the exact observed output, the expected output, and a representative state for each relevant entity. Ask it to change only the expression or field that is wrong and to explain the change. That keeps a correction reviewable instead of introducing a new, larger block of untested YAML.
What changes when I use an LLM instead of writing the template myself?
The model can reduce the effort of translating an idea into an initial expression, but it does not reduce the need to understand the logic. Hand-writing keeps each decision in your hands from the start; model drafting can give you a candidate faster to inspect, but introduces assumptions you must catch. The visual editor remains useful for simpler rules, and the Template editor remains the validation loop for either authoring method.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteEntity-specific knowledge is still the part you must supply. The model cannot reliably infer which sensors belong in your count, what their states mean, whether a fallback is safe, or which automation fields your intended YAML uses. I get the most value when I ask for a small expression, test it with realistic cases, and only then let it help shape the surrounding automation. That is not a claim that the model makes complex logic effortless; it is a way to make the first draft less intimidating without giving up control of the final behavior.
Frequently Asked Questions
Can I use a local model without giving it access to Home Assistant?
Yes. The drafting prompt can consist of your written behavior, entity IDs, and expected states; the model does not need to operate your Home Assistant instance to propose a template. You will still need to paste and validate the result in Home Assistant yourself.
Should I ask the model for a full automation or only a template?
Start with the smallest expression that answers the logic question, then ask for the surrounding YAML once you understand the expression. This separates a template error from a trigger, action, or field-placement error.
Can every Home Assistant YAML field contain Jinja?
No. Template support depends on the field; dynamic values in many text, number, and list fields are supported, while entity IDs and structural YAML keys generally need to remain literal. Check the destination field rather than assuming that a valid expression will be evaluated there.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

