Some flow ideas if you like.
Auto remove certain ‘Low Battery’ notifications by Homey, most of the time annoying and useless when a device uses rechargable batteries, like robo mowers, and robo vacs
- This flow is triggered by new timeline notifications,
- If it matches the phrase you enter as argument to this Homeyscript card,
(find the used script below) -
- in this example:
**My_Mower** is low on battery
(an exact part of the original message in the Timeline notification),
- in this example:
- Then, it removes the timeline notification right away
.
- Detail of how to enter the search phrase argument
The slightly adjusted script:
-
- the argument is used with line
const containsText = args[0]; // Only deletes notifications that contains the specified text
- the argument is used with line
-
- The script returns the used argument along with the ‘flows removed’ message
-
- Note: the categories list is my own, but it is not used here
show me the script
// DEL timeline msgs ALL matching | Argument = searchphrase - Timeline_Wrangler v1.3p
// ==================== User Settings ====================
const deleteNotifications = true; // If "true": actually removes notifications, if "false": display only
const daysOld = 0; // Amount of days that need to have past before a notification is deemed old
const hoursOld = 0; // Amount of hours that need to have past before a notification is deemed old
const maximumNotifications = 250; // The maximum amount of notifications that stay, anything more will get deleted
const containsText = args[0]; // Only deletes notifications that contains the specified text, Empty ( '' ) = not used
const showCategories = false; // If "true" it will show all timeline categories you have and had in the past
const useCategory = false; // If "true" it will only remove from the specified categories below
// Separate categories by comma ( , )
const categories = [
'homey:manager:flow',
'homey:manager:presence',
'homey:manager:apps',
'homey:manager:updates',
'homey:manager:zigbee',
'homey:manager:energy',
'homey:manager:backup',
'homey:manager:users',
'homey:app:com.athom.flowchecker',
'homey:manager:security',
'homey:app:nl.qluster-it.DeviceCapabilities',
'homey:app:net.i-dev.betterlogic',
'homey:app:com.spkes.telegramNotifications',
'homey:manager:safety',
'homey:app:nl.nielsdeklerk.log',
'homey:manager:experiments',
];
// ==================== Don't change anything below here ====================
const removedNotifications = [];
const notificationCategories = [];
let amountNotifications = 0;
let amountKept = 0;
if (showCategories) {
await Homey.notifications.getOwners()
.then(owners => {
log(Object.keys(owners).length, 'Timeline Categorie(s):');
Object.keys(owners).forEach(key => {
if (owners[key].uriObj.hasOwnProperty('name')) {
log('-', owners[key].uriObj.name, (owners[key].uriObj.name.length <= 5) ? '\t\t\t|' : (owners[key].uriObj.name.length <= 12) ? '\t\t|' : '\t|', '\'' + key + '\'');
}
else {
log('- Unkown Name', '\t\t|', '\'' + key + '\'');
}
});
log('\n');
})
.catch(err => {
log(err);
return 'Getting categories failed';
});
}
await Homey.notifications.getNotifications()
.then(notifications => {
amountNotifications = Object.keys(notifications).length;
log(amountNotifications, 'Timeline Notification(s):');
Object.keys(notifications).forEach(key => {
const currentDate = new Date();
const dateCreated = new Date(notifications[key].dateCreated);
const timeDifference = (currentDate - dateCreated) / 1000;
const daysDifference = Math.floor(timeDifference / 86400);
const hours = Math.floor((timeDifference % 86400) / 3600);
const hoursDifference = Math.floor(timeDifference / 3600);
const minutes = Math.floor((timeDifference % 3600) / 60);
if (
((containsText.length > 0 && notifications[key].excerpt.toLowerCase().includes(containsText.toLowerCase()))
&& (daysDifference >= daysOld && hoursDifference >= hoursOld))
|| maximumNotifications < amountKept
) {
log('- Removing:', notifications[key].id, ' |', notifications[key].ownerUri, '|', notifications[key].excerpt, '(' + notifications[key].dateCreated + ' - ' + daysDifference + ' day(s), ' + hours + ' hour(s) and ' + minutes + ' minute(s) old)');
if (deleteNotifications) {
Homey.notifications.deleteNotification({id: notifications[key].id});
removedNotifications.push(notifications[key].id);
}
}
else if (
((containsText.length === 0 && useCategory)
&& (categories.includes(notifications[key].ownerUri))
&& (daysDifference >= daysOld && hoursDifference >= hoursOld))
|| maximumNotifications < amountKept
) {
log('- Removing:', notifications[key].id, ' |', notifications[key].ownerUri, '|', notifications[key].excerpt, '(' + notifications[key].dateCreated + ' - ' + daysDifference + ' day(s), ' + hours + ' hour(s) and ' + minutes + ' minute(s) old)');
if (deleteNotifications) {
Homey.notifications.deleteNotification({id: notifications[key].id});
removedNotifications.push(notifications[key].id);
}
}
else if (
((containsText.length === 0 && !useCategory)
&& (daysDifference >= daysOld && hoursDifference >= hoursOld))
|| maximumNotifications < amountKept
) {
log('- Removing:', notifications[key].id, ' |', notifications[key].ownerUri, '|', notifications[key].excerpt, '(' + notifications[key].dateCreated + ' - ' + daysDifference + ' day(s), ' + hours + ' hour(s) and ' + minutes + ' minute(s) old)');
if (deleteNotifications) {
Homey.notifications.deleteNotification({id: notifications[key].id});
removedNotifications.push(notifications[key].id);
}
}
else {
log('- Keeping: ', notifications[key].id, ' |', notifications[key].ownerUri, '|', notifications[key].excerpt, '(' + notifications[key].dateCreated + ' - ' + daysDifference + ' day(s), ' + hours + ' hour(s) and ' + minutes + ' minute(s) old)');
amountKept++;
}
});
})
.catch(err => {
log(err);
return 'Script failed';
});
if (removedNotifications.length > 0) {
return 'Removed ' + removedNotifications.length + ' out of ' + amountNotifications + ' notification(s).\nUsed Argument: ' + args[0];
}
return 'No notifications were (actually) removed. \nUsed Argument: ' + args[0];