Perhaps something like this:
const INVALIDATE_AFTER = 86400;
const invalidatedDevices = [];
for (const device of Object.values(await Homey.devices.getDevices())) {
for (const capabilityObj of Object.values(device.capabilitiesObj || {})) {
if (capabilityObj.lastUpdated && (Date.now() - new Date(capabilityObj.lastUpdated) > INVALIDATE_AFTER * 1000)) {
invalidatedDevices.push(device.name);
}
}
}
await tag('InvalidatedDevices', invalidatedDevices.join(', '));
return invalidatedDevices.length != 0;
This will mark a device as invalid if it hasn’t updated for at least one day (86400 seconds). It will set a token that can be used in a notification.