Hi folks!
Here is another example of my series of automations using Rules DSL and Jython
This solution is not final or complete but can help new members to start with OpenHAB (at least that’s my objective
). It is based on all feedback and solutions shared by members of the community to my questions in this forum.
Automation #3 Smart Radiator
Turn off the radiator of the LIVING_ROOM if one its windows is open
For this example, I consider that the living room has only two windows and a radiator. Both windows belong to the group gLR_Windows
, by doing that we can react in our rule whenever one of the windows is opened (Trigger) and close the radiator (Action).
Items
Group:Contact:OR(OPEN, CLOSED) gLR_Windows
Contact LivingRoom_Window_A (gLR_Windows) { channel="mqtt:topic:MyBroker:Home:Contact1" }
Contact LivingRoom_Window_B (gLR_Windows) { channel="mqtt:topic:MyBroker:Home:Contact2" }
Switch LivingRoom_Radiator { channel="mqtt:topic:MyBroker:Home:Radiator1" }
Rules DSL Implementation
rule "(DSL) Turn off the radiator of the LIVING_ROOM if one its windows is open"
when
Member of gLR_Windows changed to OPEN
then
if(LivingRoom_Radiator.state === ON){
// Turn off the radiator
LivingRoom_Radiator.sendCommand(OFF)
}
end
Jython implementation
from core.rules import rule
from core.triggers import when
import core
@rule("(Py) Turn off the radiator of the LIVING_ROOM if one its windows are open")
@when("Member of gLR_Windows changed to OPEN")
def window_open(event):
if items.LivingRoom_Radiator == ON:
# Turn off the radiator
events.sendCommand("LivingRoom_Radiator", "OFF")
Happy automation!
Humberto
Note:
- Suggestions or recommendations to improve the implementation are welcome!
- Do you have more complex automations that shares the same logic of this example? Please share it
Other automation examples
- Automation #1: Doorbell notification
- Automation #2: Bathroom Smart light
- Automation #4: Smart Radiator (Generic Rule)
- Automation #5: Window Alert
- Automation #6: Boiler Failure Alert
- Automation #7: Detect a particular sequence of events
Related Posts