Automation #3: Smart Radiator

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 :slightly_smiling_face:). 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 :slightly_smiling_face:

Other automation examples

Related Posts

4 Likes

This can be accomplished using core.utils.sendCommandCheckFirst. That function, and it’s brother postUpdateCheckFirst will have new names that are more clear about their purpose very shortly.

Thanks @CrazyIvan359 :+1:

I will wait then for the final names. Right now, the package core.util doesn’t appear in the doc Core — openHAB Helper Libraries documentation

Right you are, I will look into that as well. You can see the docstrings at the beginning of each function in the modules themselves for the moment. Here is postUpdateCheckFirst, you can see the description there. sendCommandCheckFirst just calls postUpdateCheckFirst with the flag sendACommand=True so their descriptions are the same.

Also I made a typo, it is utils not util

1 Like