I want to calculate the relative humidity of the air entering my house through an Air Exchanger (if you don’t know how these work, they take the air from outside, and mix it with the air inside the house through a plastic core, mine has heat recovery, so it mixes warm air with the cold air from outside).
I have a formula:
100*(EXP((17.625TD)/(243.04+TD))/EXP((17.625T)/(243.04+T)))
TD is the dewpoint in degrees c
T is the temperature in degrees c
EXP is the exponent to raise Euler’s constant to
The result is the Relative Humidity of the air once it’s in the house. The same air outside will have a different relative humidity to the same air inside. For example today it’s -10 outside and the dewpoint is -12. That gives a relative humidity in the house @ 20 degrees of around 18%. The relative humidity outside is 85%.
Here’s my question. How can I calculate these values in HA on the fly. I want HA to do the math and return the relative humidity of the air if it enters my house. I in turn want to then use this value to see if the humidity inside the house, exceeds the humidity outside the house, and then turn on the air exchanger (no point in adding more humidity in).
This is beyond my knowledge (I’m good with the math, I just don’t know how to implement this). I’m hoping someone out there is smart enough to tell me how to do this!
Have you tried the Node-Red add-on? You can use a simple function that reads your variables upon change or at a certain time and based on that you can opt to trigger a humidifier on/off.
I personally am using Aquara environment monitors that return temperature and humidity inside my kids’ room and based on the value decide to turn on/off their humidifier. You can easily tweak this flow to suit your needs if you’re up to it. Let me know and I’m happy to post it and connect with you to help.
So I’m getting an error, but I don’t really understand what the issue is:
[homeassistant.components.sensor.template] Template sensor humidity_true_inside has no entity ids configured to track nor were we able to extract the entities to track from the value template(s). This entity will only be able to be updated manually.
The sensor values are:
sensor.bedroom_temperature
20.0
unit_of_measurement: °C friendly_name: Bedroom Temperature
And:
Sensor.pws_dewpoint_c
-4
attribution: Data provided by the WUnderground weather service date: Last Updated on February 7, 7:40 PM EST unit_of_measurement: °C friendly_name: Dewpoint icon: mdi:water
The defined entity ids tell HA what to monitor to update the template.
You also missed the “states” part of states(‘sensor.pws_dewpoint_c’) in your template. Same for the bedroom temp sensor (fixed above).
I once started doing this for absolute humidity by using the python_script component. Even though you may have your answer, an alternative approach might be interesting for comparison.
Here’s the script (it’s just logging everything):
# Compute the absolute humidity in g/m³
# Param rh - relative humidity in %
# Param t - temperature in °C
def ah(rh, t):
mw = 18.016 # kg/kmol (Molecularweight of vapor)
rs = 8314.3 # J/(kmol*K) (Universal Gasconstant)
svp = 6.112 * math.exp((17.67*t)/(243.5+t)) # Compute saturated water vapor pressure in hPa
vp = rh/100. * svp # Compute actual water vapor pressure in hPa
return 10**5 * mw/rs * vp/(t + 273.15)
humidity_entity = data.get('humidity_entity')
humidity_attribute = data.get('humidity_attribute')
temperature_entity = data.get('temperature_entity')
temperature_attribute = data.get('temperature_attribute')
if humidity_entity is not None and temperature_entity is not None:
if humidity_attribute is not None:
logger.warning("Humidity attr: {}".format(humidity_attribute))
humidity = float(hass.states.get(humidity_entity).attributes[humidity_attribute])
else:
humidity = float(hass.states.get(humidity_entity).state)
if temperature_attribute is not None:
logger.warning("Temperature attr: {}".format(temperature_attribute))
temperature = float(hass.states.get(temperature_entity).attributes[temperature_attribute])
else:
temperature = float(hass.states.get(temperature_entity).state)
logger.warning("Humidity: {}".format(humidity))
logger.warning("Temperature: {}".format(temperature))
absolute_humidity = ah(humidity, temperature)
logger.warning("Absolute Humidity: {}".format(absolute_humidity))
#hass.bus.fire(name, { "wow": "from a Python script!" })
else:
logger.error("Missing entities in service data.")
To use this you would you would call the service with data like this:
So it’s using existing entities, just like the template approach. In my example I used a climate entity for the temperature where the current temperature is exposed via an attribute. But it could also be a sensor like I do it for the humidity.
That’s an interesting approach. Did this actually work? I’m just getting a value of 100, which when I do the math means that there are no values for either sensor, but this doesn’t make a whole load of sense as the sensors actually have values.
Where do you put the Python script? And where do you call the service? In HA?
It does generate a value. I am however not too involved in that topic to judge if the result makes any sense. It’s what I implemented based on my Google research.
Follow the python_script instructions. Once you have placed the script at the correct location etc., you shoul see the script as a service in the service overview panel of HA. There you can feed it with JSON just like I have posted above. The result will be logged. Just below the line that does the final log there’s a commented out line I took from a template that would generate an event. But you probably could also modify an entity. I don’t know about that. So that’s the part you have to figure out, as it depends on you how you want this to work.