Skip to main content
Version: V3 (Ignition 8.3)

system.mes.meter.saveMeterType

Description

Creates or updates a Meter Type record in the system based on the provided parameters.

Permissions

This method requires the METERING.WRITE.SAVE permission.

Syntax

system.mes.meter.saveMeterType(**meterTypeData)

Parameters

ParameterTypeNullableDescription
idString (ULID)TrueThe ULID of the Meter Type (optional, used for updating an existing Meter Type).
nameStringFalseDisplay name for this meter type (e.g., Water, Electricity, Gas).
usageUnitOfMeasureIdString (ULID)FalseThe ULID of the unit of measure for usage values.
costDoubleFalseDefault cost per unit of measure. Default value is 0.0.
costUnitOfMeasureIdString (ULID)FalseThe ULID of the unit of measure for cost values.
notesStringTrueNotes related to the meter type.
enabledBooleanTrueIndicates if the meter type is active and enabled. Default value is true.
spare1StringTrueAdditional field for user-defined context.
spare2StringTrueAdditional field for user-defined context.
spare3StringTrueAdditional field for user-defined context.

Returns

Returns a JSON representation of the saved Meter Type.

Code Examples

# Generate the object structure for a new Meter Type, set the initial arguments and save it
newMeterType = system.mes.meter.newMeterType()
newMeterType['name'] = 'Electricity'
newMeterType['usageUnitOfMeasureId'] = '01J9YP3JBR-WQ8GWRR2-8Y879V2D'
newMeterType['cost'] = 0.12
newMeterType['costUnitOfMeasureId'] = '01J9YP3JBR-WQ8GWRR2-8Y879V2E'
savedMeterType = system.mes.meter.saveMeterType(**newMeterType)

# Output the JSON representation of the saved Meter Type
print(savedMeterType)

# Generate the object structure for another Meter Type to update the previous one
meterTypeData = system.mes.meter.newMeterType()

# Set basic attributes for the updated Meter Type
meterTypeData['id'] = savedMeterType['id']
meterTypeData['name'] = 'Electricity'
meterTypeData['usageUnitOfMeasureId'] = '01J9YP3JBR-WQ8GWRR2-8Y879V2D'
meterTypeData['cost'] = 0.15
meterTypeData['costUnitOfMeasureId'] = '01J9YP3JBR-WQ8GWRR2-8Y879V2E'
# (You can continue setting other properties as needed here)

# Save the Meter Type to update it in the system
updatedMeterType = system.mes.meter.saveMeterType(**meterTypeData)

# Output the JSON representation of the updated Meter Type
print(updatedMeterType)