Get a warning when any device has low battery?

Homey will inform you automatically, when the capacity of a battery will become less than 20 %. You can choose if you want to be informed in the timeline and/or via push notification. Make sure that the Energy notifications are enabled: Homepage → Timeline → … → Energy
So this feature exists.

But of course it’s also possible via flow(s).
The When… flow card can be found here: When… → Home → Cards → (Sensor) of any device changed.
(Sensor) is a drop down field where you have to choose Battery.

To ensure that the correct tags (device, sensor, value, zone) can be selected in the timeline notification, the previous flow cards must already be connected to each other. If you click on the tag symbol in the text field, then the relevant tags can be chosen:

1 Like

Thank you both for your help.

I had no idea this was a standard feature of Homey. I think this is a good example of where the Homey team should put more efforts, it’s difficult to locate such information (lack of real user guide / tutorials covering most basic features, although there are some good tutorials from the Homey team, but some basics seem to be left out)

I cannot find how to activate notification for low battery.

Here is what I see under Timeline (chronologie in French", no “ENERGY” under timeline

I also tried this scrren, but still no ENERGY section…

Regarding the flow itself, thank to your explanation, I found the “battery of any device changed” CARD, thanks

Regarding the second part I see you are showing advanced flow, this is probably why I was not able to achieve it. I need to take some time to understand advanced flows, i have not tried yet

Thanks a lot

Hm, strange! I know that some timeline categories are only available once a first timeline notification has been sent. Unfortunately, I cannot answer whether this is also the case with the energy category, sorry. Maybe someone else knows more about this.

With a normal flows it’s more or less the same way:

However, it’s also important here that the previous flow cards are already available.
If you insert first the timeline notification flow card, then alls the relevant tags are missing:

This is indeed the case.
I get a battery notification from Homey via the energy module if the level falls below 15% (apparently that is the internal threshold). Only after the first notification that timeline category became available.

1 Like

ok pretty, clear, but will I ever receive a notification if I have not activated it?
I hope by default the notifications are active, although i would never be able to set if to active :slight_smile:
Thanks

By default Homey will put a notification on its timeline. In addition you have the option to enable a push notification. That will only be send to the user that is the owner of Homey.

You can enable the push notification in the Homey app by going to the tab with the three dots (bottom right) > Settings > Timeline > Energy. There you’ll find a toggle to enable push notifications.

The Energy settings might not be available until after your first energy timeline notification. A timeline notification looks like this (sorry, it’s in Dutch - it say that the battery of a device is almost empty - but you get the picture I hope):

1 Like

thanks, I get the picture indeed, I’ll wait for the first notification
Have a great day

Olivier

What about HomeyScript? Is it any good on the Homey?

Forget it… I guess HomeyScript can’t send notifications or email… hmmm

Even if script can not - then the script output can be used from flow :wink:

Message sending tested on animals :face_with_hand_over_mouth:

1 Like

Funny you should mention that… I was JUST trying to do that. I have a flow called “Low Battery Notification” and it is triggered when I run my script but I was trying to pass the device(s) back and I am not seeing how you do that. I guess it does not have to pass device(s) names and could just send message “Low Battery” then you could go check what is low.

You have to replace to try this

Here is my flow

Here is the code:

// Get all devices
const devices = await Homey.devices.getDevices();

// Initialize an array to hold devices with low battery
let lowBatteryDevices = [];

// Set your battery threshold
const batteryThreshold = 20; // Change this value as needed

// Iterate over each device
for (let deviceId in devices) {
  let device = devices[deviceId];
  
  // Check if the device has a battery capability
  if (device.capabilities.includes('measure_battery')) {
    // Get battery level
    let batteryLevel = device.capabilitiesObj.measure_battery.value;
    
    // Debugging output
    console.log(`${device.name}: ${batteryLevel}%`);

    // Check if battery level is less than the threshold
    if (batteryLevel !== null && batteryLevel < batteryThreshold) {
      lowBatteryDevices.push(`${device.name}: ${batteryLevel}%`);
    }
  }
}

// If there are any devices with low battery, send a webhook
if (lowBatteryDevices.length > 0) {
  // Build the message with device names and battery levels
  let message = 'Low Battery Alert:\n' + lowBatteryDevices.join('\n');

  // Send a webhook to the flow you created
  const webhookEvent = 'low_battery_alert';
  const webhookUrl = `https://webhook.homey.app/<your id here>/${webhookEvent}`;

  // Send the webhook using fetch
  try {
    const response = await fetch(webhookUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ message, devices: lowBatteryDevices })
    });

    // Log the response to check for any errors
    const responseText = await response.text();
    console.log('Webhook sent. Response:', responseText);
  } catch (error) {
    console.error('Error sending webhook:', error);
  }
} else {
  console.log('No devices with low battery levels found.');
}

What is the advantage of solving this via a script and WebHooks?
Not to mention that another app, the HomeyScript app, is required.
I’m asking out of interest, not because I want to criticize your solution.

The idea is to get notification that a battery is low. I am guilty myself of not knowing and wondering why one of my shades did not open. When I look in Homey, I see that the battery is dead. I also will admit, I never looked around to see if there were apps to do this because I would rather keep the number of apps to a min. The other reason is that I just wanted to play with HomeyScript and see how it worked. Honestly it is flakey… that script ran and worked last night, today it doesn’t do anything.

This morning I uninstalled HomeyScript and am just using flow cards to send notification when battery drops below 20%… was fun while it lasted :slight_smile:

Ok, understand.

Maybe you didn’t read the whole thread, but the flow I posted in post #21 does exactly the same thing as your script. You can set the notification threshold yourself and will get a notification about the device name, the zone and the current charge state in percent. And no additional app is needed.
Just a hint.

1 Like

lol… no, I did not read the whole thread. Your flow is better than the script for sure. I am going to try and implement it, sounds great. Thanks!

1 Like

MUCH EASIER :slight_smile: Thank you @DirkG

Just another tip, should you run into the following situation.

The above flow might trigger multiple notifications a day for the same device. Especially when the battery level hovers around the threshold.

I use a boolean variable (per device) that indicates whether a notification has been sent that day. That variable is reset at the start of each new day.

The result is that each device notifies me only once a day in case of a low battery.

1 Like

Thanks a lot for sharing!

1 Like

Is it possible to exclude a device from the build in warnings when battery is low? I added my hybrid car and I get warnings when the battery is low. I want to exclude this car from the warnings.

AFAIK no. Maybe the app developer can add code to exclude it from reporting as device battery, because it’s a car battery.
I also would like to recommend to report to Athom homey.app/support, because for users, it should be possible to exclude home- & car batteries and the like, from the default low battery warning system.

For my vacuum cleaner, I ended up with using Timeline Wrangler script, to remove low battery warnings on the minute they’re sent:

1 Like