Notification Profile Custom Function

Notification Profile Custom Function

In Zoho IoT, notification profiles are configurations that determine how and when notification related actions should be executed in response to alarms - either when a new alarm is created or when its status changes (severity, acknowledgement, resolution, etc.). A custom function linked to a notification profile enables you to implement tailored business logic or integrations whenever those alarm events occur.

This document explains how to create a notification profile custom function, how to associate it with a notification profile, and provides an example code demonstrating its use.

Creating a notification profile custom function

To create a notification profile custom function,
  1. Click Add Custom Function.



  2. Select Notification Profiles in the Category field.



  3. Provide the required details in the appropriate fields.
Example -
Language : Deluge
Model/Module: All Device Models (Select the model on which the device, asset, or location is based on)
Display Name: Create Device Disconnect Work Order (Provide a name of your choice)
Function Name: create_disconnect_work_order (Provide a name of your choice)
Description:  A custom function to create a work order every time a gateway device is disconnected from the application. 



  1. Click Save. This will open the Code Editor.



  2. Provide the required code.



  3. Click Save and Close.


Notification Profile Custom function sample code

Below is an example of how notification-profile custom functions can be used to automate actions when alarm-related events occur. In this scenario, the notification profile includes two custom functions: one that creates a new record whenever a gateway device is disconnected, and another that escalates a specific field value from High to Urgent when the alarm’s severity changes. Because the notification profile is triggered by these alarm events, both custom functions run automatically, ensuring timely record creation and proper escalation without requiring manual intervention.

This custom function creates a work order every time a gateway device disconnects. This is configured as the notification action.

json_string = {"workorder":{"Name":"Reconnect " + gateway_name,"Gateway_Name":gateway_name,"Gateway_Location":gateway_location,"Order_Status":"High","Alarm_ID":alarm_id},"Gateway_ID":gateway_id};
response = invokeurl
[
url :"https://app12345akyrw.zohoiot.com/iot/v1/workorder"
type :POST
parameters:json_string + ""
connection:"iot-connection"
];
info response;
This custom function updates work order status to Urgent if the issue isn't fixed within the define limit. This is configured as the escalation action.

filter = {"condition_text":"1","conditions":{"1":{"field":{"api_name":"Alarm_ID"},"comparator":"equal", "value":alarm_id}}};
get_url = appUrl + "/iot/v1/workorder?filter=" + encodeUrl(filter);
response = invokeurl
[
url :get_url
type :GET
connection:"iot"
];
workorder_id = response.get("workorder").get(0).get("id");
status_response = response.get("workorder").get(0).get("Order_Status").get("display_value");
if(status_response == "High")
{
json_string = {"workorder":{{"id":workorder_id,"Order_Status":{"display_value":"Urgent"}}}};
response_put = invokeurl
[
type :PUT
parameters:json_string + ""
connection:"iot"
];
info "RESPONSE:: " + response_put;
}

Associating to a notification profile

Once the custom function is created, it becomes available for selection when configuring a notification profile. You can associate the custom function in the Choose Actions field while creating or editing a notification profile.

While adding/editing a notification profile,
  1. Click Choose Action. This opens the Notification, Escalation, or Resolution action panel, depending on the action you want to configure.



  2. Click Add Action.



  3. Select Custom Function in the context menu.



  4. Select the required custom function and click Associate.



  5. Click Save in the action panel.



  6. Click Save in the notification profiles form.


The custom function will now be executed each time the notification profiles conditions are met.