Time trigger should support 'day' too

Having the ability to specify a day together with the time would be great.

My use case would be triggering the same automation but at different times based in the day of the week. So, let’s say 08:00 at mon-fri, and 09:00 on sat-sun. Ideally, this would look like:

automation:
  - trigger:
    - platform: time
      at: 
        time: "15:32:00"
        day: "mon"
    - platform: time
      at: 
        time: "09:32:00"
        day: "sun"

While still keeping the option to use the current shorthand at: "15:32:00" as well (we’ll need that anyway for backwards compatibility) and preferably also supporting specifying multiple days of the week, like days: "mon, tue, wed, fri, sun" or so.

You could use a condition for Sunday, that is what I do

Yeah, I have that in several automations as well, but it is an extra step / adds complexity. It still doesnt really support “trigger this at time xyz on day 1, and also at time abc on day 5”.

So, it’s a workaround, not a solution :wink:

A single Time Trigger also permits multiple times like this:

  - trigger:
    - platform: time
      at:
      - "15:32:00"
      - "17:50:00"

Here is its format in JSON. It presents the value of at as a list of time strings.

[
	{
		"trigger": [
			{
				"platform": "time",
				"at": [
					"15:32:00",
					"17:50:00"
				]
			}
		]
	}
]

To suppost multiple times within a single Time Trigger, your suggestion would need to be constructed like this:

  - trigger:
    - platform: time
      at: 
        - time: "15:32:00"
          day: "mon"
        - time: "17:50:00"
          day:
            - "fri"
            - "sat"

The JSON equivalent is a list where each item is a dict containing two keys:

[
	{
		"trigger": [
			{
				"platform": "time",
				"at": [
					{
						"time": "15:32:00",
						"day": "mon"
					},
					{
						"time": "17:50:00",
						"day": [
							"fri",
							"sat"
						]
					}
				]
			}
		]
	}
]

Home Assistant must inspect at and check if its value contains one of the following:

  1. a single time string
  2. a list of time strings
  3. a list of dicts where each item in the dict contains time and day keys

It’s all feasible but might require an Architectural review because the inclusion of a weekday alters the Time Trigger’s scope (which has been traditionally constrained to “time of day”).

Time Trigger also supports an input_datetime so it would also be possible to do this:

  - trigger:
    - platform: time
      at: 
        - time: "15:32:00"
          day: "mon"
        - time: input_datetime.whatever
          day:
            - "fri"
            - "sat"

That means yet more processing of the time key to determine if it contains a time string or an entity_id.

It’s a useful enhancement but it remains to be seen if attracts the attention of any developers.

1 Like

Nice analysis! I think especially your last code block is on the point on what I’d like to achieve with this feature request.

Now hope someone can implement (I for sure can’t, I’m no dev…). It would be really helpful in automations to be able to trigger the same automation on different times based on the day.