Humidifier Control

OH 5.02 on RPi5 configured entirely using MainUI

I recently added a humidifier to my hot air furnace.

Rather than use the dumb controller that was supplied with the unit, I’d like to create a smarter control using OpenHAB.

The recommendation from the humidifier supplier is to vary the indoor humidity target based on outside temperature. This reduces the chance of condensation when it’s very cold outside.

They provided this chart.

The target humidity can be calculated with the formula

Indoor humidity % = (outside temp (F) /2) + 25

I was planning to create a rule to make this calculation every time the outside temp is updated and store the result as an Item (IndoorHumidityTarget)

Then with another rule to compare the Indoor humidity when it is updated to the Target Humidity and turn the humidifier on/off with a Shelly relay.

Not being adept at creating rules, I was considering using a Blockly rule to do the calculation. One other consideration is my Outside Temp is in Celsius, so I need to add C to F conversion to the calculation.

Is Blockly capable of handling this job?

Does anyone have a suggestion for a more elegant approach?

Thanks for any comments!

I do not use blockly but i think it should be able to do what you plan. If you’re interested in deepening your openHAB knowledge, learning a few core concepts will really open up your options

  1. the item containing temperature reading can have Unit of Measurement. This means that openHAB can convert to any other UoM if you properly query the item, without using a rule.

  2. the humidity set point item can be linked to the temperature channel of the thing describing your temperature sensor, by using a “profile”. In practice it is a script that takes the temperature reading and applies your formula to return the humidity set point. I am not sure if this script can be a blockly one. Again, this may avoid using a rule

  3. It is not clear how your humidifiers works or what your aims are. it appears that you set the humidity set point and then the humidifiers controls humidity by an internal logic. But later you say that you would like to use a shelly plug to switch it on or off, which means that you do not rely on the internal humidity controller and you want to implement a control by yourself. In my limited experience, implementing this kind of control in openhab (which is an on-off control) would not give satisfactory results.

I hope that this may help

If this is a Number:Temperature Item OH can do that for you in Blockly. You can ask for the value in what ever unit you need.

2025-12-05_08-00

Maybe. The challenge is I don’t see a block to get the raw number from a Quantity. So doing the math with units is going to be a pain. As far as I can tell what you’ll need to do is get the numericState from the outside temp Item, assuming that’s in °C you’ll need to do the math to convert it to °F yourself, and then do the calculation to get the target humidity.

It’s awkward enough that I would recommend against it and to use a text rule instead. In JS the rule’s action would look something like:

var rawOutTempF = items.OutsideTemp.quantityState.toUnit('°F').float;
var targetHum = (rawOutTempF / 2) + 25;
items.HumidifierTarget.postUpdate(targetHum + ' %');

The problem is temperature is weird in that 0 isn’t the same value for °F, °C, and K. In order to do any meaningful math what OH does is convert everything to K, does the math, then converts it back. But when doing a calculation like this, that doesn’t give you the answer you need.

For example, given 27 °F (my current outside temp) if I divide by 2 °F gives 1.05… If I divide just by 2 I get -216.20... °F (notice how the units got canceled out for the first operation but not the second). And Blockly doesn’t provide a block to convert a Quantity to a number.

Your approach as described is sound over all.

Unfortunately it cannot. Maybe one day but not yet. Avoiding a rule by using a Script transformation profile doesn’t really save anything. But it doesn’t cost anything either so it becomes a matter of preference.

Here is what it would look like as a JS script transformation profile. You’d link the outside temperature Channel to a Number:Dimensionless Item with unit=%. On the link you’ll choose “SCRIPT ECMAScript (ECMAScript 262 Edition 11)” from the list of profiles and for the Thing to Item " field enter:

| ((Quantity(input).toUnit('°F').float / 2) + 25) + ' %'

When the outside temperature updates, the update will be converted to a Quantity, converted to °F, and then we strip the units from the value to get a plain number. I don’t normally recommend stripping the units like this but ultimately we are changing from temperature to percent so it makes sense. We do the calculation and then append the new unit to the result.

The code above is what it would look like in a rule. Essentially it’s the same thing.

I’ve had very satisfactory results. What didn’t go well for you?

It works here when a variable is used for converting to a number.
But I also find the inline transformation more elegant.

1 Like

It didn’t occur to me to come at converting it from the other direction. That makes the Blockly much more reasonable.

I created a rule named HumidityTarget using your example and using my Outside Temperature Item

and got an error in the event log.

 Script execution of rule with UID 'HumidityTarget' failed: org.graalvm.polyglot.PolyglotException: Error: Failed to create QuantityType from NaN%: java.lang.NumberFormatException: Invalid BigDecimal value: NaN%



It wasn’t clear whether I should create a typed variable or non-typed but I chose non-typed.

I will add more logging to see where it’s failing.

I got it working!

I had not put the proper °F units in the rule.

Thanks to everyone who commented…I certainly learned a lot more about Blockly!

I added a line to send the targetHum value to an Item so it gets persisted.

This humidifier is a simple machine (Aprilaire 700) with a water valve and a fan that blows water mist into the hot air plenum. It is controlled with a 24 VAC signal.

Normally a 24 VAC supply is connected in series with a relay that closes when the furnace fan is running, and another relay controlled by device that monitors outside temp and indoor humidity.

OpenHAB is replacing that simple controller with a smarter solution.

In my case I had to implement a temperature control of a room. The actuator was a “radiator valve” and the sensor a bluetooth indoor temperature sensors. For some reasons, due to limitations of my radiator pipe connections, the radiator valve could only be totally open or totally closed. The thermostatic rule was a on-off controller with hystheris: when temp> set_point: valve is on, when temp < (set_point - threshold): valve is off, when temp is in between, valve do not change state, to avoid excessive flickering.
The controller worked but with resulting temperature fluctuations relatively high (one or two degrees°C), definitely higher than what a commercial thermostat or radiator valve with proportional control can achieve. I know that openhab has a Pulse Width Modulation add-on, but I never attempted using it: there are many parameters to adjust. In the end, I decided to fix the piping connection and use the valve as a proportional controller.

This is the humidostat controller, that openhab should completely replace. I do not know how complex its internal logic can be: if it is analogous to a room temperature thermostat controller it can be rather sophisticated.

that does make sense and for temperature one degree C is something you’d feel. It may be where I live where it’s really dry, but 5% or more swings in humidity is nearly imperceptible. I don’t even bother with PWM or anything like that and let it swing.