Skip to main content Link Search Menu Expand Document (external link)


TimeOfDay class can be used in rules for time related logic. Methods:

parseStringCreates a TimeOfDay object with a given time string. The format is hh[:mm[:ss]][am|pm]. When am/pm is not specified, the time should be in 24h format.curfew_start = TimeOfDay.parse ‘19:30’ => 19:30
TimeOfDay.parse ‘2pm’ => 14:00
TimeOfDay.parse ‘12:30am’ => 00:30
TimeOfDay.parse ‘15’ => 15:00
now Creates a TimeOfDay object that represents the current > curfew_start, or > ‘19:30’
MIDNIGHT Creates a TimeOfDay object for 00:00TimeOfDay.MIDNIGHT
NOON Creates a TimeOfDay object for < TimeOfDay.NOON
constructorh, m, sCreates a TimeOfDay with the given hour, minute, 17, m: 30, s: 0)
hour Returns the hour part of the
minute Returns the minute part of the
second Returns the second part of the
between?RangeReturns true if it falls within the given time range. Supports a range of TimeOfDay, Ruby Time, string, DateTimeItem, DateTimeType, and ‘3pm’..’7pm’

A TimeOfDay object can be compared against another TimeOfDay object, a Java LocalTime object or a parseable string representation of time.

Note: the following global constants are available:



#Create a TimeOfDay object
break_time = NOON

if > 17, m: 30, s: 0) # comparing two TimeOfDay objects
  # do something
elsif < '8:30' # comparison against a string
  #do something
four_pm = TimeOfDay.parse '16:00'
#Trigger security light between sunset and sunrise when motion is detected
rule 'Outside Light Motion' do
  updated Motion_Sensor, to: OPEN
  run do
    astro = things['astro:sun:home']
    sunrise = astro.getEventTime('SUN_RISE', nil, nil).to_local_time
    sunset = astro.getEventTime('SUN_SET', nil, nil).to_local_time
    next if

    Security_Light.on for: 10.minutes


between creates a TimeOfDay range that can be used to check if another Time, TimeOfDay, LocalTime, or TimeOfDay parsable string is within that range."Within time range") if between('10:00'..'14:00').cover?"Within time range") if between('10:00'..'14:00').include?"Within time range") if between('10:00'..'14:00').include?

when between('6:00'...'12:00')"Morning Time")
when between('12:00'..'15:00')"Afternoon")
else"Not in time range")