Calculated Properties

CPs can modify and combine incoming data using numeric, string and time-based operations, do unit conversion, select and combine properties, convert latitude/longitude into distance, integrate and differentiate ...and much more.

How-to Articles

Points to note about Calculated Properties

  1. See the expression syntax used throughout DevicePilot including in CPs, including how to 'escape' property names which contain non-alphanumeric characters.
  2. $ts values are in milliseconds
  3. You can’t use CPs within CPs
  4. Like normal properties, a CP is defined the same across all devices, but when it’s evaluated for a particular device it is calculated purely from other properties of that device. It can’t see the values of properties in other devices - to do that kind of analysis you need to use a KPI.
  5. Because a CP is calculated every time any of its inputs changes it can be used to merge event streams. But be careful that in some cases it can cause event duplication: if you have a CP which copies events from other properties, but is gated by the state of a third property, then a change in that third property will also cause a CP event.
  6. If a CP uses $previous then any properties it uses must always be set together (i.e. in the same message). So if your CP is e.g. "y - $previous/x" then x and y must always be set in the same message, otherwise $previous/x may sometimes return undefined.
  7. Whitespace is ignored --- so feel free to use newlines & tabs/spaces to make structure clear.