Type conversion template functions
These template functions convert values between text, numbers, and other types, and let you check what type a value currently is. Use them whenever you need to turn sensor states into numbers for math, or verify the shape of data before acting on it.
Home Assistant extends the Jinja2 template engine with many custom functions, filters, and tests. Each function on this page has its own page with detailed descriptions, parameters, and practical examples.
New to templates? Start with the templating documentation to learn the basics.
-
Add to a value
addAdds a specified amount to a numeric value, with an optional default if conversion fails. -
Convert to ean
boolConverts a value to a boolean (true/false), with an optional default if conversion fails. -
Test if
booleanTests whether a value is a boolean type. -
Test if
callableTests whether a value is callable (a function or method). -
Set a value
defaultProvides a default value if a variable is undefined or none. -
Test if
definedTests whether a variable is defined (not undefined). -
Test if
falseTests whether a value is false. -
Convert to
floatConverts a value to a floating-point number, with an optional default if conversion fails. -
Test if
floatTests whether a value is a floating-point number type. -
Test if sequence
inTests whether a value is contained in a sequence. -
Convert to eger
intConverts a value to an integer, with an optional default if conversion fails. -
Test if
integerTests whether a value is an integer type. -
Require a value is defined
is_definedForces a template error if the value is undefined, ensuring variables exist before use. -
Test if value is numeric
is_numberTests whether a value can be converted to a finite number. -
Test if
iterableTests whether a value is iterable. -
Convert to
listConverts a value to a list. -
Test if
mappingTests whether a value is a mapping (dictionary). -
Multiply a value
multiplyMultiplies a numeric value by a specified amount, with an optional default if conversion fails. -
Test if
noneTests whether a value is None. -
Test if
numberTests whether a value is a number (integer or float). -
Round a number
roundRounds a numeric value to a specified number of decimal places using various rounding methods. -
Test same object
sameasTests whether a value is the same object as another (identity check). -
Test if
sequenceTests whether a value is a sequence (list, tuple, or string). -
Convert to
stringConverts a value to its string representation. -
Test if
stringTests whether a value is a string type. -
Serialize to JSON
tojsonSerializes a value to a JSON-formatted string. -
Test if
trueTests whether a value is true. -
Get the type of a value
typeofReturns the type name of a value as a string. -
Test if
undefinedTests whether a variable is undefined.