[Release] Ideal Indoor (Winter) Humidity Calculator

The following app calculates the 'ideal' interior humidity for homes in cold climates. I use my smart hub to control my whole house humidifier in order to set the humidity of the home through out the winter.

If you live in a cold climate you know that if you set your interior humidity too high you will get condensation on your windows. This is bad as it can lead to rot and mold. This app takes into account the outside air temperature and calculates a humidity which will be comfortable without leading to condensation.

If you still get condensation at when you can adjust the frost factor stetting to be a negative value, this will adjust the target humidity in a downward direction. If you have particularly well insulated windows you can increase the frost factor to increase the target humidity.

This app does not control your humidity it just exposes a virtual humidity sensor which represents a reasonable humidity target


/*
Copyright 2019 Jmaxxz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE
*/
definition(
    name: "Target indoor humidity calculator",
    namespace: "jmaxxz",
    author: "jmaxxz",
    description: "Calculates the ideal indoor humidity based on outside air tempature",
    category: "Convenience",
    iconUrl: "",
    iconX2Url: "")

preferences {
    section("Configuration") {
        input "tempSensor", "capability.temperatureMeasurement", title: "Select outside temperature sensor", submitOnChange: true, required: true, multiple: false
        input "minRh", "decimal", title: "The minimum target relative humidity allowed", defaultValue: 20, submitOnChange: true
        input "maxRh", "decimal", title: "The maximum target relative humidity allowed", defaultValue: 50, submitOnChange: true
        input "frostCorrection", "decimal", title: "Used to correct calculation by applying a fixed offset. If you set condensation on your windows set to a lower number.", defaultValue: 0, submitOnChange: true
    }
}


def installed() {
	initialize()
}

def updated() {
	unsubscribe()
	initialize()
}

def initialize() {
	def targetHumidity = getChildDevice("TargetHumidity_${app.id}")
	if(!targetHumidity) targetHumidity = addChildDevice("hubitat", "Virtual Humidity Sensor", "TargetHumidity_${app.id}", null, [label: "Target humidity", name: thisName])
	targetHumidity.setHumidity(calculateTarget())
	subscribe(tempSensor, "temperature", handler)
}

def calculateTarget() {
	def double outsideTemp = tempSensor.currentTemperature
    // See: http://www.vistawindowco.com/docs/default-source/pdfs/condensationlit.pdf?sfvrsn=0 for source of math
	def target = Math.max(Math.min((double)frostCorrection+27.7+0.535*outsideTemp - 0.00409 * Math.pow(outsideTemp, 2), (double)maxRh), (double)minRh)
    log.info "Calculated a target humidity of ${target}% RH given an outside temperature of ${outsideTemp}"
    return Math.round(target*10)/10
}

def handler(evt) {
	def targetHumidity = getChildDevice("TargetHumidity_${app.id}")
	if(!targetHumidity) targetHumidity = addChildDevice("hubitat", "Virtual Humidity Sensor", "TargetHumidity_${app.id}", null, [label: thisName, name: thisName])
    def target = calculateTarget()
	targetHumidity.setHumidity(target)
}

5 Likes

For those of us with dumb-humidistats, a notification for humidity-out-of-bounds would be pretty sweet.
That way I can set it each morning if it's determined to be in the wrong spot. I can add it for my own use, but figured maybe others would be interested as well.

If you have a Git Repo with that code, I can submit a PR :slight_smile:

1 Like

I will be putting most everything up on github at some point, still porting over from ST/Webcore ATM.

As for notifications, would suggest you use the rules engine for this.

IMO it is best to keep apps like this simple, and then use glue code (e.g. the rules engine, or another small app) to add functionality. (So while I appreciate the offer for the PR, I would end up not accepting it...but hey that is what forks are for :wink:.)

1 Like

Wonderful. That's a great idea. Thank you! :slight_smile:

I like the idea too (Quebec, Canada, cold weather).
I just installed the app and set a tile to see my target humidity.
If I put a standard tile (1 by 1), the value is too big and removes the 3 dots menu and I had to edit the layout to remove it.
If I put a longer tile (2 by 1), the tile is OK, but the value is far too precise (because of the math). Is it possible to decrease that precision (and because humidity measure is by nature imprecise) ?

target%20humidity

Really I think the tiles system should let you pick the precision you like to see. However, since that is unlikely to happen for a while, I've updated the original post to include code that rounds to 2 decimal places.

As a scientist myself, I absolutely agree ! It's useless to display measures with a lot of numbers after the comma. Even a temperature (do you really have a precision of 1/100th of a degree on your sensor?) with that (in)precision has no real meaning.

But I don't think the tile system allows you to change the precision of any tile.
Will reinject your code with the lowered precision.
Thank you

No, I do not. However, the average of my sensors might. But...ok, will make it 1 decimal place instead.

Just to clarify, when I wrote "do YOU", It's not about your specific sensors, but more a general thought about temperature sensors. It's more philosophical than a complaint :slight_smile:

1 Like

Just a small suggestion...one thing you might want to consider adding is an Uninstall method that also uninstalls the child device when uninstalling the app. That way you're not left with any orphans.

@Ryan780 You are not wrong, however it has been my experience that hubitat does not gracefully handle when a device is removed if that device is used in other automations.

Maybe could make it an option to 'enable' remove child on uninstall. But I don't think I would want to do that by default given the current state of things.

I've actually been 'disabling' on my custom apps because of some trouble I ran into with devices being removed and 'bricking' a scene or two.

@Ryan780 Adding the following code to any custom driver or app should make it remove all of its child devices on uninstall.

def uninstalled() {
    def children = getChildDevices()
    children.each({child ->
        deleteChildDevice(child.deviceNetworkId);
    })
}

Hello is maybe possible to calculate Absolute humidity in grams. I do not have experience of complicate programming :frowning:
Can be handy for basement ventilation.
I find a links:

Absolute humidity is a mass ratio, and is therefore generally expressed in grams water per kilogram of dry air (g/kg in SI). It is also measuring essentially the same thing as dewpoint, so while they are not "equal," they can be considered equivalent. The conversion between the two is non-linear. Based on some relationships from a psychrometric chart, a general approximation for the conversion should be:

H(abs) = y = 0.0192 * T(dew)^2 + 0.2413 * T(dew) + 2.834

With dewpoint temperature in degrees C and humidity in g/kg. Although not the cleanest, you could do this simply in rule machine using math.

I know there is at least one device driver (Sonoff Temp/Humidity by @markus) that will report absolute humidity as well as the relative humidity. The mathematical conversion is in the driver code.

BigDecimal numerator = (6.112 * Math.exp((17.67 * deviceTempInCelsius) / (deviceTempInCelsius + 243.5)) * relativeHumidity * 2.1674) 

Probably a closer approximation, but harder to do in RM.

2 Likes

@gaber00 sounds like you are targeting the opposite problem I am with this app (you are venting a humid crawl space, I am trying to drive my humidity as close to comfortable as possible with getting condensation on windows). The bones of this app should be usable if you use the math provided by @dylan.c .

Even simpler is to just use the dewpoint calculation. General guidelines from the American organization ASHRAE are to maintain dewpoint below 60 deg. F. to control mold growth.

Read the following thread...

https://community.hubitat.com/t/dew-point-calculator/

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.