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 boolean
boolConverts a value to a boolean (true/false), with an optional default if conversion fails. -
Test if boolean
booleanTests whether a value is a boolean type. -
Test if callable
callableTests whether a value is callable (a function or method). -
Set a default value
defaultProvides a default value if a variable is undefined or none. -
Test if defined
definedTests whether a variable is defined (not undefined). -
Test if false
falseTests whether a value is false. -
Convert to float
floatConverts a value to a floating-point number, with an optional default if conversion fails. -
Test if float
floatTests whether a value is a floating-point number type. -
Test if in sequence
inTests whether a value is contained in a sequence. -
Convert to integer
intConverts a value to an integer, with an optional default if conversion fails. -
Test if integer
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 iterable
iterableTests whether a value is iterable. -
Convert to list
listConverts a value to a list. -
Test if mapping
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 none
noneTests whether a value is None. -
Test if number
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 sequence
sequenceTests whether a value is a sequence (list, tuple, or string). -
Convert to string
stringConverts a value to its string representation. -
Test if string
stringTests whether a value is a string type. -
Serialize to JSON
tojsonSerializes a value to a JSON-formatted string. -
Test if true
trueTests whether a value is true. -
Get the type of a value
typeofReturns the type name of a value as a string. -
Test if undefined
undefinedTests whether a variable is undefined.