With the latest updates on JRuby OpenHAB Rules System I’ve simplified my bathroom exhaust fan to this:
rule 'Humidity: Control ExhaustFan' do
updated MasterBathRoom_Humidity, MainBathRoom_Humidity
run do |event|
humidity = event.item
exhaust_fan = items[humidity.name.sub '_Humidity', '_ExhaustFan']
evo_rate = humidity.evolution_rate 4.minutes, :influxdb
logger.info("#{humidity} #{event.state} evolution_rate: #{evo_rate}")
if event.state > 70 && evo_rate > 15
exhaust_fan.on
elsif event.state < 70 || evo_rate < -5
exhaust_fan.off
end
end
end
Notes:
- It is based on the rate of change in humidity levels. When it increased more than 15% (or any setting of your choice) in the past 4 minutes, it would turn on the exhaust fan.
- Humidity levels are stored in influxdb persistence service on every change. This makes for easy retrieval using
evolution_rate
or any other persistence functions. - Persistence calls are attached to each item, e.g.
humidity.last_update
,MainBathRoom_Humidity.average_since
, etc. - Simplified duration - instead of calling the cumbersome ZonedDateTime.now.minusMinutes(4), simply specify
4.minutes
- Number items can be directly compared against numeric e.g.
MainBathRoom_Humidity > 70
instead of MainBathRoom_Humidity.state.intValue etc.