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.
Points to note about Calculated Properties
- See the expression syntax used throughout DevicePilot including in CPs, including how to 'escape' property names which contain non-alphanumeric characters.
- $ts values are in milliseconds
- You can’t use CPs within CPs
- 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.
- 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.
- 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.
- Whitespace is ignored --- so feel free to use newlines & tabs/spaces to make structure clear.