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?
I found the solution. So I will put it here for all adventures on the same quest.
-
You need to create an API Key in the Settings.
-
Copy the Code to new homeyscript file.
-
Enjoy
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}`;
}```
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
or one of the many other posts.
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)