0

I would like do do some simple calculations with two single dataports. E.g. calculation of electric power from current and voltage. -> SQRT(3) * V * I * cos phi.

The result shall be written to a new dataport "Power". Can anyone give me a hint how to do that with CEL? I do not understand the examples given in the documentation.

Thanks a lot.

Marc
  • 11
  • 2

1 Answers1

1

Here is a sketch, maybe it helps. It should produce a data point "power" that is calculated based on "voltage", "current" and "cosphi". You would need to edit the text below to replace it with the names that your actual device uses, both for the fragment type and the data point names. Note that the assumption is that voltage, current and cosphi come together as part of one measurement.

insert into
 CreateMeasurement
select
 m.measurement.source as source,
 current_timestamp().toDate() as time,
 "marc_Power" as type,
 {
  "marc_Power.power.value",
   Math.sqrt(3) * 
   getNumber(m, "marc_CurrentAndVoltageMeasurement.voltage.value") *
   getNumber(m, "marc_CurrentAndVoltageMeasurement.current.value") *
   getNumber(m, "marc_CurrentAndVoltageMeasurement.cosphi.value"),
  "marc_Power.power.unit", "kW"
 } as fragments
from
 MeasurementCreated m
where 
 getObject(m, "marc_CurrentAndVoltageMeasurement") is not null;
André
  • 668
  • 6
  • 11