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

Create Custom Meter with EnergyPlus/OpenStudio Python API

asked 2023-08-21 00:43:01 -0600

Elvis's avatar

Hi, I am just wondering if we can create Meter:Custom using EnergyPlus/OpenStudio Python API. If yes, importing key and variable names from a csv file would be more convenient. I didn't find any relevant examples. Thank you for your help.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2023-09-08 02:02:35 -0600

updated 2023-09-09 01:48:24 -0600

Why couldn't you? If the SDK has an object, the ruby and the python bindings have it too (very rare exceptions aside)

SDK Documentation: MeterCustom Class Reference

Ruby example of API: OpenStudio-Resources: meters.rb#L68-L88

Python works EXACTLY the same, syntax aside.

In [1]: import openstudio

In [2]: m = openstudio.model.exampleModel()

In [3]: meter = openstudio.model.MeterCustom(m)

In [4]: meter.setFuelType("Electricity")
Out[4]: True

In [5]: for l in m.getLightss():
   ...:     meter.addKeyVarGroup(l.nameString(), "Lights Electricity Energy")

In [6]: for e in m.getElectricEquipments():
   ...:     meter.addKeyVarGroup(e.nameString(), "Lights Electricity Energy")

In [7]: print(meter)
OS:Meter:Custom,
  {22211bf0-8e18-4956-9e3c-3038f8e7723e}, !- Handle
  Meter Custom 1,                         !- Name
  Electricity,                            !- Fuel Type
  Lights 1,                               !- Key Name 1
  Lights Electricity Energy,              !- Output Variable or Meter Name 1
  Printer,                                !- Key Name 2
  Lights Electricity Energy,              !- Output Variable or Meter Name 2
  Electric Equipment 1,                   !- Key Name 3
  Lights Electricity Energy;              !- Output Variable or Meter Name 3
edit flag offensive delete link more

Comments

Thank you very much Julien. Yes, I will use Ruby examples for reference.

Elvis's avatar Elvis  ( 2023-09-09 02:41:27 -0600 )edit
1

answered 2023-09-07 18:11:12 -0600

Elvis's avatar

I've figured out the question. Let me ask and answer myself. I am using OpenStudio Python API.

import csv
import openstudio

def create_meter_customs_from_csv(csv_file_path, model):
    meter_dict = {}
    output_meter_dict = {}

    with open(csv_file_path, 'r') as csvfile:
        csvreader = csv.reader(csvfile)

        next(csvreader) # Skip the header

        for row in csvreader:
            meter_name, fuel_type, key_name, output_variable_or_meter_name = row

            if meter_name not in meter_dict:
                meter = openstudio.model.MeterCustom(model)
                meter.setName(meter_name)
                meter.setFuelType(fuel_type)
                meter_dict[meter_name] = meter

                # Create and configure OutputMeter for the same MeterCustom
                output_meter = openstudio.model.OutputMeter(model)
                output_meter.setName(meter_name)
                output_meter.setReportingFrequency('timestep') # Options: 'detailed','timestep','hourly','daily', 'monthly'
                output_meter_dict[meter_name] = output_meter

            meter = meter_dict[meter_name]
            meter.addKeyVarGroup(key_name, output_variable_or_meter_name)

    print(f"Meter:Custom objects created: {list(meter_dict.keys())}")
    print(f"Output:Meter objects added: {list(output_meter_dict.keys())}")

# Usage
model = m  # Replace this with your OpenStudio model
create_meter_customs_from_csv('csv_file_path', model)
edit flag offensive delete link more

Your Answer

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

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 2023-08-21 00:43:01 -0600

Seen: 199 times

Last updated: Sep 09 '23