Finding a specific flow that causes a ghost trigger

Yesterday I started getting message notifications that a specific device is not responding. I looked through all the advanced flows I could think of to find the ghost message, to no avail. AI wrote me a short script to search all the flows for a specific phrase, and I found the culprit message source in a second or less.

I thought I would share the script here if someone needs a similar function.

Copy the script below and paste it into a Homey Script “‘Run my code’ with ‘MyArg’ and return Text-tag’”
Input Argument: Create a text tag with a simple json containing the search phrase, pass the text tag as the “argument”.
Add a Text-tag to receive the output of the script

Execute the flow and read the results in the text-tag.

It saved me hours of searching.

SCRIPT

// Search flows for phrase

let settings;

try {
settings = JSON.parse(args[0]);
} catch (e) {
return JSON.stringify({
error: “Invalid JSON argument”
});
}

const searchText = String(settings.search || “”).toLowerCase();

if (!searchText) {
return JSON.stringify({
error: “No search string supplied”
});
}

const result = {
search: settings.search,
matches: 0,
flows:
};

// ---------- Regular Flows ----------

const flows = await Homey.flow.getFlows();

for (const flowId in flows) {
const flow = flows[flowId];

const flowJson = JSON.stringify(flow).toLowerCase();

if (flowJson.includes(searchText)) {
    result.flows.push({
        type: "flow",
        name: flow.name,
        id: flow.id
    });
}

}

// ---------- Advanced Flows ----------

const advancedFlows = await Homey.flow.getAdvancedFlows();

for (const flowId in advancedFlows) {
const flow = advancedFlows[flowId];

const flowJson = JSON.stringify(flow).toLowerCase();

if (flowJson.includes(searchText)) {
    result.flows.push({
        type: "advancedflow",
        name: flow.name,
        id: flow.id
    });
}

}

result.matches = result.flows.length;

return JSON.stringify(result);

Hi @Theuns_vanNiekerk

There’s already an app that does that, the most excellent Device Capabilities app

For example:

Please format the code as code. I think you agree with me it makes no sense the way it is posted, plus it is impossible to copy/paste, when I only look to the fancy (double) quotes you posted. Only straight (double) quotes are valid.

.

About the peculiar variable as in-between: You can enter the JSON right into the argument field, just make sure it is on one line:

Imho the caseSensitive and maxResults options can be hard-coded in the script, which makes entering the search phrase less complicated.