Skip to main content
Version: V3 (Ignition 8.3)

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

ParameterTypeNullableDescription
idString (ULID)TrueThe ULID of the Meter Configuration (optional, used for updating an existing configuration).
nameStringFalseDisplay name for this meter configuration.
descriptionStringTrueOptional description.
equipmentIdString (ULID)FalseThe ULID of the equipment this configuration is attached to.
maxRecordDurationSecondsIntegerFalseMaximum record duration in seconds. Minimum value: 30. Default value is 600.
maxTimeBetweenExecutionsSecondsIntegerFalseMaximum seconds between data collection executions. Minimum value: 1. Default value is 5.
maxFlushIntervalSecondsIntegerTrueMaximum seconds between database flush operations. Minimum value: 10. Default value is 30.
pruneDaysIntegerTrueNumber of days to retain completed records before pruning.
meterTypeIdString (ULID)FalseThe ULID of the Meter Type being measured.
usageExpressionStringFalseIgnition expression returning the current usage counter value.
overflowValueDoubleTrueMaximum counter value before rollover. Null means no rollover.
costSourceStringFalseSource for cost calculation. One of: STATIC, FROM_METER_TYPE, EXPRESSION. Default is STATIC.
costDoubleTrueStatic cost per unit of measure (used when costSource is STATIC).
costExpressionStringTrueIgnition expression returning cost per unit (used when costSource is EXPRESSION).
costUnitOfMeasureIdString (ULID)TrueThe ULID of the unit of measure for cost values.
notesStringTrueNotes related to the meter configuration.
enabledBooleanTrueIndicates if the meter configuration 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 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)