First off: ultimately, I’m looking for a way to calculate specific humidity (i.e., mass of water per mass of air – not absolute humidity, which is mass-per-volume), and moist air enthalpy from dry bulb temperature, relative humidity, and pressure.
I searched and searched, but did not find an existing component or other straightforward way to do this. Also, I’m not familiar enough with Home Assistant yet to write such a component…but I’d like to be.
I installed it to config/custom_components and initially got error messages, as it was missing the Version tag. I fixed the Version tag in the manifest (the same way most of the forks on github have fixed it), but I am still unable to get it to work. The component now loads without error (now that the the Version thing is fixed), but adding this code to sensor.yaml first causes Developer Tools > Check Configuration to hang, and doesn’t create the sensor on a restart anyway:
I had a suspicion this might be what you were trying to do. I actually setup some template sensors and an automation to do exactly this. Here’s one of my template sensors for calculating total enthalpy:
Obviously you normally can’t derive enthalpy directly like this, however I found this equation online that someone derived by curve fitting data in excel. It’s not perfect, but it’s more than close enough for my needs. I then made the following template sensor to throw on my dashboard (I have window sensors, so I have it change based on how many windows with screens are currently open):
Mostly writing this as a follow-up for others interested in this problem.
I didn’t want to try to copy the entirety of the calculations from psychrolib into my own code; part of the point of libraries is that they are tested, and might be difficult to duplicate.
That said, I ended up figuring it out – I looked at the Thermal Comfort module and was able to add specific humidity (or “humidity ratio”), and even Wet Bulb temperature. I’m sure HA will try to wipe out my changes in the next update, but I’ll back it up and cross that bridge later. For now, I just edited the version that was installed in config/custom_components/thermal_comfort
This commit was the most helpful in that process:
It shows that there are 3 major locations within the code that need to be modified to add another output to the module:
name of the sensor and its key (related) - line 83
attributes (device class, display precision, units of measurement, icon) - lines 142-148
calculation of the sensor value (from only the inputs) - lines 712-763
Following their naming scheme, I coded my own addition. I also needed to add psychrolib to the manifest.
I also determined that it is necessary to restart Home Assistant (via Developer Tools > YAML > RESTART or Settings > System > (power icon)) to get it to recognize a change in the code.
I’m still not entirely sure why the other module didn’t work, but I figure I’ll discover the reason eventually. My next task is to modify Thermal Comfort to make use of the pressure sensor in the BME280, since many psychrometric calculations take pressure as an input. Right now, Thermal Comfort just has hardcoded atmospheric pressures in several places.
In general, Thermal Comfort appears to be a good template for general “numeric converter modules” of sorts – it doesn’t require you to write yaml just to use it (configuration can be done through the GUI), it has multilingual support, there are a dozen examples of varied output types/units, etc…
Interesting. Are you planning to submit a PR to thermal Comfort to add these entities? It’d be nice to pull in Enthalpy natively.
Does your use-case have you comparing air volumes at meaningfully different pressures? I admittedly have not compared psych charts for varying pressures, but I can’t imagine it really making a difference unless the pressures are significantly different or you’re at elevation (and even then, my gut says the comparative calculations wouldn’t have significant differences).
Thermal Comfort already calculates Moist Air Enthalpy, so no need for that. I’m considering submitting a PR for wet bulb and/or specific humidity, but I probably need to write tests, update documentation, etc…
Regarding pressure, no, my use case doesn’t have meaningfully different pressures, and I can’t imagine it would be common. Considering this is Home Assistant and Thermal Comfort, I can’t see anyone taking one of these devices on a plane, nor sticking one in the inlet manifold of a car. This change certainly wouldn’t warrant a pull request. That said, it’s for the same reason I wanted to go through the process of learning to modify a component myself – it gives me an idea of how to write/modify software that connects to HA.
It might be practical to have a configuration field for altitude or, more specifically, “atmospheric pressure where the sensor is”. That way, if you happen to live at a higher altitude, your values might be comparable to those at sea level. I’ll have to look up a few things and see if that even makes sense.
Interesting, I was aware of this entity but I assumed it was just the enthalpy of the water vapor in the air (and explicitly excluding the dry air component) . Google seems to confirm you are correct; maybe it’s a regional thing? I’m a mechanical engineer in the US and never heard of that term despite taking numerous thermodynamics courses: we always just called it total enthalpy. Thanks for enlightening me! I’ll have to update my automations and get rid of the template sensors I made for this value.
Totally makes sense.
That would actually be really handy I think, specifically for folks at elevation. But at the same time, probably wouldn’t significantly change most of the values.
Well, to satisfy my own curiosity I checked the ‘Moist Air Enthalpy’ number reported by Thermal Comfort to both my own Total Enthalpy calculation (from the excel curve fit) as well as pulling out a psych chart and plotting the values manually. Something is very off…
I used my current outside conditions of 80.4F & 88% RH which yields a total enthalpy of ~41 BTU/lb (both my excel curve fit calculation and paper psych chart essentially match). But the Thermal Comfort ‘Moist Air Enthalpy’ value is wildly different with ~33 BTU/lb (77.36 kJ/kg is what it actually reports). Interestingly, while triple checking my work I came across one website that happens to exactly match the Thermal Comfort value: https://drajmarsh.bitbucket.io/psychro-chart2d.html
To confirm that I’m not crazy (at least in regards to this), I asked a friend of mine who is also an engineer to calculate things and his numbers match mine. Without digging further, I have a sneaking suspicion that they both use the same library to calculate Enthalpy and that it’s just plain wrong. So much for being able to get rid of a couple more template sensors…
Edit 1: To further try and satisfy my curiosity, I wondered if maybe the lower enthalpy value was actually just the latent enthalpy from the moisture in the air, but that also doesn’t match. For my stated outside conditions I came up with a Total Enthalpy of 41, Sensible (Dry Air) Enthalpy of 19 and Latent Enthalpy of 22 (BTU/lb). Obviously, none of those matches to the 33 reported by Thermal Comfort…
And finally, I found this page on Engineering Toolbox, which explained the whole thing: Moist Air - Enthalpy
Note! - the “reference” points for the metric and imperial enthalpies are different.
for eq. (5) metric units - the “reference” point for enthalpy h = 0 (kJ/kg) is t = 0 oC(32oF) and x = 0 kg/kg
for eq. (6) imperial units - the “reference” point for enthalpy h = 0 (Btu/lb) is t = 0 oF(-17.8oC) and x = 0 lb/lb. The evaporation heat for water at 0 oF is 1061 Btu/lb as used in eq. (6).
You can not convert from metric to imperial enthalpy or vice versa directly.
…so it appears that, like everything else related to psychrometry, it’s dirty. Nice of them to make it look like the units work like standard units… I’m going to try to borrow the proper ASHRAE book this week and confirm.
I ended up just asking the friend with the books and he confirmed that it’s a hack – if you start messing around with relative temperature scales, you have to treat the results as deltas only, or manually add the offset when converting.
The problem is, the unit labels (BTU/lb, kJ/kg) are missing any indication that they are offset from absolute zero. Not a problem if you happen know the secret, but a terrible communication tool.
Admittedly, it’s normally rare that one would be switching unit systems and deltas are normally what one uses those types of values for anyway. All of that material was purpose-made for HVAC design, not abstract scientific curiosity. As soon as you use a temperature scale other than Kelvin you’ve pretty much entered the world of relative values already.
Does it seem like there’s anything stopping Thermal Comfort from using Imperial units for Enthalpy and Absolute Humidity? While it doesn’t REALLY matter, it’d be nice to have it use the user’s selected unit system.
Internally, Thermal Comfort uses celsius. I don’t think the Thermal Comfort module is actually aware of the user’s selected output units; it appears HA is what converts outputs marked as temperature to the user’s units. I don’t know how to hook into that part of the system yet.
psychrolib can be configured for SI or IP units, so if you wanted to calculate those fields in in imperial, you could just configure it for IP and convert the input values.
I’m also working on a custom component to let me know if the windows should be open or closed. The reason it’s a custom component instead of a simple sensor is that it links to an hourly weather forecast and calculates future open or close times (for open windows at night).