Anyone have logic for detecting bedtime?

I have an input_boolean for bedtime that gets set at 11:30pm and off at 5:30am. Also a manual over-ride and tied into Alexa so we can tell her to enter/exit bedtime mode.

But would like to add some more intelligence that if we go to bed before 11:30 this mode would be turned on earlier.

Anyone have a good example of similar? Perhaps using the bayesian sensor?

How about a pressure sensor under the mattress? :wink:

I have a logic which uses find3 room presence to check whether we are in the bedroom for a defined time range:

I just hooked up a Aqara Vibration/tilt/movement sensor to my mailbox door for alert of incoming real mail. The mailbox is outdoors and 80’ feet from the Conbee stick. It’s inexpensive (approx. $14 USD). It may do the trick ductaped under the mattress. :slight_smile:

1 Like

In last home I had bluetooth device tracker for me and my wife. Then strain gauges under the bed.

Based on weight I triggered the modes. Also based on the presence. In the evening both would have to be on the bed or only one, if home alone. Same thing at the morning. Turn on either night lights or full lights.

Before bedtime you could lie together on one side, then roll on own sides to turn off lights. It was perfect.

A few ideas, maybe one will stick out for you to try:

I have Alexa notifications set to go off when someone is in the fridge, electronic cabinet or pantry, which works well until I wake up at 3AM and decide to start my day and then wake up the entire house.

My ridiculously simple solution was a RBG bulb in a bedside lamp.
I have it set to very dim, and purple, so it’s a night light.
When it’s on, “Sleep mode” is on, meaning my alexa notifications are “on” to wake me up if my kids are into shit they shouldn’t be into.
If I wake up early, I can turn the lamp off to turn off “sleep mode”, which silences my notifications.
This was super easy and works well, until one of my kids figure it out.

A few things I tried but ultimately didn’t work out:
I tried using scenes which I could activate by a button (I was using Echo Buttons) or script or input_boolean but I could never get them to work right, someone with more patience likely could.

Other ways I considered but did not try before going this route was a series of things that are always true;

  • If no motion is detected in the living room after 9PM, for more than 20 minutes, it’s safe to assume everyone is in bed.
  • If the FireTV in my workshop (I run a small business from home and if I am working, I always have the TV running) shuts off after 9PM, AND the bedroom firestick is on, and the ps4’s are both off (husband and kid have one to play together) then it’s a safe bet we’re in bed.
  • For times I may not be working - If both ps4s are “off” and my bedroom firestick is on, and both of my kids firesticks are on, we’re in bed.
1 Like

This is cheap and easy if your bed has slats.

There’s another post where someone put loadcells under the bed legs.

I’m currently experimenting with the stats sensor change-rate attribute as an in/out of bed trigger instead of a set level that is subject to drift of the sensor due to the wood slat dimensions changing with humidity and temperature. Seems to be working well but I won’t post an update until I have a few more nights data.

“Hey Google Goodnight” is mine.

Another cheap approach, YABOS.

That is mine right now, but with Alexa, and it works unless you forget to turn it on. That is what my 11:30pm automation does.

We use a Bayesian Binary Sensor to deduce whether we’re in bed from other entities:

binary_sensor:
  - platform: bayesian
    name: In Bed
    probability_threshold: 0.95
    prior: 0.42
    observations:
      - entity_id: sun.sun
        platform: state
        to_state: below_horizon
        prob_given_true: 0.75
      - entity_id: input_boolean.blackout_mode
        platform: state
        to_state: "on"
        prob_given_true: 0.75
      - entity_id: group.living_room_lights
        platform: state
        to_state: "off"
        prob_given_true: 0.65
      - entity_id: alarm_control_panel.simplisafe
        platform: state
        to_state: "armed_home"
        prob_given_true: 0.65
      - entity_id: remote.living_room_tv
        platform: state
        to_state: "off"
        prob_given_true: 0.65

That seems backwards to me. All of those states are what I would want to set automatically when I get in bed.

Yup, my bedtime turns locks all the locks (and alerts if a jam), confirms all the door sensors are closed, and arms the alarm. It ends with a 5 minute delay before turning off any lights not part of “night light” group.

Anyhow I think I have some working logic that will turn on bedtime if no motion detected on the main floor after 9pm for 30 minutes.

Makes sense. For us, it’s the reverse: we’re reliably in bed when these things happen.

I guess as long as they are happening automatically that makes sense. Otherwise it’s just remote control not automation.

I use a Bayesian sensor, which is true when: 1. The TV in the living room is not playing anything 2. The sun is down 3. Both our phones are charging 4. There has been no movement in the non-bedroom areas of the house for 5 minutes. So when the Bayesian goes from OFF to ON, the house goes into sleep mode. It also turns off an input boolean until the next morning, which is a condition for the house to go into sleep mode, incase we stop charging our phones and then charge again to not run sleep mode automation again :slight_smile:

3 Likes

I have a phone_charging boolean that I set using Tasker (Android only), then I use Node Red to set in_bed to true if phone_charging gets turned to true after 10:30pm. It’s not perfect, but I rarely charge my phone after 10:30 unless I’m getting into bed so it’s pretty close to perfect.

I’ve been using the automation below for over a year now and it works pretty well. What it basically does is to check 15 minutes after the last movement upstairs whether this happened later than downstairs and then arms the alarm. Another automation then turns off all the lights, tv, sonos downstairs, when the alarm is arming. As you can see there is no dependancy on time nor the sun etc. So we just leave everything on and just go upstairs.

- alias: Alarm Arm Home Upstairs
  initial_state: true
  trigger:
    platform: state
    entity_id: binary_sensor.floor1_motion
    to: 'off'
    for:
      minutes: 15
  condition:
    - condition: state
      entity_id: binary_sensor.person_home
      state: 'on'
    - condition: state
      entity_id: binary_sensor.floor0_motion
      state: 'off'
    - condition: template
      value_template: >-
        {{ as_timestamp(states.binary_sensor.floor0_motion.last_changed) < as_timestamp(states.binary_sensor.floor1_motion.last_changed) }}
  action: 
    - service: alarm_control_panel.alarm_arm_home
      data:
        entity_id: alarm_control_panel.alarm

Thx for the inspiration!

Can I ask you how you call a NodeRed flow with Tasker ?