Integrations

Template helpers

Spook tells you when a template helper or template entity uses entities, actions, attributes, states, areas, floors, labels or devices Home Assistant does not have, or has a template that can never pass.

The Template integration lets you make your own entities, whose state and actions come from templates. A template is a small piece of code that works out a value from other entities. Like a sensor that adds up three others, or a switch that runs a script.

A template gets nothing back when the entity it reads is gone, and no error tells you. The same goes for an attribute it reads: an extra detail on an entity, like the brightness of a light. A template that holds an entity to a state it is never in, like On for a light that is on or off, is never true. An action that no longer exists fails when it runs. And an area, floor, label or device that is gone finds nothing, in a template or as the target of an action. A template trigger or condition written so that it can never be true, like a template in quotes, never lets anything through. Spook reads your templates and raises a repair when they point at something Home Assistant does not have, or can never pass.

That goes for template helpers made in the UI, and for template entities set up in YAML, under template: in your configuration, trigger based ones included.

Repairs

Spook looks through your template helpers and template entities for things that can no longer work, and tells you in the repairs dashboard. Each repair names the helper or template entity and what is wrong with it.

Fixing a template helper goes the same way each time: open the helper from the repair, change its template, and save. For a template entity from YAML there is no editor: edit it under template: in your configuration, and reload your template entities. Spook looks again, and takes the repair away by itself. New to this? Follow Fix your first repair.

Unknown referenced entities

A template uses an entity that no longer exists, usually because it was renamed, replaced or removed. The template gets nothing back for it, and a trigger on it never fires.

How to fix it: Open the helper from the repair, and in its template, use the right entity. Or take it out. For a template entity from YAML, the repair names it and its entity ID: change it under template: in your configuration, and reload your template entities. The repair disappears by itself once it is fixed.

Unknown referenced actions

A template helper or template entity runs an action that does not exist, usually because the integration or script that provided it was removed. Like the press of a template button, or the turn_on of a template switch. That action fails when it runs.

How to fix it: Open the helper from the repair, and change the action to one that exists. Or bring back the integration or script it came from. For a template entity from YAML, change it under template: in your configuration, and reload your template entities. The repair disappears by itself once it is fixed.

Unknown referenced attributes

A template reads an attribute its entity does not have, like state_attr('light.kitchen', 'brightnes'). It gets nothing back, and you get no error.

How to fix it: Open the helper from the repair, and use an attribute the entity has. When Spook is nearly certain what you meant, the repair says so. For a template entity from YAML, change it under template: in your configuration, and reload your template entities. The repair disappears by itself once it is fixed.

Unknown referenced areas

A template uses an area that no longer exists, usually because it was removed or merged into another. A template looking it up, like area_entities('living_room'), gets an empty list, and an action targeting it skips it. Home Assistant logs a warning about the action at most, and does not say which template entity it came from.

How to fix it: Open the helper from the repair, and use an area that exists. Or take it out. For a template entity from YAML, change it under template: in your configuration, and reload your template entities. The repair disappears by itself once it is fixed.

Unknown referenced floors

A template uses a floor that no longer exists. A template looking it up, like floor_areas('upstairs'), gets an empty list, and an action targeting it skips it, without telling you.

How to fix it: Open the helper from the repair, and use a floor that exists. Or take it out. For a template entity from YAML, change it under template: in your configuration, and reload your template entities. The repair disappears by itself once it is fixed.

Unknown referenced labels

A template uses a label that no longer exists. A template looking it up, like label_entities('christmas'), gets an empty list, and an action targeting it skips it, without telling you.

How to fix it: Open the helper from the repair, and use a label that exists. Or take it out. For a template entity from YAML, change it under template: in your configuration, and reload your template entities. The repair disappears by itself once it is fixed.

Unknown referenced devices

A template helper or template entity uses a device that no longer exists, usually because it was removed. A template looking it up, like device_entities('0123456789abcdef0123456789abcdef'), gets an empty list, and an action targeting it skips it. Home Assistant logs a warning about the action at most, and does not say which template entity it came from.

A device trigger, condition or action is worse. It keeps working for now, but Home Assistant checks those when it loads your template entities. For a device action, the next reload or restart leaves that template entity out. For a device trigger or condition, the next reload of your template entities fails as a whole, so none of your changes to them take, and after a restart none of your template entities from YAML load.

A template helper can also be linked to a device, so it shows up with that device. When the device is gone, the helper keeps working, without the link.

How to fix it: Open the helper from the repair, and use a device that exists. Or take it out. For a template entity from YAML, change it under template: in your configuration, and reload your template entities. The repair disappears by itself once it is fixed.

Unknown referenced states

A template helper or template entity waits for, or checks, a state its entity is never in, like is_state('light.kitchen', 'On') for a light that is on or off. That template is never true, a trigger waiting for that state never fires, and a condition checking for it never passes. You get no error.

How to fix it: Open the helper from the repair, and use a state the entity can be in. When Spook is nearly certain what you meant, the repair says so. For a template entity from YAML, change it under template: in your configuration, and reload your template entities. The repair disappears by itself once it is fixed.

Templates that can never pass

A template helper or template entity has a template in a trigger, condition or action that, the way it is written, can never be true. Its trigger never fires, so it never updates the template entity. Its condition always fails, so the template entity never updates, its action stops right there, or an if always takes its else. Its wait only ends on a timeout. You get no error.

How to fix it: Open the helper from the repair and correct the template. The usual causes: quotes around the template, missing {{ }}, something pasted around it, a template that gives on where true is needed, and a template in the to, from or state of a state trigger or condition, which Home Assistant never renders. For a template entity from YAML, change it under template: in your configuration, and reload your template entities. The repair disappears by itself once it is fixed.

Missing something here?

An action, an entity or a repair this integration should have? Say so. Stuck, or found a bug? There is help.