Last active
October 1, 2017 15:06
-
-
Save PascalTurbo/cf624ec7241ca354735e5a0439cd8774 to your computer and use it in GitHub Desktop.
zwave-window-contact
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
For controlling the temperature, Desired_Temperature isn't touched directly. | |
Desired_Temperature_Command is used to change the temperature and | |
Desired_Temperature will react on this changes. | |
*/ | |
var Number WINDOW_OPEN_TEMPERATURE = 8.0 | |
val org.eclipse.xtext.xbase.lib.Functions$Function1<float, void> update_temperature = [ temperature | | |
if (Contact_Window.state == OFF) { | |
// Set actual Temperature and desired Temperature | |
Desired_Temperature_Command.postUpdate(temperature) | |
Last_Desired_Temperature.postUpdate(temperature) | |
} else { | |
// Only set desired Temperature | |
// Will be activated untill window is closed | |
Last_Desired_Temperature.postUpdate(temperature) | |
} | |
] | |
// Change the vents temperature on command changes only if the window is closed | |
rule Command_Desired_Temperature | |
when | |
Item Desired_Temperature_Command received update | |
then | |
Desired_Temperature.sendCommand(Desired_Temperature_Command.state) | |
end | |
// Reduce the temperature if the window is opened | |
// And save the current temperature to restore it later | |
rule Close_Vent_If_Window_is_opened | |
when | |
Item Contact_Window received update ON | |
then | |
logInfo("Window","window opened") | |
Desired_Temperature_Command.postUpdate(WINDOW_OPEN_TEMPERATURE) | |
end | |
// Set the last desired temperature if the window is closed | |
rule Open_Vent_If_Window_is_closed | |
when | |
Item Contact_Window received update OFF | |
then | |
logInfo("Window","window closed") | |
Desired_Temperature_Command.postUpdate(Last_Desired_Temperature.state) | |
end | |
// Check, if Desired_Temperature_Command equals Desired_Temperature | |
rule Check_Temperature_For_Consistency | |
when | |
Time cron "0 /5 * * * ?" | |
then | |
if (Desired_Temperature_Command.state != Desired_Temperature.state) { | |
if (Contact_Window.state == OFF) { | |
logInfo("Warning","Desired Temperature differes from Command Temperature") | |
Desired_Temperature.sendCommand(Desired_Temperature_Command.state) | |
} | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment