Developer Web API Playground - Notes of geeky oneliners

I would like to add one of my favorites. It’s not a one liner but still useful.
This script lists all unused flows along with its folder path.

However be carefull if you want to use this script to remove all unused flows. Flows may be used from HomeyScript or set as favorite. This script only list flows that has a ‘Start as flow’ trigger and for which it can’t find a flow with a flowcard to trigger.

'use strict';
const folders = await Homey.flow.getFlowFolders(); 
const flowsDic = await Homey.flow.getFlows();
const flows = Object.values(flowsDic)
const triggers = flows.map(f => f.actions.filter(a => a.uri === 'homey:manager:flow' && 
                                                      a.id === 'programmatic_trigger').map(a => a.args.flow)).flat()
function getFolder(id) {
  if (folders[id]) {
    if (folders[id].parent) {
      return `${getFolder(folders[id].parent)} > "${folders[id].name}"`
    }
    return `"${folders[id].name}"`
  }
  return '';
}
log(`Searching in ${flows.length} flows\n---------------------\n`)
flows.filter(f => f.trigger.uri === 'homey:manager:flow' && 
                  f.trigger.id === 'programmatic_trigger' &&  
                  !triggers.find(t => t.id === f.id)
            ).forEach(flow => log(`${getFolder(flow.folder)} > ${flow.name}`));
2 Likes