# Set homekit\_exclude for all devices

**URL:** <https://community.homey.app/t/set-homekit-exclude-for-all-devices/91848>\
**Category:** Devices\
**Created:** [October 15, 2023, 12:54pm UTC](https://community.homey.app/t/set-homekit-exclude-for-all-devices/91848 "2023-10-15T12:54:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HansMax](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hansmax/32/88406_2.png) [@HansMax](https://community.homey.app/u/HansMax)\
**Post date:** [October 15, 2023, 12:54pm UTC](https://community.homey.app/t/set-homekit-exclude-for-all-devices/91848/1 "2023-10-15T12:54:40Z")

</div>

I want to add Homey as a Hub in Homekit…  
Homekit Hubs only support 150 Devices.  
I have way more than that. I see that there is a an option to exclude specific devices from homekit. But going into hundreds of devices to set this to true are way to many clicks… is there a way to write a script or sth to set device.settings.homekit\_exclude to true?

---

<div class="post-metadata">

**Author:** ![HansMax](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hansmax/32/88406_2.png) [@HansMax](https://community.homey.app/u/HansMax)\
**Post date:** [October 15, 2023, 1:10pm UTC](https://community.homey.app/t/set-homekit-exclude-for-all-devices/91848/2 "2023-10-15T13:10:26Z")

</div>

I found the solution. So I will put it here for all adventures on the same quest.

1. You need to create an API Key in the Settings.

2. Copy the Code to new homeyscript file.

3. Enjoy

````auto
let token = "YOUR_TOKEN_HERE";

// URL zur Homey-API für Geräte
const devicesUrl = "http://127.0.0.1/api/manager/devices/device";

async function updateDeviceSettings(deviceId, updatedSettings) {
    const deviceUrl = `${devicesUrl}/${deviceId}`;
    const response = await fetch(deviceUrl, {
        method: 'PUT',
        headers: {
            'Authorization': `Bearer ${token}`, 
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({ settings: updatedSettings })
    });

    if (!response.ok) {
        throw new Error(`HTTP error when updating device (${deviceId}) settings! Status: ${response.status}`);
    }
}

try {
    // Alle Geräte abrufen
    let response = await fetch(devicesUrl, {
        method: 'GET',
        headers: {
            'Authorization': `Bearer ${token}`
        }
    });

    if (!response.ok) {
        throw new Error(`HTTP error when fetching devices! Status: ${response.status}`);
    }

    const allDevices = await response.json();

    for (let deviceId in allDevices) {
        const device = allDevices[deviceId];
        const updatedSettings = { ...device.settings, homekit_exclude: true };
        await updateDeviceSettings(deviceId, updatedSettings);
    }

    return "HomeKit-Ausschluss für alle Geräte wurde erfolgreich auf 'true' gesetzt.";

} catch (error) {
    return `Error: ${error.message}`;
}```
````

---

<div class="post-metadata">

**Author:** ![Dijker](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@Dijker](https://community.homey.app/u/Dijker)\
**Post date:** [October 15, 2023, 1:11pm UTC](https://community.homey.app/t/set-homekit-exclude-for-all-devices/91848/3 "2023-10-15T13:11:53Z")

</div>

Pretty sure it is possible with a small simple script in the Web API Playground,

there are a lot of examples on the community, haven’t seen this request before but maybe you get inspired by one of this,  
[Developer Web API Playground - Notes of geeky oneliners](https://community.homey.app/t/developer-web-api-playground-notes-of-geeky-oneliners/24392)

or one of the many other posts.

---

<div class="post-metadata">

**Author:** ![Andres\_Acosta](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/andres_acosta/32/79881_2.png) [@Andres\_Acosta](https://community.homey.app/u/Andres_Acosta)\
**Post date:** [August 17, 2024, 10:00am UTC](https://community.homey.app/t/set-homekit-exclude-for-all-devices/91848/4 "2024-08-17T10:00:14Z")

</div>

For some reason, I get the following error when I execute the code.

Any suggestion?

SyntaxError: Unexpected end of input  
at new Script (node:vm:99:7)  
at HomeyScriptApp.runScript (/app/app.js:352:23)  
at Object.runScript (/app/api.js:30:38)  
at process.processTicksAndRejections (node:internal/process/task\_queues:95:5)
