Times of the Day

The Times of the Day integration provides a binary sensor that gets its values by checking if the current time is within defined time ranges.

配置

要将 Times of the Day helper 添加到您的 Home Assistant 实例中,请使用此 My 按钮:

手动配置步骤

如果上述 My 按钮不起作用,您也可以手动执行以下步骤:

  • 浏览到您的 Home Assistant 实例。

  • 转到 设置 > 设备与服务

  • 在屏幕顶部,选择标签:Helpers

  • 在右下角,选择 创建助手 按钮。

  • 从列表中选择 Times of the Day

  • 按照屏幕上的说明完成设置。

Name

The name the binary sensor should have. This can be changed later.

On time

The time when the sensor should turn on.

Off time

The time when the sensor should turn off.

YAML configuration

Alternatlively, this integration can be configured and set up manually via YAML instead. This has some additional functionality over the UI version.

The time ranges can be provided as absolute local time or using the sunrise or sunset keyword calculated based on the sun position for location. The location must be provided in the configuration.

In addition for sun position based ranges, the negative or positive offset can be configured.

To enable the Times of Day binary sensor in your installation, add the following to your configuration.yamlconfiguration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more] file:

# Example configuration.yaml entry
binary_sensor:
  - platform: tod
    name: Early Morning
    after: sunrise
    after_offset: "-02:00"
    before: "07:00"
    unique_id: early_morning_sensor

  - platform: tod
    name: Late Morning
    after: "10:00"
    before: "12:00"
    unique_id: late_morning_sensor

Configuration Variables

name string Required

Name of the sensor.

before string | time Required

The absolute local time value or sun event for ending of the time range.

before_offset time (Optional)

The time offset of the ending time range.

after string | time Required

The absolute local time value or sun event for beginning of the time range.

after_offset time (Optional)

The time offset of the beginning time range.

unique_id string (Optional)

An ID that uniquely identifies this sensor. This allows changing the name, icon, and entity_id from the web interface.

Considerations

The primary purpose of this sensor is to use a simple time range definition instead of creating a complex template with references to sun.sun integration attributes.

The sensor state is ON when this condition after + after_offset <= current time < before + before_offset.

If after time is later than before then the next day is considered, i.e.:

binary_sensor:
  - platform: tod
    name: Night
    after: sunset
    before: sunrise

In the above example, the next day sunrise is calculated as a time range end.

Daylight Saving Time Handling

The ToD sensor handles the following cases where the sensor interval:

  • does not exist at all
  • stops at a non-existent time
  • starts at a non-existent time.

To help understand all 3 cases, actual examples are provided below.

Case 1: Sensor Interval Does Not Exist

Let’s make the following assumptions:

  • Daylight Saving starts at 2am
  • On the DST day, the ToD sensor interval is from non-existent 2:30am to non-existent 2:40am.

In this case, the ToD sensor will not trigger since the 2:30am-2:40am interval does not exist on the day when time jumps from 2am to 3am. However, on the following day, the sensor resumed operating normally.

Case 2: Sensor End Time Does Not Exist

  • Daylight Saving starts at 2am
  • On the DST day, the ToD sensor interval is from 1:50am to non-existent 2:10am.

In this case, the ToD sensor will last 10 minutes starting at 1:50am and stop at 3am (the 2am-3am time is jumped over and does not exist).

Case 3: Sensor Start Time Does Not Exist

  • Daylight Saving starts at 2am
  • On the DST day, the ToD sensor interval is from non-existent 2:50am to 3:10am.

In this case, the ToD sensor will last 10 minutes, starting at 3:00am and stopping at 3:10am (the 2am-3am time is jumped over and does not exist).