Ok a few issues in the rule:
- Use
==
instead of===
. Use==
for OH states likeNULL
,ON
…, Use===
for javanull
- Add
.toString
in your colour command:BedroomLight_Color.sendCommand(def_hue.state.toString + "," + def_sat.state.toString + "," + new_bri)
- VERY dangerous to use a loooonnnng Thread::sleep like this: Why have my Rules stopped running? Why Thread::sleep is a bad idea
Use a timer instead
rule "bedroom_light_off"
when
Item BedroomPresence changed to OFF
then
logInfo("bedroom.rules", "Presence no longer detected")
if (Film_Scene.state == ON) {
logInfo("bedroom.rules", "But film is running, exiting")
return;
} else {
logInfo("bedroom.rules", "Moving on, film is not running")
if (Sun.state == OFF) {
logInfo("bedroom.rules", "And the Sun is down, dimming")
var new_bri = (Math.round(Integer::parseInt(def_bri.state.toString) / 2)).toString
BedroomLight_Color.sendCommand(def_hue.state.toString + "," + def_sat.state.toString + "," + new_bri)
//Thread::sleep(90000)
createTimer(now.plusSeconds(90), [ |
if (BedroomPresence.state == OFF) {
logInfo("bedroom.rules", "Presence is still off, switching light off")
BedroomLight_Color.sendCommand(OFF)
}
])
}
else if (BedroomPresence.state == OFF) {
logInfo("bedroom.rules", "Sun is not down, simply switching off")
BedroomLight_Color.sendCommand(OFF)
}
}
end
If the item Film_Scene
has no binding, it make no sense to send a command to it.
And you can combine these two rules into one:
rule "bedroom presence"
when
Item BedroomMovement_MotionStatus changed or
Item BedroomPCMovement_MotionStatus changed
then
if (BedroomPCMovement_MotionStatus.state == ON || BedroomMovement_MotionStatus.state == ON) {
BedroomPresence.postUpdate(ON)
} else if (BedroomPCMovement_MotionStatus.state == OFF && BedroomMovement_MotionStatus.state == OFF) {
BedroomPresence.postUpdate(OFF)
}
end