Skip to article frontmatterSkip to article content
Template function

Typeof

Also tired of playing: Guess Who?

The typeof function is inspired by the JavaScript typeof operator. It reveals the type of the given value.

This is mostly useful when you are debugging or playing with templates in the developer tools of Home Assistant. However, it might be useful in some other cases as well.

Template function properties
FunctionReveals the type of a given value
Function nametypeof
ReturnsThe type of the given value
Return typestring
Can be used as a filterYes
Can be used as a testNo
Spook's influenceNewly added template function
Developer toolsTry this in the template developer tools
Signature
typeof(
    self,
    value: Any,
) -> str
Function parameters
AttributeTypeRequiredDefault / Example
valueAnythingYesSpook

ExamplesΒΆ

Using typeof as a functionΒΆ

1
2
{{ typeof("Spook") }}
{{ typeof(True) }}

Returns:

str
bool

Using typeof as a filterΒΆ

1
2
{{ "Spook" | typeof }}
{{ True | typeof }}

Returns:

str
bool

Features requests, ideas, and supportΒΆ

If you have an idea on how to further enhance the Home Assistant template engine, for example, by adding a new template function; feel free to let us know in our discussion forums.

Are you stuck using this new feature? Or maybe you’ve run into a bug? Please check the Support page on where to go for help.