Phi function reference

 

IoT-specific function reference

The following functions from PHP and Twig are available in Phi:

  • dump(string)

    returns null

    An alias of print(), this allows you to check the value of variables while testing your code. The data processor ignores this function.

  • exit()

    An alias of return(), call this to end the current Phi script. Any code after this will not be run.

    Note that this is a function, so you need to include the brackets when calling it.

  • fireTrigger(triggerCodeName, explanation)

    returns null

    If you create a trigger, and choose the ”Triggered from the Phi code“ option, then the trigger will not be set until you call the fireTrigger() function in your Phi code for the asset or data pool.

    Note that if the trigger was set the last time the Phi code was run, and you call the fireTrigger() function again, then there will be no further effect. However if the trigger was set the last time the Phi code was run, and you don't call the fireTrigger() function again, then the trigger will turn off.

  • getAllChildIds([schema[, nodeId]])

    returns ids

    This gives you all of the children of the current asset or data pool.

    You can optionally filter by a specific schema.

    This checks from the current asset or data pool by default, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds() or getAllChildIds() function to override this.

  • getHistoricValue(key, timestamp[, nodeId])

    returns value

    Looks up the value of a field at the specified timestamp.

    This checks the current asset or data pool, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds() or getAllChildIds() function to override this.

  • getImmediateChildIds([schema[, nodeId]])

    returns ids

    This gives you all of the immediate children of the current asset or data pool.

    You can optionally filter by a specific schema.

    This checks from the current asset or data pool by default, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds() or getAllChildIds() function to override this.

  • getInheritedMetadata(key[, nodeId])

    returns value

    Looks up the value of a metadata field.

    This checks the current asset or data pool, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds() or getAllChildIds() function to override this.

    If the requested field was not set for the specified asset or data pool, the system will check the data pools above in the hierarchy until it finds one with the field set.

  • getMetadata(key[, nodeId])

    returns value

    Looks up the value of a metadata field.

    This checks the current asset or data pool, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds() or getAllChildIds() function to override this.

  • getMetricValue(key, fromTimestamp[, nodeId])

    returns value

    Looks up the value of a field from a metric at the specified timestamp.

    Metrics are indexed by their fromTimestamp time, and not their toTimestamp time. E.g. if you wish to get the value of a monthly metric in June, you should use a timestamp from June (e.g. 1st June 00:00:00 is best, but any timestamp from June will work).

    Note that a timestamp of 1st July 00:00:00 would not work in this example, as this would give you the metric from July.

    This checks the current asset or data pool, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds() or getAllChildIds() function to override this.

  • getMinValue(key, fromTimestamp, toTimestamp[, assetIds])

    returns value

    Looks up the smallest value of a field between the specified timestamps.

    This checks the current asset or data pool, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds() or getAllChildIds() function to override this.

  • getMaxValue(key, fromTimestamp, toTimestamp[, assetIds])

    returns value

    Looks up the largest value of a field between the specified timestamps.

    This checks the current asset or data pool, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds() or getAllChildIds() function to override this.

  • getParentNodeId([schema[, nodeId]])

    returns id

    This gives you the node id of the data pool above the current node.

    You can optionally filter by a specific schema, in which case you'll get an id of a data pool above the current node that has the specified schema. If you don't specify a schema then you'll get the id of the data pool immediately above the current node.

    This checks from the current asset or data pool by default, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds() or getAllChildIds() function to override this.

  • getTimestamp(description[, timestamp])

    returns number

    Generates a timestamp as described above.

  • query(fromTimestamp, toTimestamp, nodeIds)

    returns value

    This finds all of the data for the specified assets, between the specified timestamps.

    This returns a cursor of results that you can loop through using a for () loop.

  • setValue(key, value)

    returns null

    Sets the value of a calculated field, as described above.