Schedule

The Schedule integration集成将 Home Assistant 与您的设备、服务等连接和集成。 [Learn more] provides a way to create a weekly schedule entity实体表示 Home Assistant 中的传感器、执行器或功能。实体用于监控物理属性或控制其他实体。实体通常是设备或服务的一部分。 [Learn more] in Home Assistant, consisting of time blocks with defined start and end times. The schedule is active when a time block starts and becomes inactive when it ends, allowing it to be used for triggering or making decisions in automations and scripts.

配置

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

手动配置步骤

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

  • 浏览到您的 Home Assistant 实例。

  • 转到 设置 > 设备与服务

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

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

  • 从列表中选择 Schedule

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

Name

Friendly name of the schedule.

Icon

Icon to display in the frontend for this schedule.

Schedule blocks

Press and drag to select time blocks for each day of the week. It is not possible to create overlapping time blocks on the same day.

After creating schedule blocks, you can press a block to edit the details.

Start

The start time to mark the schedule as active/on.

End

The end time to mark as inactive/off again.

Additional data

A mapping of attribute names to values, which will be added to the entity’s attributes when the block is active.

Adding additional data

Adding the following as Additional data will show brightness and color_temp as entity实体表示 Home Assistant 中的传感器、执行器或功能。实体用于监控物理属性或控制其他实体。实体通常是设备或服务的一部分。 [Learn more] attributes when the block is active:

brightness: 100
color_temp: 4000

YAML configuration

Alternatively, this integration集成将 Home Assistant 与您的设备、服务等连接和集成。 [Learn more] can be configured and set up manually via YAML instead. To enable the Integration sensor in your installation, add the following to your configuration.yamlconfiguration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more] file.

Note

The data field follows the same logic as described above in Adding additional data.

schedule:
  light_schedule:
    name: "Light schedule"
    wednesday:
      - from: "17:00:00"
        to: "21:00:00"
        data:
          brightness: 100
          color_temp: 4000
    thursday:
      - from: "17:00:00"
        to: "23:00:00"
        data:
          brightness: 90
          color_temp: 3500
    friday:
      - from: "07:00:00"
        to: "10:00:00"
        data:
          brightness: 80
          color_temp: 3000
      - from: "16:00:00"
        to: "23:00:00"
        data:
          brightness: 60
          color_temp: 2500

Configuration Variables

schedule map Required

Alias for the schedule. Multiple entries are allowed.

name string Required

Friendly name of the schedule.

icon icon (Optional)

Icon to display in the frontend for this schedule.

monday|tuesday|wednesday|thursday|friday|saturday|sunday list Required

A schedule for each day of the week.

from time Required

The start time to mark the schedule as active/on.

to time Required

The end time to mark as inactive/off again.

data map (Optional, default: {})

A mapping of attribute names to values, which will be added to the entity’s attributes when the block is active.

Attributes

A schedule entity exports state attributes that can be useful in automations and templates.

Attribute Description
next_event A datetime object containing the next time the schedule is going to change state.
key_1, key_2, … The mapping values from Additional data / data settings of a time block when the respective block is active.

Automation example

A schedule creates an on/off (schedule) sensor within the times set. By incorporating the light_schedule example from above in an automation, we can turn on a light when the schedule is active.

triggers:
  - trigger: state
    entity_id:
      - schedule.light_schedule
    to: "on"
actions:
  - action: light.turn_on
    target:
      entity_id: light.kitchen
    data:
      brightness_pct: "{{ state_attr('schedule.light_schedule', 'brightness') }}"
      kelvin: "{{ state_attr('schedule.light_schedule', 'color_temp') }}"

Another automation can be added to turn the lights off once the schedule is inactive:

triggers:
  - trigger: state
    entity_id:
      - schedule.light_schedule
    to: "off"
actions:
  - action: light.turn_off
    target:
      entity_id: light.kitchen

Actions

To interact with schedules from scripts脚本是允许用户指定 Home Assistant 打开时要执行的动作序列的组件。 [Learn more] and automationsHome Assistant 中的自动化允许您自动响应在家中和周围发生的事情。 [Learn more], the schedule integration provides the following actions动作在 Home Assistant 的多个地方使用。作为脚本或自动化的一部分,动作定义了触发器被激活后将发生的事情。在脚本中,动作被称为序列 [Learn more].

Action schedule.reload

schedule.reload reloads the schedule’s configuration from YAML without the need of restarting Home Assistant itself.

Action schedule.get_schedule

schedule.get_schedule populates response data with the configured time ranges of a schedule. It can return multiple schedules.

action: schedule.get_schedule
target:
  entity_id:
    - schedule.vacuum_robot
    - schedule.air_purifier
response_variable: schedules

The response data contains a field for every schedule entity (e.g. schedule.vacuum_robot and schedule.air_purifier in this case).

Every schedule entity response has 7 fields (one for each day of the week in lowercase), containing a list of the selected time ranges. Days without any ranges will be returned as an empty list.

schedule.vacuum_robot:
  monday:
    - from: "09:00:00"
      to: "15:00:00"
  tuesday: []
  wednesday: []
  thursday:
    - from: "09:00:00"
      to: "15:00:00"
  friday: []
  saturday: []
  sunday: []
schedule.air_purifier:
  monday:
    - from: "09:00:00"
      to: "18:00:00"
  tuesday: []
  wednesday: []
  thursday:
    - from: "09:00:00"
      to: "18:00:00"
  friday: []
  saturday:
    - from: "10:30:00"
      to: "12:00:00"
    - from: "14:00:00"
      to: "19:00:00"
  sunday: []

The example below uses the response data from above in a template for another action.

action: notify.nina
data:
  title: Today's schedules
  message: >-
    Your vacuum robot will run today:
    {% for event in schedules["schedule.vacuum_robot"][now().strftime('%A').lower()] %}
    - from {{ event.from }} until {{ event.to }}<br>
    {% endfor %}
    Your air purifier will run today:
    {% for event in schedules["schedule.air_purifier"][now().strftime('%A').lower()] %}
    - from {{ event.from }} until {{ event.to }}<br>
    {% endfor %}

If you want to run the above action both once per day and whenever one of the schedules changes, you can create an automationHome Assistant 中的自动化允许您自动响应在家中和周围发生的事情。 [Learn more] that combines a time-based trigger触发器是定义的一组平台值或条件,用于触发自动化运行。 [Learn more] with an event每当 Home Assistant 中发生某些事情时,都会触发一个事件。有不同类型的事件,例如状态更改事件、动作触发事件或时间更改事件。所有实体都会产生状态更改事件。每当状态更改时,都会产生状态更改事件。事件可用于触发自动化或脚本。例如,您可以在灯打开时触发自动化,然后在该房间中打开扬声器。事件还可用于触发前端的动作。例如,您可以在按下按钮时触发动作。 [Learn more] trigger per entity.

triggers:
  - trigger: time
    at: "07:30:00"
  - trigger: event
    event_type: entity_registry_updated
    event_data:
      action: update
      entity_id: schedule.vacuum_robot
  - trigger: event
    event_type: entity_registry_updated
    event_data:
      action: update
      entity_id: schedule.air_purifier