Function to convert station pressure to SLP
This commit is contained in:
41
weather/station_slp.js
Normal file
41
weather/station_slp.js
Normal file
@ -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
|
Reference in New Issue
Block a user