To convert psi to kPa in code, multiply the psi value by 6.894757293168361. That single multiplication is the whole formula: kPa = psi * 6.894757. It works in any language, needs no library, and takes a few lines to wrap in a reusable function. What follows covers the exact factor, rounded versions for display, a working function in JavaScript and Python, and the small mistakes (unit mismatch, sign handling, rounding at the wrong moment) that cause wrong readings in dashboards and sensor integrations.
What You'll Need
- A text editor or IDE and a working runtime for whichever language you use (Node.js, a browser console, or Python 3).
- The pressure value you want to convert, and confirmation that it really is in psi rather than another unit (bar, kPa, inHg or mmHg) - many sensors report several and the label matters.
- An understanding of how the value is stored: integer, floating point, or a string such as
"32.5 psi". - A rough expected result to sanity-check against: 1 psi is about 6.895 kPa, 14.696 psi is about 101.325 kPa (standard atmosphere).
Step-by-Step
- Start from the exact conversion factor. One pound-force per square inch equals 6.894757293168361 kilopascals. This comes from the defined pound-force and the defined square inch, so it is a fixed constant, not an approximation you need to look up per device. Store it once as a named constant such as
PSI_TO_KPA = 6.894757293168361rather than typing the number inline in several places. - Decide how many decimals you actually need. Most home-automation dashboards and sensor cards display one or two decimals, and kPa readings above about 100 rarely need more. Use the full constant for the calculation and round only when you format the output. Double rounding (rounding the constant to 6.895 and again rounding the result) is the usual source of last-digit drift.
- Write the function, input in psi, output in kPa. In JavaScript:
const psiToKpa = (psi) => psi * 6.894757293168361;. In Python:def psi_to_kpa(psi): return psi * 6.894757293168361. Keep the function dumb - no logging, no formatting, one job - so it can be reused by every sensor or automation that needs it. - Validate the input before converting. Check that the value is a finite number. If your source returns a string like
"32.5 psi", parse the numeric part first (parseFloat(value)in JavaScript,float(value.split()[0])in Python) and reject or flag anything that fails. A silentNaNpropagated into an automation condition can make rules look like they never trigger. - Handle negative values with the same formula. Pressures below zero (as in a vacuum sensor reading in psi) convert with the same multiplication: -5 psi becomes about -34.474 kPa. Do not add an absolute-value step; it flips the meaning of the reading. Only take an absolute value if the sensor itself reports a signed range and your display genuinely wants magnitude.
- Format the result for display separately. Most languages default to far more digits than you want: JavaScript's
toFixed(2)and Python'sround(value, 2)both give you a clean101.33for 14.696 psi while keeping the full-precision value available for comparisons. Round the display, not the stored value. - Test against known anchors. Assert that 1 psi returns about 6.895 kPa, 14.696 psi returns about 101.325 kPa, and 0 psi returns 0. If your results miss these by a factor of roughly 10, you have divided instead of multiplied or used the wrong constant entirely.
- Name the units in the variable or field. Use
pressureKparather thanpressure. In a smart-home setup, mixed-unit bugs almost always come from two devices or templates sharing a field name while one reports psi and the other kPa.
Common Mistakes
- Dividing instead of multiplying. To go the other way (kPa to psi) you divide by the same factor, or multiply by about 0.145038. Using the wrong direction is the most common error and produces results off by roughly a factor of 47.
- Confusing kPa with bar or hPa. 1 bar is 100 kPa, so a value mistakenly treated as kPa when it is bar will read 100 times too small. Weather services often report hPa, which is numerically identical to millibar but not to kPa.
- Rounding the constant too early. Using 6.89 for a reading near 100 kPa introduces visible error. Keep the full constant in code and round only the final formatted string.
- Losing the sign. Applying
abs()somewhere in the chain makes a vacuum reading look like positive pressure and can trip automations that should have stayed idle. - Trusting the raw sensor string. Some integrations return a string with the unit appended and a comma decimal separator in some locales. Parsing only the leading number avoids a failed conversion.
- Storing rounded values and comparing them later. Two readings that were equal before rounding can appear different after it, breaking thresholds that compare on equality.
Tips
- Keep one shared conversion helper and import it, so every sensor, dashboard card and automation uses the same factor and the same rounding rule.
- When you build a dashboard tile, show the unit explicitly next to the number. A bare figure invites exactly the confusion the conversion was meant to solve.
- If you log historical data, store the raw psi value and convert at display time. Storing converted kPa values means changing your rounding rule later rewrites nothing in history.
- For quick mental checks, multiply psi by 7 and knock off a little: 30 psi is roughly 207 kPa, and the real answer is about 206.8. Close enough to spot a wrong result at a glance.
Troubleshooting
If the converted number looks wrong, work backwards from the anchors. A result of 0 means the input parsed to zero or the value was empty. A result of NaN or None means the input was not a number - log the raw value before conversion, not after, so you can see what actually arrived. If the output is exactly 47 times too big or too small, you have multiplied by the inverse factor, which almost always means the formula and the unit label disagree.
If the value is right but the display is unwieldy, the bug is in formatting, not math: apply the rounding at the last moment. If a dashboard shows a different number than your code returns, check whether the dashboard template has its own conversion or rounding applied - double conversion produces values near 47 times off, the same symptom as an inverted factor. Finally, confirm the device's own unit setting. Some sensors switch the reported unit through a configuration option, and changing it in the app changes the raw value your code receives.
Frequently Asked Questions
What is the exact formula to convert psi to kPa?
kPa = psi × 6.894757293168361. That is the exact factor based on the defined pound-force and square inch.
How do I convert kPa back to psi?
Divide kPa by 6.894757293168361, or multiply by approximately 0.145038. The two directions use the same constant.
Can I just multiply by 6.9?
For rough estimates yes, but the error grows with the value - about 1 part in 1,300. For anything displayed or logged, use the full constant and round only the final output.
Why does my converted value not match the sensor app?
The app may be showing a different unit, a rounded figure, or a gauge rather than absolute pressure. Compare against a known reference such as 14.696 psi ≈ 101.325 kPa to find the discrepancy.
Does the formula change for negative pressures?
No. Multiply the signed value by the same factor; -5 psi converts to about -34.474 kPa. Do not take the absolute value unless you specifically want magnitude.
Which languages can use this formula?
Any language with floating-point arithmetic - JavaScript, Python, C, C#, Go, PHP and others all use the same single multiplication.