Hi,
I have many Sensor Things for temperature and relative humidity
For these sensors I would like to create one Rule to calculate absolute humidity. The calculation works fine for one Rule on one Sensor, but I would like to unify the Rule for a group of sensors (=Things).
Can you elaborate on exactly what you want to do, e.g. what calculations are you going to perform? It’s ok to use pseudocode to demonstrate your thoughts
Then create a group called Absolute_Humidity and assign all the absolute humidity items to that group.
Then you’d loop through the members of this group. You can then use the naming scheme to access the other items (the corresponding relhum and temp items)
That’s one way of doing it easily in xtend/rulesdsl
Also instead of looping through all items, you could just trigger on changes like this:
import org.openhab.core.model.script.ScriptServiceUtil
rule "calculate abs humidity"
when
Member of Relative_Humidity changed
Member of Temperature changed
then
val ir = ScriptServiceUtil.itemRegistry
name = triggeringItem.name.split("_")[0]
rel_humidity = ir.getItem(name + "_rel_humidity").state as Number
temp = ir.getItem(name + "_temperature").state as Number
abs_humidity = calcAbsHumidity(temp, rel_humidity)
postUpdate(name + "_abs_humidity", abs_humidity)
end
Another way is to use the semantic model but it’s harder to use that in rulesdsl than in, say, jruby.
I have temperature sensors added via zigbee2mqtt and created a custom transformation to calculate the drewpoint. By this you can move the calculation from item to thing definition and only need to maintain it once.
However that’s not working with all binding, mostly only mqtt, http or similar where you can customize channels
@Matze0211 - thanks to your post, I was reminded about never solving the absolute humidity puzzle.
I wanted to calculate absolute humidity, so I can compare humidity outdoor and indoor. This should allow me to create a “summer” mode for my heat recovery ventilation unit. The goal would be that the current “demand” mode is disabled in summertime when the air is too humid outside, which means that it’s not meaningful to run at high speed to try to lower the humidity inside.
I was not able to find a formula when I last looked at this problem, only some graphs. I tried again after reading your post, and found this: