Dynamic, personal bedtime/wakeup sensors and alarm clock/bedtime notification, ideas/tips needed

I need some help to start off my latest idea in my quest for a automated (not remote controlled) house :slight_smile:
Right now I’m unable to wrap my head around how I will do this exactly, so I’m thinking that maybe by sharing my idea and writing it down I will either figure it out myself and can share the result.
Or that this community has some great tips or already working solutions to help me on the way

Goal:
The idea is that I will never need to worry about setting an alarm clock and to have events trigger when I “should be awake, but is asleep” or “should be asleep, but is awake”.

I have working input_booleans and sensors to set our “states” currently that I will be comparing to this new sensor that will be the suggested “awake/asleep”-sensor.

Existing and working:

  • input_number.person_x_sleep_wanted
    • Preset amout of hours I want to sleep
  • input_number.person_x_morning_routine
    • time to add to sleep hours before a calendar event or office hours start
  • input_boolean.person_x_awake
    • controlled by google routine, bedside button - this will tell if I’m actually awake or not, automation takes care of it if I forget it (if it is night and no movements in the house, no chromecast playing, computer is idle etc it will switch this one to off )

Need to create:

  • binary_sensor.person_x_awake_recommended
    • Template from below sensors: if after bedtime and before wakeup -> asleep, else -> awake
  • sensor.person_x_next_bedtime (template sensor)
    • timestamp of next recommended bedtime, if still awake negative values until next wakeup time is within 1 hour (for example)
    • first to occur from:
      • calendar event start time - morning routines - sleep wanted
      • if workday: office hour start time - morning_routine - sleep wanted
      • latest time to wake up if no event/workday - sleep wanted
  • sensor.person_x_next_wakeup (template sensor)
    • negative values if person is asleep and time for next bedtime has not passed
    • first to occur from:
      • first calendar event+morning routine
      • if workday: office hour start time + morning_routine
      • time when input_boolean.person_x_awake was switched off + sleep_wanted
      • latest time to wake up if no events (preset time)

Soo, even thhough it takes some time for me between efforts I am little by little getting closer with this.
The current struggle is for to create a template sensor that will show the earliest time/lowest value of 3 sensors:

  • calendar event time
  • bedtime + x-hours set from input_number

And this last one I haven’t been able to crack out a template for yet, but I’m assuming it should not be too difficult once I read up a little:
If hour >12
set “tomorrow” @ input_datetime
else
set “today”@ input_datetime

Hey man! Have you shared the code anywhere yet? Would love to try to help push this forward if I can. Sounds useful for me too.

Hi, no not yet. Not really sure how/when.
I’m separating it in a a separate “package” from my config, so it should only be a YAML file containing the sensors, automation, input_numbers and input_selects.
But at the moment struggling a bit with templating of dates back and forth between UNIX and normal formats.

have you seen this:

I don’t know if it will help but it can’t hurt (I hope… :wink:)

It does, been on that one.
Problem is that I’m loosing track of what I’m working on as I need to create several templates, but I think I’m close to having all “modes” working.

I’m creating a Selector to choose “Full auto”, “Calendar only”, “Manual time” or “Off”
But I get ideas while doing it, so possibly need to add options for.
“Late Weekend”-days and “Holidays” (from a google holiday calendar or the “workday”-sensor.

Another problem is that I have many dependencies from “other” sensors and digging them all out is a bit of work it seems, but will try and share what I have

Ho Forschi
This sounds very interesting! Have you been able to get it to work? I would greatly appreciate it, if you could share your code.
Thank you :slight_smile: