Skip to main content

cron

Syntax

  identifier:
type: cron
cron: string
duration: interval
timezone: string
  • identifier is the name of the identifier that will represent boolean state value.
  • type: Must be set to the value cron. Indicates this is a cron generator.
  • cron: A valid cron expression. See Expressions below.
  • duration: The time interval the state is active for.

Description

The cron generator is a self-contained data source that updates a boolean state as active (true) or inactive (false) based on a cron schedule. This generator allows cases such as marking "The 9th hour of every Monday".

The cron option is mandatory and must be a valid cron expression. Cron expressions are defined by between 5 and 7 fields separated by whitespace, which specify a recurrence pattern. See Expressions below for more info on cron expressions. Cron expressions usually need to be surrounded in double quotes due to the special nature of the asterisk character.

The duration option specifies how long the generator's value will be held in an active (true) state when the cron schedule fires.

The timezone option takes a TZ identifier such as America/New_York to specify the timezone that the cron should be evaluted under.

Examples

generators:
first_shift:
type: cron
cron: "0 6 * * 1-5"
timezone: America/New_York
duration: 8h
info

In the above example, first_shift is the identifier that can be referenced by other parts of the adapter script.

This creates a value that will be true every weekday from 6am to 2pm, US eastern time, and false at all other times.

Expressions

Cron expressions are based on the expressions supported in the GNU crontab file.

*  *  *  *  *  *  *    Field              Allowed values    Special symbols
| | | | | | | ----------------- --------------- ---------------
`--|--|--|--|--|--|-> Second (optional) 0-59 * / , -
`--|--|--|--|--|-> Minute 0-59 * / , -
`--|--|--|--|-> Hour 0-23 * / , -
`--|--|--|-> Day of Month 1-31 * / , - ? L W
`--|--|-> Month 1-12 or JAN-DEC * / , -
`--|-> Day of Week 0-7 or SUN-SAT * / , - ? L #
`-> Year (optional) 0-275759 * / , -

A full explanation of supported cron expressions can be found here.