Pi: pi
The pi template constant provides the mathematical constant pi, approximately 3.14159. This is the ratio of a circle’s circumference to its diameter and is fundamental to trigonometric and geometric calculations.
This is commonly used for converting between degrees and radians in trigonometric calculations. For example, you might multiply a degree-based sensorSensors return information about a thing, for instance the level of water in a tank. [Learn more] value by pi / 180 before passing it to sin, cos, or tan. It is also useful for circle-related geometry in your templatesA template is an automation definition that can include variables for the action or data from the trigger values. This allows automations to generate dynamic actions. [Learn more].
Usage
Here’s how to use this template function. Copy any example and adjust it to your setup.
{{ pi }}
3.141592653589793
Good to know
- This is a mathematical constant approximately equal to 3.14159.
- Use it without parentheses.
piis a value, not a function you call. - Trigonometric functions like
sin,cos, andtanexpect radians, so multiply degree values bypi / 180first.
Try it yourself
Ready to test this? Open Developer tools > Template, paste the example into the Template editor, and watch the result update on the right. Edit the values to see how the function adapts to your own entitiesAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more].
More examples
Real scenarios where this function comes up in automations and templates. Copy any example and adapt it to your setup.
Converting degrees to radians
Convert a sensor value in degrees to radians for use with trigonometric functions.
{% set degrees = states("sensor.wind_direction") | float %}
{{ degrees * (pi / 180) }}
3.141592653589793
Still stuck?
The Home Assistant community is quick to help: join Discord for real-time chat, post on the community forum with your template and expected result, or share on our subreddit /r/homeassistant.
AI assistants like ChatGPT or Claude can also explain or fix templates when you describe what you want in plain language.
Related template functions
These functions work well alongside this one:
-
Tau: tau - The mathematical constant tau (2 * pi), approximately 6.28318.
-
Euler’s number: e - The mathematical constant e (Euler’s number), approximately 2.71828.
-
Sine: sin - Returns the sine of a value given in radians.
-
Cosine: cos - Returns the cosine of a value given in radians.
-
Tangent: tan - Returns the tangent of a value given in radians.