Motion Sensor in bedroom? Solution "sensors and switches need to have "rank"

This post turned out to be long. The real question is "How to set and check a global flag? or better, how to assign “rank” to controls

Here is why I think I need this:

This is not really a technical question, more of a logical issue. The motion sensor works as it should. When motion is detected and it is dark, my “Bedroom Medium” scene is activated and the light go up to 50%. They dim way down and them go off when no motion is detected. This is what I want most of the time. But at bedtime I switch the lights off with a smart switch and take two steps to the bad and the lights go back on to 50%.

The only why right now to make it dark is to wait in bed until the sensor clears. I solved the problem of moving in bed by placing the motion senor at ankle hight, the sensor can’t “see” a person in the bed.

What I want is some kind of automation that activates my “Bedroom Dark” scene and then disables the motion sensor for a few minutes.

After I press the “bedtime” button the sensor automation should be deactivated for a few minutes, then later at night if motion is detected (because I got up out of bed at night) the sensor should activate “Bedroom Nightlight” it is about 5% power on three of the lights then after sunrise I don’t care. And the next evening we go back to motion detection trigger the “Medium” scene, untill again I pess “bedtime button” which deactivates the sensor for a while before going to “nightlight”.

I don’t need someone to write a script for me. But hints would be nice

The part I’m stuck on is how to make my “bedtime” button reprogram the sensor automation. Somehow (???) it needs to set a flag and the other automations need to check the flag and the flag needs to be reset every day. How to set and check a global flag?

+++++

Here is another us case I can’t figure out how to do.

I have a closet light and a door sensor, the light works like a refridgerator light, It comes on when the door is open. This works reliabley.

But there happens to be another light near the closet and it would be helpful if this light also came on if the door is opened. Even in the daytime this would help.

I know how to make it work just like the light in the closet but what if the light is already on based on some automation or a smart switch. Then when the closet door shuts the light would go off. This anoys the person who just turnd on the light using the switch. So the closet door-shut automation has to “know” if the light is on because of the clost door-open automation or because of any of 4 other reasons. So we have to track “who was the last agent to turn on this light”.

Or so to speak, the closet door should turn the light off ONLY if it was the closet door that turned the light on. If it was on for any other reeason the light should remain on when the door shuts.

In this case I want the light to have an attribute “Why_am_I_on” and then an automation checks this attribute before turning the light off.

++++

But still this is WRONG. The above fails to handle this case: I open the closet, I want the hellway light by the door to go to 100% and 6,000K. Then someone else turns on a set of 6 lights that includes the hall light but sets them to 50% and 2,400K. 5 of the lights should go to 50% and 2.400K but the hall light shoiuld remain at 100% and daylight until the closet door shuts, then the light goes to 50% 2,400K.

So now I see there should a “rank” attribte with sensors. and if a light gets conflicting commands it “listenes” to the highest ranking switch/sensor. then when that switch/sensor goes away, it listens to the second in command. Or said another way the door sensor should have primary control of the hall light only when it is open and revert control when the door is shut.
++++

It switch/sensor had “rank” iot was dramatically simplify automation logic.

  1. are you using a blueprint for motion? or did you do your own motion/lights? and also can you differentiate between when someone presses the smart switch vs when motion turns the light off?
    if you did your own automation and you can tell when the smart switch is physically pressed then… on the automation where you trigger on motion sensor detecting motion, add another trigger which is smart switch off (don’t do it on the light of, do it on the smart switch button being pressed if you can). add a delay for a few seconds and make sure that automation is in “single” mode. it will then blow off any motion detection for those few seconds.
  1. two ways (of many) to do this.
    2a. use a scene. when you open the closet, snapshot the state of the second light. when you close the closet, restore the state of the light.
    2b. create a boolean helper (input_boolean.turned_on_by_closet). when you open the closet, set the boolean if the second light was off. turn it off when the closet closes only if the boolean is on. reset the boolean to off whenever the closet closes

the nicer thing about doing b is that if someone happens to intentionally turn off the second light while the closet door was open, it won’t “restore” it back to on when you close the closet door.

  1. if you do 2b then on whatever automation you have for your “turn all 6 lights on” you can check to see if this boolean is set and don’t futz with that one light.
    if you don’t have an automation for that set but is somehow just automatic, then you could detect it post-facto… but that means the light will temporarily go to 50% then go back to your 100%. just depends on the automation you have for the 6 light switch.

hopefully this helps. i appreciate that you don’t want someone to write it for you but want just directional help… wish more folks did that!!! but if you do end up needing help on the actual writing, holler and post the automation you’ve got…

Hint: add a condition: light must be off for 30 seconds. No need to clear anything. Or set a timer on button press, no motion action while it is still running.

Put motion turns light off in a second automation, disable the automation by default, end the automation by disabeling itself.
When motion starts: if light is on do nothing, otherwise turn light on and enable motion turns light off automation on.

Other actions can disable the automation to turn off lights when no motion too.

i personally don’t like the “light must be off for x seconds” approach because for me too often i’m in the room somewhat still… the lights go off and i waive my arms to get them to turn on and i want them on immediately. so i have a "when i turn off the lights manually, then wait for xx period of time before motion is allowed to turn them on again. but that’s a personal preference…

True, less of a problem with mmwave motion sensors. I edited in more answers, a timer is better if only the button must temporarily disable motion.