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

Duration

Ruby integers and floats are extended with several methods to support durations. These methods create a new java.time.Duration object that is used by the Every trigger, delay, the for option and timers.

Extended Methods

MethodDescriptionExamples
hour or hoursConvert number to hours1.hour, 2.5 hours
minute or minutesConvert number to minutes3.minutes
second or secondsConvert number to seconds5.seconds
millis or millisecond or milliseconds or msConvert number to milliseconds200.ms

Examples

rule 'run every 30 seconds' do
  every 30.seconds
  run { logger.info('Hello') }
end
rule 'Warn about open door' do
  changed FrontDoor, to: OPEN, for: 10.minutes
  run { |event| logger.info("#{event.item.name} has been open for 10 minutes") }
end
rule 'Timer example' do
  on_start
  run do
    after(3.hours) { logger.info('3 hours have passed') }
  end
end