Hello, I want to set up a script that will analyze all my battery-powered modules to test if they respond and generate a report that I will send by email at a certain time. I’ve had instances where modules with a battery stuck at 33% stopped responding because the battery was actually defective. I’m looking to have the script ping the modules, and if the ping fails, display that information in the logs. Here’s the beginning of a script that might help you. There might be an app in the store that does this job, but I’m not aware of it.
async function checkBatteryDevices() {
try {
// Get all devices
const devices = await Homey.devices.getDevices();
// Log the list of all devices
log("All devices:", devices);
// Loop over all devices
for (const device of Object.values(devices)) {
// Log information about each device
log(`Device: ${device.name}, ID: ${device.id}, Capabilities: ${device.capabilities.join(', ')}`);
// Check if the device has the measure_battery capability
if (device.capabilities.includes('measure_battery') && device.capabilities.includes('alarm_contact')) {
// Check if the device is ready (online)
if (device.ready) {
log(`Device '${device.name}' (${device.id}) is online. OK`);
} else {
log(`Device '${device.name}' (${device.id}) is not online. Ne répond plus`);
}
}
}
log("Script Success");
} catch (error) {
log(`Script Error: ${error.message}`);
}
}
// Run the function
checkBatteryDevices();