Day of week using UI Only

UPDATE: I selected @Troom answer as the answer to this post, both methods work. One as the original post suggests uses the UI 100%. The other utilizes the UI in a less work sort of way, however breaks the UI elements by utilizing an unsupported template sensor. @Troom way also utilizes a Monday - Sunday week, vs my way which would allow you to use a Sunday - Saturday week.
Both ways are correct, and both ways work. If you want to learn and understand YAML @Troom way is great, if you don’t want to know anything about yaml, now or later, my way uses the abilities provided in the UI, up to you to decide.

For the 100% UI supported method keep reading. For the @Troom method, see the selected answer post.

I’ve seen a lot of people who asked over the years how to have a day of the week sensor to trigger automations, or show and hide items using the conditional card.
Every answer I’ve seen points back to a yaml config file of sorts, binary sensors, sensor templates, and a bunch of more advanced setups that alot of people cannot/do not want to understand.

Here is the solution I came up with that 100% uses the GUI to create a day of week sensor.

The first step is to create a helper Number, I called mine "Day of Week’ with a minimum value of 1 and a max of 7.
The initial value I set to the number for the day of the week, in my case being in the US with a week beginning of Sunday (1), ending on Saturday (7), you may adjust accordingly though the automation will need to be tweaked to match.

Next after this sensor is created we need to create an automation.

This automation will be a time automation with the time trigger being 00:05:00 - or 5 minutes after midnight.

Then in actions we will create a bunch of if/then actions.
These will use the time again as an if statement, however this time we will be presented with a before and after, as well as day of the week. I entered the following:
After: 00:00:00
Before: 23:59:00
Weekday: Sun

Then:
Call service: Input number: Set
Target: Day of Week
Value: 1 (for Sunday)

You will need to create 7 of these one for each day of the week.

Once this is done, you can now use this in any other automation or condition. Just use a state number is equal to which ever corresponding number for the day of the week, 1-7.

For those who want it easy, here is my yaml editor config to copy and paste.

alias: Set Day of Week
description: ""
trigger:
  - platform: time
    at: "00:05:00"
condition: []
action:
  - if:
      - condition: time
        weekday:
          - sun
        after: "00:00:00"
        before: "23:59:00"
    then:
      - service: input_number.set_value
        data:
          value: 1
        target:
          entity_id: input_number.day_of_week
  - if:
      - condition: time
        weekday:
          - mon
        after: "00:00:00"
        before: "23:59:00"
    then:
      - service: input_number.set_value
        data:
          value: 2
        target:
          entity_id: input_number.day_of_week
  - if:
      - condition: time
        weekday:
          - tue
        after: "00:00:00"
        before: "23:59:00"
    then:
      - service: input_number.set_value
        data:
          value: 3
        target:
          entity_id: input_number.day_of_week
  - if:
      - condition: time
        weekday:
          - wed
        after: "00:00:00"
        before: "23:59:00"
    then:
      - service: input_number.set_value
        data:
          value: 4
        target:
          entity_id: input_number.day_of_week
  - if:
      - condition: time
        weekday:
          - thu
        after: "00:00:00"
        before: "23:59:00"
    then:
      - service: input_number.set_value
        data:
          value: 5
        target:
          entity_id: input_number.day_of_week
  - if:
      - condition: time
        weekday:
          - fri
        after: "00:00:00"
        before: "23:59:00"
    then:
      - service: input_number.set_value
        data:
          value: 6
        target:
          entity_id: input_number.day_of_week
  - if:
      - condition: time
        weekday:
          - sat
        after: "00:00:00"
        before: "23:59:00"
    then:
      - service: input_number.set_value
        data:
          value: 7
        target:
          entity_id: input_number.day_of_week
mode: single

Screenshot For Automation Trigger:

This automation will be a time automation with the time trigger being 00:05:00 - or 5 minutes after midnight.

Seems like a ton of work just to avoid a single yaml template sensor.

template:
- sensor:
  - name: Day of the week
    state: "{{ now().weekday() + 1 }}"
1 Like

