Battery status report

A question from a novice user:

Is it possible to script a report in Homey Pro 2013 containing:
device name , battery type, battery status

I.E.
Thermometer1, CR2450, 77%

battery type = comment/note for device
I’ve added battery type as comment for each battery powered device.

If this is possible please help understanding how I can achieve this.

Somewhere in the forum you can find a few Homey scripts that you can use in a flow telling you the battery levels or treshholds of all your devices.
Just look it up in Search results for 'battery' - Homey Community Forum

Actually no, I didn’t find anything useful or understandable for a non programmer.
And the titles showing closely useful info are like in german (?).
TY anyway…

If your purpose is purely getting insight into that info, then you can also use the battery overview in the mobile app (via More … > Batteries)

Or the detailed/list view of the devices page in the web app.

TY!
The mobile “More - Batteries” is more or less what I’d like to see on web as well…
On the devices You need to go device by device, not as visual as on mobile app.
Well, if that’s the way then that’s the way then.
Thanks!

In the web app, if you select the list view:

Then you get a list of your devices, which includes the battery percentage and type:

1 Like

Thanks, that’s quite close to what I’m looking for.
As some devices doesn’t have battery type, I have added the info in additional info fields for those devices (like IKEA sensor and remote).
I was hoping that even the additional info could be made visible somehow.
This is good enough though.
Thanks!

1 Like

This “case” kept me awake for 3 nights, now I found a way to get the Notes field data, and edited a script for battery level reporting.
Can you test the code below?

Code

const devicesObject = await Homey.devices.getDevices({ filter: { class: 'sensor' } });
const deviceKeys = Object.keys(devicesObject);
const batteryLevels = [];

for (const deviceKey of deviceKeys) {
  const device = devicesObject[deviceKey];
  const batteryCapability = device.capabilitiesObj?.measure_battery;
    if (batteryCapability) {
      const batteryLevel = batteryCapability.value;
      const deviceName = device.name;
      const batteryInfo = device.energyObj.batteries;
      const deviceNote = device.note;
      batteryLevels.push({ name: deviceName, battery: batteryLevel, info: batteryInfo, note: deviceNote });
      }
  }
// Sort on charge level low > high
batteryLevels.sort(function(a, b) {
return a.battery - b.battery;
});

const batteryInfoText = batteryLevels.map((device) => `- ${device.name} \nCharge: ${device.battery}% \nInfo: ${device.info} \nNote: ${device.note}`).join('\n');
      
console.log('Device Battery info:\n' + batteryInfoText);
// for use in Homeyscript flow cards:
return 'Device Battery info:\n' + batteryInfoText;



NB
To have it formatted like:

You just have to change this line

const batteryInfoText = batteryLevels.map((device) => `- ${device.name} \nCharge: ${device.battery}% \nInfo: ${device.info} \nNote: ${device.note}`).join('\n');

into this:

const batteryInfoText = batteryLevels.map((device) => `${device.name}, ${device.info}, ${device.note}, ${device.battery}%`).join('\n');

Output:

3 Likes

THANKS!!!
Made small changes to “beautify” the output and now it’s pretty much what I was looking for!
(I know absolutely nothing about coding but trial-and-error works when You have a good base to start with!)
Again, thank You!

1 Like

I made a simple flow for it. Works fine, and I get a reminder every day to charge or replace battery’s

1 Like