Custom Unit conversion



We would like to be able to sum Gas consumption (in cubic meter) with electricity consumption (in kilowatt hour).
In order to do this, we are trying to convert the gas consumption to kilowatt hour, but that conversion that is not supported in the standard.

So, we tried to create a custom unit “kilowatt hour per cubic meter” with components “kilowatt_hour” and “cubic_meter” with the appropriate multiplier and order but it didn’t work;
We also tried to directly update the “component” part of the “cubic_meter” unit to add a reference to “kilowatt_hour”, but it didn’t work neither

Any hint of how we could do this ?


Since this isn’t a true unit conversion (you can’t actually convert from meters^3 to kilwoatthours…) you should define a metric do do the conversion. e.g. (if you estimate 150 kilwatt hours per cubic meter)

id: ‘KilowattHoursPerCubicMeterOfGas’,
name: “KilowattHoursPerCubicMeterOfGas”,
expression: “identity(treatAsUnit(‘kilowatt_hour_per_cubic_meter’, 150))”,
unit: “kilowatt_hour”

Then you can retrieve this value by evaluating the expression: “NaturalGasConsumption * KilowattHoursPerCubicMeterOfGas”

Of course, if you want to get REALLY fancy, you should rewrite KilowattHoursPerCubicMeterOfGas as a CompoundMetric which takes into consideration pressure, temperature, the specific TYPE of gas, etc.


Isn’t the purpose of the type UnitOfConversion?


No. UnitOfConversion is for use for units that have a constant conversion factor. e.g.
“sourceUom” : “kilowatt hour”,
“targetUom” : “therms”,
“conversionFactor” : 0.03413,

Note that converting from cubic_meters to kilowatt_hours is total nonsense unless you also specify cubic_meters OF WHAT.

there are probably 0 kwh in a m^3 of air, while there might be 10 kwh in a m^3 of natural gas, and 1000000kwh in a m^3 of uranium…