---
title: "Times of the Day"
description: "Spook adds an action to the Times of the Day helper that changes when it turns on and off, so an automation can move the times without a trip to the helper's options."
canonical_url: "https://spook.boo/tod"
---
# Times of the Day

> Spook adds an action to the Times of the Day helper that changes when it turns on and off, so an automation can move the times without a trip to the helper's options.

The Times of the Day helper is on between two times, and off the rest of the day. Quiet hours from 22:00 to 07:00, the cheap night tariff, school hours. Automations ask it whether it is that time, instead of each carrying their own times.

The times are set in the helper's options, and only there. An automation cannot move them: not quiet hours that start later on the weekend, not an end time you pick on your dashboard.

Spook adds an action for that: set times.

## Actions

Spook adds one action to the Times of the Day integration. You find it wherever you add an action, marked with a 👻.

### Set times

Changes when one or more Times of the Day helpers turn on, when they turn off, or both, like the options of the helper do. What you leave out stays as it is.

The change goes through the helper's own options, so Home Assistant checks it the same way it checks what you fill in there. Then Home Assistant reloads the helper, as it does after you save its options. The helper works out at once whether it is on or off with its new times, and the action returns once it has, so the next step of your automation already sees it. A helper that already has the times you give is left alone, without a reload.

An off time earlier than the on time spans midnight, the same as in the options: on after 22:00 and off before 07:00 is on from 22:00 until 07:00 the next morning.

Every entity is checked before the first helper changes. An entity that is not a Times of the Day helper, or one set up in YAML, is refused with an error, and nothing changes. The helpers change one at a time, in the order you give them.

Run by hand, the action takes an administrator, like the options of a helper do. Your automations can always run it. So can your scripts, unless a user who is not an administrator starts one.

**How to use it**

1. Open the automation or script that should change the times, and select **Add action**.
2. Search for **set times**, and select **Times of the Day: Set times 👻**.
3. Choose the Times of the Day helpers.
4. Turn on the times you want to change, and pick the new times.
5. Select **Save**.

**Technical details**

| Action properties |
| --- |
| Action | Times of the Day: Set times 👻 |
| Action name | `tod.set_times` |
| Action targets | No targets |
| Action response | No |
| Spook's influence | Newly added action |
| Tools | [Try this action](https://my.home-assistant.io/redirect/developer_call_service/?service=tod.set_times) [![Open your Home Assistant instance and show the Actions tool with a specific action selected.](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=tod.set_times) |

| Action data parameters |
| --- |
| Attribute | Type | Required | Default / Example |
| `entity_id` | string or list | Yes | `binary_sensor.quiet_hours` |
| `after` | string | No | `"22:00:00"` |
| `before` | string | No | `"07:00:00"` |

Give at least one of `after` and `before`. A time is like `"22:00"` or `"22:00:00"`, in quotes in YAML. Neither can be taken away: a Times of the Day helper always has both.

**Example actions in YAML**

Start the quiet hours half an hour later:

```yaml
action: tod.set_times
data:
  entity_id: binary_sensor.quiet_hours
  after: "22:30"
```

Change both, from a time helper on your dashboard and a fixed end:

```yaml
action: tod.set_times
data:
  entity_id: binary_sensor.quiet_hours
  after: "{{ states('input_datetime.quiet_hours_start') }}"
  before: "07:00"
```

Quiet hours from 22:00 to 07:00 on work nights. On Friday and Saturday nights, everybody stays up later and sleeps in, so they run from 23:30 until 09:00. Every day at noon, while the quiet hours are off, the automation sets the times for the coming night. On the days the times do not change, the helper is left alone:

```yaml
alias: Quiet hours later on the weekend
triggers:
  - trigger: time
    at: "12:00:00"
actions:
  - action: tod.set_times
    data:
      entity_id: binary_sensor.quiet_hours
      after: "{{ '23:30' if now().isoweekday() in [5, 6] else '22:00' }}"
      before: "{{ '09:00' if now().isoweekday() in [5, 6] else '07:00' }}"
```

**Known limitations**

- Every change reloads the helper. While it reloads, its state is `unavailable` for a moment. An automation triggered on it turning `on` fires again when it comes back on. Add `from: "off"` to that trigger to skip the reload.
- The helper works out its state again with the new times. Move the on time past the current time while the helper is on, and it turns off at once.
- The same time for on and off is not a whole day: the helper is never on.
- A helper made in the UI takes times of the day only. Sunrise, sunset and offsets are for helpers set up in YAML, and those are refused: their times are in your configuration, change them there.


## Sitemap

See the full [sitemap](https://spook.boo/sitemap.md) for all pages.
