Day of Week Chooser

So, I’ve been trying to figure out the best way to do this, but I’m left with more questions than answers. Figured it’s time to ask the community…

What I’d like is…
The ability to dynamically select several days, during the week; and have it populate as a list (for use in an automation). I’d image the UI could be done with some custom-lovelace code. Horizontal block, Mon - Sun, with check boxes below them. Checked is on, unchecked is off.

A few examples:
Let’s say you want your roomba to run on Mon, Thurs & Sat… Then come Friday you realize you’re having company on Sat, and can “uncheck” Sat from the list. The following week you can select Tues & Thurs instead.

In a perfect world, you get to work from home 2 days a week, but it changes each week depending on demand, and you find out your work-from-home schedule every Friday, for the following week. Then select the day’s you’re working from home in the UI, and run, or don’t run certain automations based on those days.

You travel often for work, but it changes every week. One week you might be OoO Mon - Tue, the following week you might be out Thurs - Fri, but whoknows. This could be used as a vacation/ooo switch to run or not run certain automations.

Hopefully what I’m getting at, makes sense?

I’d rather not have to define a static list of days, in code, for an automation to fire. Makes so much more sense to be able to change this on the fly, when life happens.

Any idea how one might accomplish this?

ops, please feel free to move this post around, not really sure where it should go.

Put these in your configuration.yaml
Have numbers 1 before to control sort of Mon-Sun

input_boolean:    
  monday:
    name: 1_Monday
#    initial: off
  tuesday:
    name: 2_Tuesday
#    initial: off
  wednesday:
    name: 3_Wednesday
#    initial: off
  thursday:
    name: 4_Thursday
#    initial: off
  friday:
    name: 5_Friday
#    initial: off
  saturday:
    name: 6_Saturday
#    initial: off
  sunday:
    name: 7_Sunday
#    initial: off

Then this is the automation that I use for a alarm
The value templates are what make it work back on checked days

- id: '1535751230858'
  alias: Alarm Clock Work Days
  condition:
    condition: or
    conditions:
    - condition: template
      value_template: '{{ (now().strftime("%a") == "Mon") and (states.input_boolean.monday.state=="on")}}'
    - condition: template
      value_template: '{{ (now().strftime("%a") == "Tue") and (states.input_boolean.tuesday.state=="on")}}'
    - condition: template
      value_template: '{{ (now().strftime("%a") == "Wed") and (states.input_boolean.wednesday.state=="on")}}'
    - condition: template
      value_template: '{{ (now().strftime("%a") == "Thu") and (states.input_boolean.thursday.state=="on")}}'
    - condition: template
      value_template: '{{ (now().strftime("%a") == "Fri") and (states.input_boolean.friday.state=="on")}}'
    - condition: template
      value_template: '{{ (now().strftime("%a") == "Sat") and (states.input_boolean.saturday.state=="on")}}'
    - condition: template
      value_template: '{{ (now().strftime("%a") == "Sun") and (states.input_boolean.sunday.state=="on")}}'
  trigger:
    platform: template
    value_template: '{{ states(''sensor.time'') == (states.input_datetime.only_time.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', False)) }}'
  action:
  - service: light.turn_on
    entity_id:
    - light.sengled_e12n14_0309cda5_1
    - light.sengled_e11g13_03092ed4_1
    data:
      brightness_pct: '20'
  - service: tts.google_say
    entity_id: media_player.ccaudio_media
    data_template:
      message: 'Time to get out of bed! Todays temperature will be a high
        of {{states.sensor.y_temperature_max.state}}  and a low of {{states.sensor.y_temperature_min.state}}
        Weather conditions will be {{states.sensor.y_condition.state}}.

        '
  - delay: 00:00:15
  - service: media_player.volume_set
    data:
      entity_id: media_player.runeaudio_mpd
      volume_level: '0.65'
  - service: media_player.media_play
    data:
      entity_id: media_player.runeaudio_mpd
5 Likes

Nice! Thank you for this.

I ended up using parts of the code.

A more compact way is to put the input_boolean into a group. Example of group.yml file:

group_days:
  name: days
  entities:
    - input_boolean.1_Monday
    - input_boolean.2_Tuesday
    - input_boolean.3_Wednesday
    - input_boolean.4_Thursday
    - input_boolean.5_Friday
    - input_boolean.6_Saturday
    - input_boolean.7_Sunday

and then as condition use Template condition Value template:
{{ is_state(state_attr('group.group_days', 'entity_id')[now().isoweekday() - 1], 'on') }}

2 Likes