From 3a97da1b6da42da3e79ccfa37fbbe7078632e425 Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Sat, 24 May 2025 20:16:07 -0400 Subject: [PATCH] Function to convert station pressure to SLP --- weather/station_slp.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 weather/station_slp.js diff --git a/weather/station_slp.js b/weather/station_slp.js new file mode 100644 index 0000000..c15227c --- /dev/null +++ b/weather/station_slp.js @@ -0,0 +1,41 @@ +const states = global.get('homeassistant.homeAssistant.states') +const temp_F = states['sensor.home_tempest_temperature'].state +const elevation_ft = 693 + +// Get the pressure from the payload +let pressure_inHg = msg.payload + +if (isNaN(pressure_inHg)) { + node.error("Invalid pressure value in msg.payload: " + msg.payload) + msg.payload = null + return null +} + +// Convert pressure from inHg to hPa +let pressure_hPa = pressure_inHg * 33.8639 + +// Convert temperature to °C +let temp_C = (temp_F - 32) * (5 / 9) + +// Convert elevation from feet to meters +let elevation_m = elevation_ft / 3.28084 + +// Apply the barometric formula +let slp = pressure_hPa * Math.pow( + 1 - ((0.0065 * elevation_m) / (temp_C + (0.0065 * elevation_m) + 273.15)), + -5.257 +) + +// Optional: Convert back to inHg +let slp_inHg = slp / 33.8639 + +// Round both values +slp = Math.round(slp * 100) / 100 +slp_inHg = Math.round(slp_inHg * 100) / 100 + +// Return the SLP value +msg.payload = slp_inHg + +node.status({fill:'Success',shape:'dot',text:'green'}) + +return msg