Disable motionSensing if light is controlled by switch or Alexa

Hi OH Friends,

MotionSensing is great, in the kitchen it turns my lights on at night time, slightly dimmed, and shuts off again, great when visiting kitchen or toilets at night.

But - when we are up late, sitting in kitchen, we turn on lights by Hue Switch or Alexa command, and now MotionSensing should be disabled so that lights don’t Dim or gets set to off after x amount of time.

Several options comes to mind;

  1. set Global variable that the light group is controlled by Switch or Alexa, and have the MotionSensing rule query if its allowed to control lights

  2. Disable MotionSensing rule when lights is controlled by Switch or Alexa

  3. Test if light is anything but 0 in MotionSensing rule
    Tried that and it was a pain - gave funny results from time to time

I would like option 1, but I don’t know how to achieve this. Just recently moved from complete Home Automation using Node Red

Any Advice or new ideas?

This and the other options are deceptively difficult to achieve simply because OH is designed around an event philosophy that is source agnostic. When the light item gets a command to turn on, it doesn’t and cannot know where this comes from. The only real solution to this is to break the chain up, by which I mean have the motion sensor, Alexa and the light switch control different items and use a single rule that determines what command is sent to the light switch based on the combination of different items.

The global variable part is actually easy, that’s just an item. That’s what items are in OH they are variables that each store one piece of information about the state of the automation system. As you system gets more and more sophisticated, you’ll find that your “variable” Items begin to out number your true device items.

The ideal solution to your “don’t turn off the lights when we’re in the kitchen” problem is to improve the system’s ability to know when you are in the room, but this is also a tricky problem that usually requires additional hardware (as mm wave devices become more common, this should get substantially easier).

One of the most common ways of addressing issues like this to actually give your system some idea of the time of day (you’ll find several different implementations demonstrated these forums. What this gives you is a test that says “if it is evening time, don’t use the motion sensor rule for the light, but if it is night time use the motion sensor rule”.

For example, my time of day system recognizes, Wake up, Morning, Afternoon, Evening, Bed time, and Night. This gives me enough granularity to have very effective control over when certain lights should be motion sensor based or not.

Define Alexa Proxy Items for the motion sensors. For example if you have a motion sensor item “MotionSensor1”, define “AlexaMotionSensor1” and then control everything by rules.
DSL example:

rule "Motion detected"
when
  Item MotionSensor1 changed to ON or
  Item AlexaMotionSensor1 changed to ON
then
    Light1.sendCommand(ON)
end

rule "No Motion"
when
  Item AlexaMotionSensor1 changed to OFF or
  Item MotionSensor1 changed to OFF
then
  if (AlexaMotionSensor1.state == OFF)
    Light1.sendCommand(OFF)
end

Hue switch can update the state of the Alexa proxy item and the rules should still work.