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

Creating schedules with ruby

asked 2023-01-31 21:51:14 -0500

HoussemYounes's avatar

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

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2023-02-07 09:08:15 -0500

HoussemYounes's avatar

I wanted to create the Schedules programatically using only user arguments supplied to my measure. I eventually opted for a different approach, instead of using user argument to create the custom schedules and then get the schedule values via sensors, I use the arguments directly in my EMS program combined with conditional statements, for example :

IF (CurrentTime >= #{cs}) && (CurrentTime <= #{ce})
    SET #{charging_auth.name} = 1
ELSE
    SET #{charging_auth.name} = 0 
ENDIF

or

IF (Month == #{drm}) && (DayOfMonth == #{drd}) && (CurrentTime>= #{drst})&& (CurrentTime<=#{dret}) 
    SET DR_flag = 1 
    SET #{atc_charging_auth.name} = 0 
    SET #{atc_discharging_auth.name} = 1
ELSE 
    SET DR_flag = 0 
ENDIF

It does the trick

edit flag offensive delete link more
0

answered 2023-02-02 08:59:51 -0500

I'm not exactly answering your question here, but the most common way of creating schedules in OpenStudio is to use the ScheduleRuleset object. It is flexible, easy to use, and you can visually inspect the schedules in the OpenStudio application. You can also find lots of examples of using it. With the object, you create one or more ScheduleRules, where each rule contains a start/end date, what days of the week it applies to, and a value. (It will translate to a Schedule:Year, not a Schedule:Compact, in the IDF.)

edit flag offensive delete link more

Comments

I was looking into the ScheduleRulset object, it's quite easy to use in the GUI but I wanted to create it programatically, I eventually opted for EMS, it works for my application (my comment above). Thank you!

HoussemYounes's avatar HoussemYounes  ( 2023-02-07 09:11:37 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Careers

Question Tools

1 follower

Stats

Asked: 2023-01-31 21:51:14 -0500

Seen: 119 times

Last updated: Feb 07 '23