Created
November 29, 2018 18:10
-
-
Save psychoticbeef/c6dd982515c41efefdee1ff3dd2b221f to your computer and use it in GitHub Desktop.
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
var TP_Nightstand_Off_Timer = null | |
val TP_LOWER = 6.5 | |
val FILENAME = "power.rules" | |
rule "scene - turn off nightstand when unused" | |
when | |
Item TP_Nightstand_Power received update | |
then | |
if (TP_Nightstand_Switch.state == OFF) { | |
logInfo(FILENAME, "nightstand already off") | |
TP_Nightstand_Off_Timer?.cancel() | |
TP_Nightstand_Off_Timer = null | |
return | |
} | |
if ((TP_Nightstand_Power.state as Number) < TP_LOWER && TP_Nightstand_Off_Timer === null) { | |
logInfo(FILENAME, "starting timer") | |
TP_Nightstand_Off_Timer = createTimer(now.plusMinutes(1), [| | |
logInfo(FILENAME, "turning off nightstand") | |
TP_Nightstand_Off_Timer = null | |
TP_Nightstand_Switch.sendCommand(OFF) | |
]) | |
} | |
if ((TP_Nightstand_Power.state as Number) >= TP_LOWER) { | |
logInfo(FILENAME, "stopping timer") | |
TP_Nightstand_Off_Timer?.cancel() | |
TP_Nightstand_Off_Timer = null | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment