system.mes.meter.saveMeterConfiguration
Description
Creates or updates a Meter Configuration record in the system based on the provided parameters.
Permissions
This method requires the METERING.WRITE.SAVE permission.
Syntax
system.mes.meter.saveMeterConfiguration(**meterConfigData)
Parameters
| Parameter | Type | Nullable | Description |
|---|---|---|---|
id | String (ULID) | True | The ULID of the Meter Configuration (optional, used for updating an existing configuration). |
name | String | False | Display name for this meter configuration. |
description | String | True | Optional description. |
equipmentId | String (ULID) | False | The ULID of the equipment this configuration is attached to. |
maxRecordDurationSeconds | Integer | False | Maximum record duration in seconds. Minimum value: 30. Default value is 600. |
maxTimeBetweenExecutionsSeconds | Integer | False | Maximum seconds between data collection executions. Minimum value: 1. Default value is 5. |
maxFlushIntervalSeconds | Integer | True | Maximum seconds between database flush operations. Minimum value: 10. Default value is 30. |
pruneDays | Integer | True | Number of days to retain completed records before pruning. |
meterTypeId | String (ULID) | False | The ULID of the Meter Type being measured. |
usageExpression | String | False | Ignition expression returning the current usage counter value. |
overflowValue | Double | True | Maximum counter value before rollover. Null means no rollover. |
costSource | String | False | Source for cost calculation. One of: STATIC, FROM_METER_TYPE, EXPRESSION. Default is STATIC. |
cost | Double | True | Static cost per unit of measure (used when costSource is STATIC). |
costExpression | String | True | Ignition expression returning cost per unit (used when costSource is EXPRESSION). |
costUnitOfMeasureId | String (ULID) | True | The ULID of the unit of measure for cost values. |
notes | String | True | Notes related to the meter configuration. |
enabled | Boolean | True | Indicates if the meter configuration 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 Configuration.
Code Examples
# Generate the object structure for a new Meter Configuration, set the initial arguments and save it
newMeterConfig = system.mes.meter.newMeterConfiguration()
newMeterConfig['name'] = 'Main Panel kWh'
newMeterConfig['equipmentId'] = '01J9YP3JBR-WQ8GWRR2-8Y879V2D'
newMeterConfig['meterTypeId'] = '01J9YP3JBR-WQ8GWRR2-8Y879V2E'
newMeterConfig['usageExpression'] = '[.]Energy_kWh'
newMeterConfig['costSource'] = 'FROM_METER_TYPE'
savedConfig = system.mes.meter.saveMeterConfiguration(**newMeterConfig)
# Output the JSON representation of the saved Meter Configuration
print(savedConfig)
# Update the Meter Configuration to use a static cost instead
configData = system.mes.meter.newMeterConfiguration()
configData['id'] = savedConfig['id']
configData['name'] = 'Main Panel kWh'
configData['equipmentId'] = '01J9YP3JBR-WQ8GWRR2-8Y879V2D'
configData['meterTypeId'] = '01J9YP3JBR-WQ8GWRR2-8Y879V2E'
configData['usageExpression'] = '[.]Energy_kWh'
configData['costSource'] = 'STATIC'
configData['cost'] = 0.12
# (You can continue setting other properties as needed here)
updatedConfig = system.mes.meter.saveMeterConfiguration(**configData)
print(updatedConfig)