How would I calculate the absolute humidity using sensor values of relative humidity (and maybe pressure for more accuracy)?
And how could I display such calculated values?
The formulas to calculate Absolute Humidity from RH and Temperature are fairly complicated computations and will most likely required a python script of some sort.
I haven’t seen those formulas in years (12 or so) but I could help you write the python script.
Jardi.
This custom sensor calculates absolute humidity:
This is awesome!
That’s really a nice offer!
But no more necessary
here is how I calculate abs. humidity. input is sensor_temp_3 and sensor.hum_3. change these 2 names in the function call absolute_humidity(). pressure is not taken into account.
sensor:
- platform: template
sensors:
hum_abs_3:
entity_id: sensor.temp_3,sensor.hum_3
value_template: >-
{% macro absolute_humidity(temp,hum) -%}
{% if states(hum)|float==0 or states(temp)=='unknown' -%}
'unknown'
{%- else %}
{{ (states(hum)|float * 6.112 * 2.1674 * e**((states(temp)|float*17.67)/(states(temp)|float+243.5)) / (states(temp)|float+273.15))|round(2) }}
{% endif %}
{%- endmacro %}
{{ absolute_humidity('sensor.temp_3', 'sensor.hum_3') }}
unit_of_measurement: 'g/mÂł'
friendly_name: 'abs. humidity'
interesting thing is: if I put the sensor in the fridge, the relative humidity is higher then in my flat. but the absolut is much lower.
That’s physics…
No, thats nature.
Physics is only the art of modeling the nature into a human understandable thing.
Why use a macro here? Adds unnecessary code and you’re converting strings all over the place. Also, when you do this you can drop the entity_id list because the entities are inside the states() method which the parser looks for.
sensor:
- platform: template
sensors:
hum_abs_3:
value_template: >-
{% set h, t = states('sensor.hum_3') | float, states('sensor.temp_3') %}
{% if not h or t == 'unknown' -%}
'unknown'
{%- else %}
{% set t = t | float %}
{{ (h*6.112*2.1674*e**((t*17.67)/(t+243.5))/(t+273.15))|round(2) }}
{% endif %}
unit_of_measurement: 'g/mÂł'
friendly_name: 'abs. humidity'
I use a macro because I convert more than 1 sensor. And when I use a macro, the system needs the entity_id.
but macro’s don’t span multiple value_templates, you still need to copy/paste… You’d just be editing in 4 places verses 2 without the macro. To each his own I guess.