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.

As a function
{{ pi }}
Result (floatA number that can have decimal places, like 21.5 or 3.14. Used for temperatures, percentages, and other measurements that need precision.)
3.141592653589793

Good to know

  • This is a mathematical constant approximately equal to 3.14159.
  • Use it without parentheses. pi is a value, not a function you call.
  • Trigonometric functions like sin, cos, and tan expect radians, so multiply degree values by pi / 180 first.

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.

TemplateA 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]
{% set degrees = states("sensor.wind_direction") | float %}
{{ degrees * (pi / 180) }}
Result (floatA number that can have decimal places, like 21.5 or 3.14. Used for temperatures, percentages, and other measurements that need precision.)
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.

Tip

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.