Unifi Protect - Alarm Trigger from Homey to Unifi - Webhook - POST

Zink
Sun, 15 Mar 2026 22:45:31 +0000
Tutorials

I searched I didn’t find anything about this so here goes my problem and solution, I hope it can help someone.

Problem: Using a Logic Flow card for a JSON POST request to trigger an alarm on Unifi Protect gives a self-signed certificate error.

Solution:
1 - UNIFI: On Unifi Protect go to Alarm Manager and create a new alarm triggered by a Webhook

2 - UNIFI: Go to Integrations and create new Api Key and name it Homey, save it well because it’s only shown once and never share it:

3 - HOMEY: Install the official App HomeyScript

4 - Create a HomeyScript (named for example: “Webhook-POST_to-Unifi.js”) with the following code:

// url comes from Unifi when you create an alarm
const url = 'https://xxx.xxx.xxx.xxx/proxy/protect/integration/v1/alarm-manager/webhook/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
// apiKey is created on Unifi Protect (Integrations-> Create New APi Key)
const apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

try {
  const response = await fetch(url, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': apiKey
    },
    agent:new https.Agent({ keepAlive: true, rejectUnauthorized: false }),
    // the body can be blank
    body: JSON.stringify({
      source: 'Homey',
      timestamp: new Date().toISOString()
    })
  });
  if (response.ok) {
    console.log('Sucess! Webhook sent.');
    return true;
  } else {
    console.log('Unifi error:', response.status);
    return false;
  }
} catch (error) {
  console.error('Execution error:', error.message);
  return false;
}

5 - On your Flow use a THEN card from HomeyScript with SCRIPT and select the “Webhook-POST-to-Unifi” from the drop down list:

NEXT STEPS:
I will try to change the script to allow for dynamic arguments, the URL and the API-key. Then the Api-Key can be stored on a Homey Variable called Unifi-ApiKey and that makes the flows cleaner. Then we can use the card “Run Script with Argument”. If someone knows how to change the code to allow this would be much apreciated.

1 post - 1 participant