Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Creating schedules with ruby

Hello, I am writing a measure in openstudio that takes user inputs about start and end times of charging of a system. I want to recreate the following compact schedule in Ruby with times 7:00, 17:00, 24:00 being user inputs.

Schedule:Compact,
ChargeSchedule,          !- Name
On/Off,                  !- Schedule Type Limits Name
Through: 12/31,          !- Field 1
For: Weekdays,           !- Field 2
Until: 7:00, 1,          !- Field 4
Until: 17:00, 0,         !- Field 6
Until: 24:00, 1,         !- Field 8
For: Weekends Holidays,  !- Field 9
Until: 24:00, 1,         !- Field 11
For: AllOtherDays,       !- Field 12
Until: 24:00, 1;         !- Field 14

I will then create a sensor to get the schedule value (the authorization to charge my system) for my calculation.

This what i've written so far

# Get user inputs
  charge_start = runner.getStringArgumentValue('charge_start', user_arguments)
  charge_end = runner.getStringArgumentValue('charge_end', user_arguments

# Convert HR:MM format into HR.fraction format
(c_start_hr, c_start_min) = charge_start.split(':')
(c_end_hr, c_end_min) = charge_end.split(':')
# Store re-formatted time values in shorthand variables for use in schedule building  cs: charge start , ce:charge end 
  cs = (c_start_hr.to_f + c_start_min.to_f / 60).round(2)
      ce = (c_end_hr.to_f + c_end_min.to_f / 60).round(2)

#Create Schedule Type Limits
  sched_limits_onoff = OpenStudio::Model::ScheduleTypeLimits.new(model)
      sched_limits_onoff.setName('OnOff')
      sched_limits_onoff.setNumericType('Discrete')
      sched_limits_onoff.setUnitType('Availability')
      sched_limits_onoff.setLowerLimitValue(0.0)
      sched_limits_onoff.setUpperLimitValue(1.0)

    # Create the Compact Schedule   
  charge_schedule = OpenStudio::Model::ScheduleCompact.new(model)
  charge_schedule.setName('Charge_Schedule')
  charge_schedule.setScheduleTypeLimitsName(sched_limits_onoff.handle.to_s)

Any indications on how to continue from here ?

Thanks