Dynamic schedule ideas

I am looking for some configuration advice on how to handle my wifes dynamic work schedule. She is a nurse and the hours that she works is consistent 6:30am to 7pm. However the days that she works doesn’t have any sort of pattern, but she does know her schedule three months in advance. Currently I have an input boolean and if it is turned on the furnace turns on and the lights in the house turn on for her at 5:30am when she gets up, and then at 7:15pm turn on the outside lights.

What I’m looking to automate is the input boolean a month or two in advance. It would be nice to be able to type out the dates that she works and have HA enable to boolean for me.

Does anyone have any ideas on how to accomplish this or has accomplished this in another way.

You want to turn on an input_boolean on a specific date and turn it off on another specific date?

Correct. If she works that day the boolean is set to yes and if she doesn’t it gets set to no.

I’m open to other ideas too. This is just what I have come up with so far. I just need to find a way to be able to input a months worth of work days and then have it trigger a scene to make the house warm for her in the morning when she gets up and turn some lights on.

OK, so what’s the challenge here? Creating the Template Trigger for the two dates?

The challenge isn’t two dates. His challenge is entering in ~45 dates every three months when she gets her schedule.

I think others have done something similar with the google calendar integration. Basically create calendar entries, with a specific string in the title, that reflect her schedule. Then have an automation that runs everyday and checks the calendar for entries with that string.

Whichever technique you choose, you still have 45 dates to enter. What I have in mind involves a Template Trigger with a simple list of dates (easy to maintain).

Does she set a wake-up alarm?

Depending on the rest of your setup you could basically tie everything to that. I have e.g. a HomeKit automation to trigger when I stop the alarm on my phone to turn on some lights.

For your 2nd trigger, I assume that is always a constant delta (fixed working period) to her wake-up time so you could implement that with a relative time calculated or scheduled when the first trigger has occurred.

Although, in my case I use device tracking to turn on lights when getting home.

This way, all of it depends on only one manual action: setting your alarm.

Here’s an idea. My Jinja isn’t very good so this may not be the ideal, but hopefully simple-ish to use.

  1. Create 12 helper text inputs, named like working_days_jan, working_days_feb etc. You can then populate these with a comma-separated list of days, like 1,12,14,16,21,29,30 (spaces ignored)
  2. Create a custom sensor, like:
  - platform: template
    name: working_today
    value: >
      {%- set month = now()|as_timestamp|timestamp_custom('%b')|lower -%}
      {%- set days = states('input_text.working_days_'+month) -%}
      {%- set days_list = (days|replace(' ','')).split(',') -%}
      {%- if (now().day|string) in days_list %}true{%else%}false{%endif -%}

Value is true if it’s currently one of those days, false otherwise.

Here’s a simple way to achieve your goal.

The following is a Template Binary Sensor containing a list of your wife’s work days (obviously you will need to supply the actual work days). On a work day, the binary sensor’s state will be on otherwise it will be off.

  - platform: template
        friendly_name: 'Her Work Day'
        value_template: >-
          {% set workdays = [
            '2021-01-12', '2021-01-14', '2021-01-16',
            '2021-02-01', '2021-02-02', '2021-02-03',
            '2021-02-05', '2021-02-09', '2021-02-11',
            '2021-03-04', '2021-03-04', '2021-03-07'
            ] %}
          {{ now().date()|string in workdays }}

You can use binary_sensor.her_workday to trigger one or more automations.

For example, this automation performs its action at 07:00 but only if it’s a work day.

- alias: 'example alarm on workdays'
  - platform: time
    at: '07:00:00'
  - condition: state
    entity_id: binary_sensor.her_workday
    state: 'on'
  - service: light.turn_on
      entity_id: light.bedroom
      brightness: 125
  - service: notify.her_phone
      title: 'Rise and shine!'
      message: 'Today is a work day.'