Hi All, I had a good search and I couldnt find anything that provided an example of how to disable a Fibaro motion sensor. The reason is for use during a movie, I want the movie rule to control the lights.
Right now if you move during a movie, the lights come on due to motion.
Is there a way to disable motion under a condition? ie Kodi_Control = PLAY . The motion rule I have I fear will just re-enable the lights under movement.
I use a switch that disables the motion controls. For this, I check the state of the switch in my lighting rule. If the switch is ON, it will just print out stuff to the console. If it is NOT ON, the normal operations (the else block) continues:
rule "lighting.living.level"
when Item living_presence changed
or Item living_pir changed
or Item lux changed
or Item sun_elevation changed
or Member of settings changed
then
if (living_kodi_cinema_mode.state == ON){
logWarn("living.lights", "Cinema mode is enabled. Not managing living room lights.")
}
else // normal operation
{
[...] snip [...]
Another rule enables this switch if Kodi changes some of the items to state=PLAY and type=MOVIE and disables it when it shuts down.
So, if iâve got my Kodi rule like so, which dims the lights down when Play is running, how would I incorporate that ? I assume at the end after its dimmed.
I have item for the Motion Alarm, Dimmer and the Light Switch. I assume I set the switch as off, somewhereâŠ
rule "When Kodi Player changed to PLAY"
when
Item myKodi_control changed to PLAY
then
//Slowly Dim the Lights if they are above 50%
if (LivingRoomSw1.state == ON) {
if (fade_timer === null) {
percent = LivingRoomDim1.state as Number
fade_timer = createTimer(now.plusMillis(350), [ |
if (percent > 0) {
percent = percent - 5
if (percent < 0) percent = 0
LivingRoomDim1.sendCommand(percent)
fade_timer.reschedule(now.plusMillis(350))
} else {
fade_timer = null
}
])
}
}
end
The PIR continues to work and fire. But the rule that normally reacts to this change does something else, when the cinema mode switch is ON.
If the switch is ON, only the logWarn part of the rule is executed. If the switch is not ON, only the else part is executed. The else part contains everything that controls the lights.
Heres my light rule. Would you suggest I change the âwhenâ to:
when
Item FibaroEye1Motion changed to on && Kodi_Control = PLAY
rule "FibaroEye1 motion detection turns ON Living Room Lights when Lux is less than 20, with a 2 Minute Inactivity Timer"
when
Item FibaroEye1Motion changed to ON
then
var int Dim = 0
try {Dim = Integer::parseInt(LivingRoomDim1.state.toString)} catch (Exception e) {}
if (FibaroEye1Lux.state < 20 && Dim < 6) {
if (Eye1_Timer !== null) {
LivingRoomDim1.sendCommand("5")
logInfo("FibaroEye1Motion","Living Room Motion Timer rescheduled for " + Eye1_TimeOut + " minutes")
Eye1_Timer.reschedule(now.plusMinutes(Eye1_TimeOut))
} else {
logInfo("FibaroEye1Motion", "Living Room Motion Detected! Turning ON Living Room Lights")
LivingRoomDim1.sendCommand("5")
logInfo("FibaroEye1Motion","Living Room Timer created with " + Eye1_TimeOut + " minutes")
Eye1_Timer = createTimer(now.plusMinutes(Eye1_TimeOut))
[ |
if (FibaroEye1Motion.state == ON) {
logInfo("FibaroEye1Motion","Living Room Motion triggered, but rescheduled again for " + Eye1_TimeOut + " minutes")
Eye1_Timer.reschedule(now.plusMinutes(Eye1_TimeOut))
} else {
logInfo("FibaroEye1Motion", "Living Room, No Motion Detected! Turning OFF Living Room Lights")
LivingRoomSw1.sendCommand("OFF")
Eye1_Timer = null
}
]
}
}
end
No. Conditions wonât work in the when part. Only events. I would suggest to wrap your rule code with if (Kodi_Control.state == PLAY){ [...] }
This way, your normal lighting rule will still fire when you watch Kodi and move, but it will do nothing. Your rule block would look like this:
rule "FibaroEye1 motion detection turns ON Living Room Lights when Lux is less than 20, with a 2 Minute Inactivity Timer"
when
Item FibaroEye1Motion changed to ON
then
if(Kodi_Control.state == PLAY){
var int Dim = 0
try {Dim = Integer::parseInt(LivingRoomDim1.state.toString)} catch (Exception e) {}
if (FibaroEye1Lux.state < 20 && Dim < 6) {
if (Eye1_Timer !== null) {
LivingRoomDim1.sendCommand("5")
logInfo("FibaroEye1Motion","Living Room Motion Timer rescheduled for " + Eye1_TimeOut + " minutes")
Eye1_Timer.reschedule(now.plusMinutes(Eye1_TimeOut))
} else {
logInfo("FibaroEye1Motion", "Living Room Motion Detected! Turning ON Living Room Lights")
LivingRoomDim1.sendCommand("5")
logInfo("FibaroEye1Motion","Living Room Timer created with " + Eye1_TimeOut + " minutes")
Eye1_Timer = createTimer(now.plusMinutes(Eye1_TimeOut))
[ |
if (FibaroEye1Motion.state == ON) {
logInfo("FibaroEye1Motion","Living Room Motion triggered, but rescheduled again for " + Eye1_TimeOut + " minutes")
Eye1_Timer.reschedule(now.plusMinutes(Eye1_TimeOut))
} else {
logInfo("FibaroEye1Motion", "Living Room, No Motion Detected! Turning OFF Living Room Lights")
LivingRoomSw1.sendCommand("OFF")
Eye1_Timer = null
}
]
}
}
}
end
It basically does exacly what you suggested, in properly working code.
Just a thought: I use a dummy âArmedâ item (no binding attached) for all my motions and use that in my rules where it would normally do something like turn on a light (if motion is âArmedâ, then do stuff). It might be worth considering a similar approach instead of hard coding the " Kodi_Control.state == PLAY" into your rule logic. That way, if another situation arises where you want to disable that motion sensor from turning on the lights all you need to do is toggle that dummy switch instead of changing your lighting logic again.
Hereâs how I would do it, in a nutshell. You would need another rule to re-arm the motion sensor like in âmyKodi_control changed to STOPâ or some other event though, so there is that slight bit of extra work there to think about.
Add an item like this, somewhere:
Switch FibaroEye1Motion_Armed
Change your Kodi PLAY rule as such:
rule "When Kodi Player changed to PLAY"
when
Item myKodi_control changed to PLAY
then
FibaroEye1Motion_Armed.sendCommand(OFF)
if (LivingRoomSw1.state == ON) {
...
end
And change your motion rule so instead of âif(Kodi_Control.state == PLAY){â, it looks like this
```php
rule "FibaroEye1 motion detection turns ON Living Room Lights when Lux is less than 20, with a 2 Minute Inactivity Timer"
when
Item FibaroEye1Motion changed to ON
then
if(FibaroEye1Motion_Armed == ON){
var int Dim = 0
...
}
end
In this way, you can have any number of rules change the state of FibaroEye1Motion_Armed to control if you want it to act on the motion or not, for example in the middle of the night if you have to get up and pass that sensor to get a glass of water or something and donât necessarily to have all the lights turn on. In my case, I have a rule that gets fired when I tell my Alexa âgoodnightâ that goes through and among other things like turning all the lights off and locking the doors disables all my motions that turn on lights. They all get re-set to ON at sunrise automatically with the Astro plugin.
I dont know why - I feel stupid the last couple of days. Am I reading this right?
So reading through your suggested motion rule⊠If the Motion sensor triggers from movement, then if your dummy trigger is OFF, it wont run the motion lighting rule and will do the other items inside the Kodi Play rule, right?
However, if Motion triggers and the Dummy Trigger is ON, then it will run through the normal lighting motion rule.
Is the Dummy switch effectively always on then? If not, how is it trigger to ON so the motion rule runs?
You basically have it. The motion rule only turns on lights if the dummy switch is ON. If you wanted it to normally always turn on the lights then yes, it would effectively need to be ON by default. The Kodi rule switches the dummy item OFF as part of everything else it does. You would either need another rule to toggle it back ON or you could alter your Kodi rule like this, if you donât already also have rules for the other myKodi_control states.
I prefer this method because it moves all the logic around the âPLAYâ state into the same rule so itâs easier to manage, for me anyway. Either solution is perfectly valid, they are just different ways to do the same thing so I would encourage you to use whichever approach makes the most sense to you.
rule "When Kodi Player changed"
when
Item myKodi_control changed
then
if (myKodi_control.state == "PLAY"){
FibaroEye1Motion_Armed.sendCommand(OFF) // Disable the motion sensor from turning the lights on
//Slowly Dim the Lights if they are above 50%
if (LivingRoomSw1.state == ON) {
if (fade_timer === null) {
percent = LivingRoomDim1.state as Number
fade_timer = createTimer(now.plusMillis(350), [ |
if (percent > 0) {
percent = percent - 5
if (percent < 0) percent = 0
LivingRoomDim1.sendCommand(percent)
fade_timer.reschedule(now.plusMillis(350))
} else {
fade_timer = null
}
])
}
}
}
else {
FibaroEye1Motion_Armed.sendCommand(ON) // Enable the motion sensor for any other state of myKodi_control
}
end
Thanks, this is a bit advanced for me being a newbie. I think ill leave my rule as it is until I have a better grip on the logic of rules and how they work
It is totally fine and a good practise to define your variables at the top of the rule. I just wrapped everything to make it clear what I mean with âwrappingâ code in something.
Just move the var definition to the top of the rule (so, above the if-statement) and youâll be fine, if it works for you.
var Timer Eye1_Timer = null
val Integer Eye1_TimeOut = 2
rule "FibaroEye1 motion detection turns ON Living Room Lights when Lux is less than 20, with a 2 Minute Inactivity Timer"
when
Item FibaroEye1Motion changed to ON
then
var int Dim = 0
if(myKodi_control.state == PLAY){
try {Dim = Integer::parseInt(LivingRoomDim1.state.toString)} catch (Exception e) {}
if (FibaroEye1Lux.state < 20 && Dim < 6) {
if (Eye1_Timer !== null) {
LivingRoomDim1.sendCommand("5")
logInfo("FibaroEye1Motion","Living Room Motion Timer rescheduled for " + Eye1_TimeOut + " minutes")
Eye1_Timer.reschedule(now.plusMinutes(Eye1_TimeOut))
} else {
logInfo("FibaroEye1Motion", "Living Room Motion Detected! Turning ON Living Room Lights")
LivingRoomDim1.sendCommand("5")
logInfo("FibaroEye1Motion","Living Room Timer created with " + Eye1_TimeOut + " minutes")
Eye1_Timer = createTimer(now.plusMinutes(Eye1_TimeOut))
[ |
if (FibaroEye1Motion.state == ON) {
logInfo("FibaroEye1Motion","Living Room Motion triggered, but rescheduled again for " + Eye1_TimeOut + " minutes")
Eye1_Timer.reschedule(now.plusMinutes(Eye1_TimeOut))
} else {
logInfo("FibaroEye1Motion", "Living Room, No Motion Detected! Turning OFF Living Room Lights")
LivingRoomSw1.sendCommand("OFF")
Eye1_Timer = null
}
]
}
}
}
end
Iâve made your suggeste changes, I had to tweak the Kodi rule to put PLAY instead of âPLAYâ and it appears to be doing what I required.
However, what has broken is my standard motion lighting rule. I can see the FIbaroEye1Motion trigger, but it doesnt turn the lights on.
Any thoughts? When i remove your suggested edits to the light rule, motion lighting works again.
openhab>
smarthome:status LivingRoomDim1
0
openhab> smarthome:status FibaroEye1Motion
ON
openhab> smarthome:status FibaroEye1Motion_Armed
ON
openhab>
openhab> smarthome:status FibaroEye1Lux
0
openhab>
var Timer Eye1_Timer = null
val Integer Eye1_TimeOut = 2
rule "FibaroEye1 motion detection turns ON Living Room Lights when Lux is less than 20, with a 2 Minute Inactivity Timer"
when
Item FibaroEye1Motion changed to ON
then
if(FibaroEye1Motion_Armed == ON){
var int Dim = 0
try {Dim = Integer::parseInt(LivingRoomDim1.state.toString)} catch (Exception e) {}
if (FibaroEye1Lux.state < 20 && Dim < 31) {
if (Eye1_Timer !== null) {
LivingRoomDim1.sendCommand("5")
logInfo("FibaroEye1Motion","Living Room Motion Timer rescheduled for " + Eye1_TimeOut + " minutes")
Eye1_Timer.reschedule(now.plusMinutes(Eye1_TimeOut))
} else {
logInfo("FibaroEye1Motion", "Living Room Motion Detected! Turning ON Living Room Lights")
LivingRoomDim1.sendCommand("5")
logInfo("FibaroEye1Motion","Living Room Timer created with " + Eye1_TimeOut + " minutes")
Eye1_Timer = createTimer(now.plusMinutes(Eye1_TimeOut))
[ |
if (FibaroEye1Motion.state == ON) {
logInfo("FibaroEye1Motion","Living Room Motion triggered, but rescheduled again for " + Eye1_TimeOut + " minutes")
Eye1_Timer.reschedule(now.plusMinutes(Eye1_TimeOut))
} else {
logInfo("FibaroEye1Motion", "Living Room, No Motion Detected! Turning OFF Living Room Lights")
LivingRoomSw1.sendCommand("OFF")
Eye1_Timer = null
}
]
}
}
}
end