User friendly way of adding a start & end time and weekdays to a blueprint

I recently ran into an issue where I was trying to use templating to set a weekday condition for a blueprint.
Apparently it’s not possible to do this, so i’ve created this template condition that allows for a user to add the weekdays in short form to a text field and checks if this input matches the current day.
For completeness, I’ve also added start and stop times as conditions.

Feel free to copy and past this code into your blueprints in order to add some flexibility for other users.

Code:

I believe your Template Condition simply needs to do this:

  - condition: template
    value_template: "{{ now().strftime('%a') | lower in days }}"

Demonstrated in the Template Editor:

That’s what I meant when I suggested you use a Template Condition in the other topic.

1 Like

That is a lot cleaner.
Can you tell I’ve not worked a lot with Python? :sweat_smile:

I’ll update the code in case others want to use it.

Here’s another way to do it.

Instead of a single Text Selector, containing abbreviated day names, each day is a separate Boolean Selector. The user simply enables the desired days.

blueprint:
  name: Days Example
  domain: automation
  input:
    schedule_start:
      name: Schedule start time
      description: Automation only runs after this time.
      selector:
        time:

    schedule_stop:
      name: Schedule stop time
      description: Automation does not run after this time.
      selector:
        time:

    monday:
      name: Monday
      default: false
      selector:
        boolean:
    tuesday:
      name: Tuesday
      default: false
      selector:
        boolean:
    wednesday:
      name: Wednesday
      default: false
      selector:
        boolean:
    thursday:
      name: Thursday
      default: false
      selector:
        boolean:
    friday:
      name: Friday
      default: false
      selector:
        boolean:
    saturday:
      name: Saturday
      default: false
      selector:
        boolean:
    sunday:
      name: Sunday
      default: false
      selector:
        boolean:

variables:
  mon: !input monday
  tue: !input tuesday
  wed: !input wednesday
  thu: !input thursday
  fri: !input friday
  sat: !input saturday
  sun: !input sunday
  days: [mon, tue, wed, thu, fri, sat, sun]

trigger: []

condition:
  - condition: time
    after: !input schedule_start
    before: !input schedule_stop

  - condition: template
    value_template: '{{ days[now().weekday()] }}'

action: []

1 Like

I’ve thought of doing it that way first.
The reason for the choosing the textfield is purely based on the experience in the UI.
A textfield is one field, while the booleans take up a lot of screen real estate.

Yes, I agree. It occupies more space but provides these advantages:

  1. Speed and convenience for the end-user.
  2. Eliminates potential user-entry errors (typos, capitalized letters, etc).

have you tried the simple scheduler add-on by by Alessandro. It is simply elegant
Simple Scheduler

1 Like

I’ve not tried it yet, but I’m aware of it.
I might give that a go in a later version, but for now I just wanted to add the options to a blueprint and not deal with another add-on.