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
| Parameter | Type | Nullable | Description |
|---|---|---|---|
id | String (ULID) | True | The ULID of the Meter Type (optional, used for updating an existing Meter Type). |
name | String | False | Display name for this meter type (e.g., Water, Electricity, Gas). |
usageUnitOfMeasureId | String (ULID) | False | The ULID of the unit of measure for usage values. |
cost | Double | False | Default cost per unit of measure. Default value is 0.0. |
costUnitOfMeasureId | String (ULID) | False | The ULID of the unit of measure for cost values. |
notes | String | True | Notes related to the meter type. |
enabled | Boolean | True | Indicates if the meter type is active and enabled. Default value is true. |
spare1 | String | True | Additional field for user-defined context. |
spare2 | String | True | Additional field for user-defined context. |
spare3 | String | True | Additional 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)