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 | |
---|---|
Function | Reveals the type of a given value |
Function name | typeof |
Returns | The type of the given value |
Return type | string |
Can be used as a filter | Yes |
Can be used as a test | No |
Spook's influence | Newly added template function |
Developer tools | Try this in the template developer tools |
Signature |
---|
|
Function parameters | |||
---|---|---|---|
Attribute | Type | Required | Default / Example |
value | Anything | Yes | Spook |
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.