Automation Action If Screenshot:

Then in actions we will create a bunch of if/then actions.
These will use the time again as an if statement, however this time we will be presented with a before and after, as well as day of the week. I entered the following:
After: 00:00:00
Before: 23:59:00
Weekday: Sun

Automation Action Then Screenshot:

Then in actions we will create a bunch of if/then actions.

Then:
Call service: Input number: Set
Target: Day of Week
Value: 1 (for Sunday)

I agree, however rather than editing configs which over time can break things due to depreciated features, this way should stand through updates longer, and is way less likely to have a mistype cause your entire instance to not boot. This also only took about 10 minutes, using the UI, granted once I had the first day setup, I just edited in the code editor view, and copied and pasted the if/then statements.

Your automation doesn’t need any of those if statements:

alias: Set Day of Week
description: ""
trigger:
  - platform: time
    at: "00:05:00"
action:
  - service: input_number.set_value
    data:
      value: "{{ now().weekday() + 1 }}"
    target:
      entity_id: input_number.day_of_week
mode: single
2 Likes

That’s a very bold assumption… Nothing in a template sensor has been deprecated. Assuming things in automations are ‘deprecation’ proof is also rather bold. Two each their own.

If you put this into the automation via UI, it removes the

So to do this would require it to be done via automation.yaml, or configuration.yaml

@Troom you are totally correct, no where in the posts I went through while figuring this out did I see that through the UI you could still use sensor templates.

This still is not really a 100% UI way of doing it, as the way I proposed is. But it is definitely a viable option.

The warning message you are presented with that the UI can’t handle sensor templates, removes the GUI, and forces you back to code. However, it does at least prevent someone from needing to create this in a config file, potentially borking their entire HA instance on the next reboot.

You’re probably right, it is bold. However with plenty of people asking for a way to do this via the UI, and being told nope the only way to do it is via sensor templates, and config files, is just as bold.

Prior to my option above, I’ve yet to see someone suggest how to do this task via the UI only.

While I don’t mind going in and adding custom items to the config, I can fully understand some who are not experienced with that being tempted not to.

Myself, I prefer to do everything possible via the UI, so I only have one place to go looking for it. The UI provides a cleaner experience for the most part rather than scrolling through a block of config files, and possibly having multiple configs.

For those editing config files a simple mistype in a config can take down your entire instance. Something alot of people don’t have the knowledge or want to have to diagnose.

Save it and reopen it.

works fine… Screenshot after a save and reopen.

Same here. I tried with a time trigger and it updated the entity perfectly.

Then I’m not sure why mine reverts to changing it to the screenshot I posted.

I put it in exactly as @Troon suggested, and my screenshot was the result after saving and reopening.

Yeah, you didn’t copy/paste it correctly. You left out the quotes.

I.e. you copied {{ ... }}, when you should have copied "{{ .. }}"

Ok so I created a new automation, and didn’t select anything, went straight into yaml editor, and copied and pasted @Troom code above. There it worked but if you go through the GUI selecting the trigger and action, then editing the value: via yaml editor, it shows what I was seeing.

Because you aren’t putting the template in quotes. When you switch to the yaml editor from the visual, and you place the template, you put the template in quotes.

Bad:

    service: input_number.set_value
    data:
      value: {{ now().weekday() + 1 }}
    target:
      entity_id: input_number.day_of_week

will result in

    service: input_number.set_value
    data:
      value: 
        "[object Object]": null
    target:
      entity_id: input_number.day_of_week

good

    service: input_number.set_value
    data:
      value: "{{ now().weekday() + 1 }}"
    target:
      entity_id: input_number.day_of_week

will result in

    service: input_number.set_value
    data:
      value: "{{ now().weekday() + 1 }}"
    target:
      entity_id: input_number.day_of_week

You are correct… :roll_eyes: See what I mean by a simple mistype :rofl:

Well, this is what happens when you actively avoid learning yaml when 70% of all integrations are yaml. You sit here having a rough time because you’re unwilling to just learn simple quoting and spacing.

1 Like