-
Notifications
You must be signed in to change notification settings - Fork 50
Rule Designer: Example 2
This rule is used to control a bathroom fan based on the humidity of two rooms (the fan is actually a heat recovery system, so impacts both rooms). If the humidity of either room is above a setpoint, it turns the fan on. If the humidity of both rooms is below a different setpoint, it turns the fan off. A different ON/OFF setpoint provides some hystereses which ensures that the fan doesn't switch too often. Below this is a section with two timers - the first timer will turn the fan on if it's been off for 3 hours, and the second timer will turn the fan off after 10 minutes if it was turned on by the first timer.
Comments can be added to the rule by right clicking on a block and clicking "Add Comment". This will add a ? icon to the block, and clicking on this will open a box for you to add the comment. Comments added is some blocks will also be added to the rule output file.
When saving this rule, HABmin will automatically create the following openhab .rules file -:
// This rule file is autogenerated by HABmin.
// Any changes made manually to this file will be overwritten next time HABmin rules are saved.
// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
// Global Variables
var boolean Override = false
var Timer _timerA = null
var Timer _timerB = null
// Constants used to generate this rule
// HumidityHIGH == 70
// HumidityLOW == 68
rule "Bathroom Fan Controller"
when
Item Bath_TempHum_Humidity changed
or
Item Bed1_TempHum_Humidity changed
or
Item Bath_Fan_State changed
then
// This section controls the fan between a high and low set-point.
if((Bath_TempHum_Humidity.state > 70) || (Bed1_TempHum_Humidity.state > 70)) {
Override = false
sendCommand(Bath_Fan_State, ON)
}
else if((Override == false) && (Bath_TempHum_Humidity.state < 68) && (Bed1_TempHum_Humidity.state < 68)) {
sendCommand(Bath_Fan_State, OFF)
}
// This timer turns the fan on if it has been off for 3 hours.
if(Bath_Fan_State.state == OFF) {
if(_timerA == null) {
_timerA = createTimer(now.plusHours(3)) [|
Override = true
sendCommand(Bath_Fan_State, ON)
]
}
}
else if(_timerA != null) {
_timerA.cancel()
_timerA = null
}
// This timer turns the fan off after 10 minutes if it was turned on by the first timer.
if((Bath_Fan_State.state == ON) && (Override == true)) {
if(_timerB == null) {
_timerB = createTimer(now.plusMinutes(10)) [|
Override = false
sendCommand(Bath_Fan_State, OFF)
]
}
}
else if(_timerB != null) {
_timerB.cancel()
_timerB = null
}
end
- Home
- General Configuration
- Item Configuration
- Sitemap Configuration
- Binding Configuration
- Charting
- Persistence stores and graphing
- Rules and Automation
- Rule Designer: Overview
- Rule Designer: Building Blocks
- Rule Designer: Example 1
- Rule Designer: Example 2
- Rule Text Editor
- Technical
- Language Support
- Binding descriptor files
- Z Wave Product Database
- REST Item Config
- REST Item Icons
- REST Persistence
- REST Sitemap Config
- Rule Item Library
- Item Rule Configuration