# Get a warning when any device has low battery?

**URL:** <https://community.homey.app/t/get-a-warning-when-any-device-has-low-battery/52280>\
**Category:** Flows\
**Created:** [September 27, 2021, 1:51pm UTC](https://community.homey.app/t/get-a-warning-when-any-device-has-low-battery/52280 "2021-09-27T13:51:57Z")\
**Posts on this page:** 2\
**Page:** 3

<div class="post-metadata">

**Author:** ![Franq](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/franq/32/81358_2.png) [@Franq](https://community.homey.app/u/Franq)\
**Post date:** [January 26, 2025, 3:47pm UTC](https://community.homey.app/t/get-a-warning-when-any-device-has-low-battery/52280/41 "2025-01-26T15:47:00Z")

</div>

Thanks. I posted it on github.

> <https://github.com/ricott/homey-com.volvocars/issues/43>
>
> Recently I added my car to homey. I get (push&timelime)notifications if the batt…ery is low. Is there a possibility that you exclude it from reporting as device battery? So that I do not get unnecessary notifications?
> 
> https://community.homey.app/t/get-a-warning-when-any-device-has-low-battery/52280/39?u=franq

---

<div class="post-metadata">

**Author:** ![Derk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/derk/32/79237_2.png) [@Derk](https://community.homey.app/u/Derk)\
**Post date:** [January 26, 2025, 7:19pm UTC](https://community.homey.app/t/get-a-warning-when-any-device-has-low-battery/52280/42 "2025-01-26T19:19:28Z")

</div>

I tried to solve this with this script:

```auto
// Script: Controleer accuniveaus van apparaten
const threshold = 20; // Drempelwaarde voor de batterij (in %)
let lowBatteryDevices = []; // Lijst om apparaten met lage batterij op te slaan

// Haal alle apparaten op
const devices = await Homey.devices.getDevices();

// Loop door alle apparaten
for (let deviceId in devices) {
  const device = devices[deviceId];
  
  // Controleer of het apparaat een batterij heeft
  if (device.capabilities.includes('measure_battery')) {
    const batteryLevel = device.capabilitiesObj.measure_battery.value;

    // Controleer of de batterij onder de drempel zit
    if (batteryLevel !== null && batteryLevel <= threshold) {
      lowBatteryDevices.push({
        name: device.name,
        battery: batteryLevel
      });
    }
  }
}

// Controleer of er apparaten met een lage batterij zijn
if (lowBatteryDevices.length > 0) {
  // Maak een melding
  let message = 'Apparaten met lage batterij:\n';
  lowBatteryDevices.forEach(device => {
    message += `- ${device.name}: ${device.battery}%\n`;
  });

  // Start de Flow om de pushmelding te verzenden
  await Homey.flow.triggerFlow({
    id: '3bc6999b-6f1b-450c-a31a-b5e77cc3c24b', // Gebruik hier de ID van je Flow
    tokens: { message } // Geef de melding door aan de Flow
  });

  // Log het resultaat
  console.log(message);
} else {
  console.log('Alle batterijen zijn OK!');
}

```

The script works fine and when testing, it exactly shows the right devices. The flow that actually sends the push message, looks like this:

 ![Pushmeldingflow](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/d/dd0cbce53d56b9154ef832c0d09035f602517cd3.png)

For screenshot purposes I left out the user. De message information generated by the script does not show in de actual push notification (it just shows this):

 ![Notifications](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/a/baafde2073f3a3cd9277fe1c3e5505a039f8f2b4.jpeg)

How do I solve this?

[Previous page](https://community.homey.app/t/get-a-warning-when-any-device-has-low-battery/52280.md?page=2)
