Alarm creation from Homey App and HomeyAPI

Hey, everybody.

I am trying to create an alarm clock in an application, but unfortunately there is only one way, through API. I seem to do everything according to the instructions, but I still get an error. Here is a sample of my code:

// Client creation
this.homeyClient = await HomeyAPI.createAppAPI({ homey: this.homey });

// Alarm creation
await this.homeyClient?.alarms.createAlarm({
                alarm: {
                  name: 'New Alarm',
                  time: '12:20',
                  enabled: true,
                  repetition: {
                    monday: true,
                    tuesday: false,
                    wednesday: true,
                    thursday: false,
                    friday: true,
                    saturday: false,
                    sunday: false,
                  },
                },
              }

I always end up getting an error:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot PUT /api/manager/alarms/alarm/</pre>
</body>
</html>
] {
  statusCode: 404,
  description: null
}

Obviously, I’ve thrown the permission for the API. Does anyone know what could be wrong?
I especially like it: “description: null:smile: :smile: :sweat_smile:

Status code 404 is most likely a HTML error code indicating page not found. So your URL is somehow wrong.

But I don’t specify any URL, just the embedded Homey functions.

closing ); is missing from the alarm create code

To create an alarm, the API should be using a POST request, not a PUT request (those are meant to update existing alarms).

If createAlarm uses a PUT instead, you may want to report this to Athom: Issues · athombv/homey-web-api-issues · GitHub

/api/manager/alarms/alarm/ is an URL.

That’s how the Web API works under the hood.

And that’s why it is called a Web API :grin:

Judging by how long it’s been since anyone has responded in the github, this problem is with us for a long time :cry:

Yes, I’m afraid so :frowning:

Maybe you can try a different API function to be sure the overall structure of your code is ok.