Brainstorming how best to do this good night automation

When I kick off my good night routine, I turn on a few lights as well. One lights the hallway, and gets turned off a bit later with a different automation, I also turn on a couple of lamps in my bedroom. Works great, very happy with it, with one scenario.

If my wife or I go to bed 1st, I dont want the bedroom lights to turn on.

Here is the automation

- alias: 'Goodnight Lighting'
  trigger:
  - platform: state
    entity_id: input_boolean.goodnight_switch
    from: 'off'
    to: 'on'
  action:
  - service: light.turn_on
    data:
      entity_id:
        - light.hallway_light
      brightness: 20
  - condition: state
    entity_id: binary_sensor.master_bedroom_occupancy
    state: 'off'
  - service: light.turn_on
    data:
      entity_id:
        - light.bedroom_lamp_one
        - light.bedroom_lamp_two
      brightness: 50

The binary_sensor.master_bedroom_occupancy is an ecobee sensor, and it does stay active for quite a while after being activated. I believe about 30 minutes. So if one of us goes to bed, and the other goes to bed within 30 minutes, it works just how I’d like. but if I stay up longer, then of course it does not work, and the lamps come one.

I could create a separate automation, but would like to try to figure out something. So here are some thoughts.

I have a few other lights in the bedroom as well. light.bedroom_lights, and light.closet_lights. I’d say there is a decent chance that one of those would have been turned on and off while the 1st person was going to bed.

I’m just trying to work the logic of ways that I could have the automation “guess” with a high level of confident that someone is in bed (without making a bed sensor).

Ideas?

Based on the probability of several conditions, the Bayesian Binary Sensor determines the probability of something being true (or false). Here’s a silly example listing the probability of various events that, when all are taken into consideration, suggests everyone is in bed.

50% Cat was let outdoors.
25% Car is in the garage.
45% TV is off.
65% Someone is home.
70% No motion in bedroom.
80% Laptop is off.
90% Enabled the “We are in bed” button.

Threshold for “We are in bed” is 85%.

The Bayesian sensor digests all of that and if its calculation exceeds the threshold you specified then, ta-dah, the sensor indicates true, you are in bed.

It’s a little bit more complicated than that, but close enough. Definitely worth exploring to see if it meets your needs. The hurdle is that you often aren’t monitoring enough things to feed into the Bayesian sensor so it can make an informed decision.

That’s a great Idea. I use a baysian sensor for presense, so this would be easy to work on.

Wonder if other than just states “on/off”, home/not home, etc I could say
turned off in the past X, of motion off for 30 minutes, etc

I dont think I can do that, but maybe if I think differently. Instead of figuring out if one person is in bed (harder), figure out if likely no one is in bed (maybe easier??)

Like motion on downstairs and upstairs? or lights going on in bedroom, and motion downstairs, etc. I’ll have to do some thinking, but this could work.
Thanks

Then you’re halfway there. You already know if someone is home, now you have to narrow the field to “is everyone is in bed”.

The task boils down to itemizing your evening habits and identifying the ones that suggest you’re in bed. Then you cull that list, tossing out all the habits that you aren’t monitoring (like “milling around the kitchen looking for snacks” is out because you have no sensors in the kitchen). Whatever is left is fed to the Bayesian Binary Sensor. Don’t overlook stuff like identifying the “day type” (workday, weekend, holiday) which can influence when you go to bed (earlier/later).

To incorporate time, you may wish to create binary template-sensors for handling things like “turned off in the past X, of motion off for 30 minutes, etc”. Feed the output of the template-sensors to the Bayesian sensor.

My mental struggle is how do I determine if one person went to bed. I think I can definitely figure out of someone (or someones) are not in bed, or if both are in bed. Hmmm,

I do have quite a few motion senors, and lights throughout the house. Hmm, maybe this one

I have a hallway motion sensor, that you cannot avoid if you leave the bedroom. So if the bedroom lights turn on, then off, but there is not motion in the hallway within the next minute I can say with a pretty good level of confidence that someone stayed in the bedroom and the lights are off. It would not be 100% because one person could be walking in the hallway at the same moment someone went to bed, but usually that would not be the case. Defintiely better than what I have now