An Advanced Flow to re-enable a Flow, passing the flow ID/Name

Hi all,

Can I please ask for assistance from anyone smarter than me, cos I’m stumped.
The Flow Checker app (highly recommended BTW) can detect and return the name & ID of disabled flows. I have a few flows that can be disabled by the press of a Zigbee button. For example if you want to override the turning off of a light by a presence sensor to keep it on while you are in and out of a room.

Trying to be clever, I thought I could create a flow using Flow Checker to send a question via Push to my mobile, asking if I wanted to re-enable a flow, then pass the flows ID to the Then action card Enable Flow, to re-enable a detected disabled flow.

But you can’t use the values of the tags Flow & ID returned by the Flow Checker “is disabled” card to specify which Flow you want to enable. A Homey shortfall to be sure, but I was hoping someone might have an idea for a way around it???

Much appreciation and thanks

.

.

EDIT:

@martijnpoppen as it’s your awesome Flow Checker app I’m using here, do you have any ideas how I might accomplish this (and yes I use a number of your apps, cos they’re all brilliant and very useful :star: )

@Drako74 use a HomeyScript :smiley: and provde the tags to it.

// args[0] = flow ID passed in from the Flow card
const flowId = args[0];
const enable = args[1] === 'true'; // pass 'true'/'false' as second arg, or use a boolean tag

const flows = await Homey.flow.getFlows();
const advancedFlows = await Homey.flow.getAdvancedFlows();
const flow = flows[flowId] || advancedFlows[flowId];

if (!flow) {
  log(`Flow with ID ${flowId} not found`);
} else {
  if (flows[flowId]) {
    await Homey.flow.updateFlow({ id: flowId, flow: { enabled: enable } });
  } else {
    await Homey.flow.updateAdvancedFlow({ id: flowId, advancedFlow: { enabled: enable } });
  }
  log(`Flow "${flow.name}" ${enable ? 'enabled' : 'disabled'}`);
}

@martijnpoppen as usual you are a legend sir, I doff my hat to you.

It might take me a little time to get my thick head around that, so I can make my advanced flow work the way I want it… but nonetheless I am extremely grateful and appreciative of your knowledge and expertise. The Homey Wizard :mage: Thank you

Unfortunately my Homey (Java) Script understanding is almost non-existent, and I couldn’t get it to work. Just kept returning the error “Missing Parameter: advancedflow” and I can’t figure out how to fix it

Not a fix, but do you know that instead of asking “Y/N”, you can also use the “Confirm” condition card?

Then you get yes/no buttons in the notification

I hadn’t seen that before… but now you’ve mentioned it I went looking for it, thank you :+1:t3:

But yes, I still can’t get the script part to work… been scratching my head for hours, but I think it’s just over my head :disappointed_face: oh well

Can you share the non-working script? So copy it exactly from the HomeyScript card

@Drako74
sorry small change:

const flowId = args[0];
const enable = true;

const flows = await Homey.flow.getFlows();
const advancedFlows = await Homey.flow.getAdvancedFlows();
const flow = flows[flowId] || advancedFlows[flowId];

if (!flow) {
  log(`Flow with ID ${flowId} not found`);
} else {
  if (flows[flowId]) {
    await Homey.flow.updateFlow({ id: flowId, flow: { enabled: enable } });
  } else {
    await Homey.flow.updateAdvancedFlow({ id: flowId, advancedFlow: { enabled: enable } });
  }
  log(`Flow "${flow.name}" ${enable ? 'enabled' : 'disabled'}`);
}

try like this:

and if you want a disable flow you create a additional script

Thank you. Tried the revised script code, still gives error about advanced flow.

This is the advanced flow:

This is the full error it returns:

❌ Script Error

⚠️ Error: Missing Parameter: advancedflow
    at ManagerFlow.value (/app/node_modules/homey-api/lib/HomeyAPI/HomeyAPIV3/Manager.js:192:27)
    at Test.js:14:22
    at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
    at async HomeyScriptApp.runScript (/app/app.js:364:22)
    at async /app/lib/flow/actions/RunCodeWithArgAction.js:29:9
{"message":"Missing Parameter: advancedflow"}

Also tried it like this, but get the same error:

This is the whole thingymajig I am trying to achieve. This is the last part to get working as desired, if it’s possible.

@Drako74
Ah typo from my side

const flowId = args[0];
const enable = true;

const flows = await Homey.flow.getFlows();
const advancedFlows = await Homey.flow.getAdvancedFlows();
const flow = flows[flowId] || advancedFlows[flowId];

if (!flow) {
  log(`Flow with ID ${flowId} not found`);
} else {
  if (flows[flowId]) {
    await Homey.flow.updateFlow({ id: flowId, flow: { enabled: enable } });
  } else {
    await Homey.flow.updateAdvancedFlow({ id: flowId, advancedflow: { enabled: enable } });
  }
  log(`Flow "${flow.name}" ${enable ? 'enabled' : 'disabled'}`);
}

I’ll give it another try when I get home… just visiting my mum after surgery… I’ll let you know how I get on soon as had chance to try it. Thank you, your expertise and assistance are very much appreciated :blush::sign_of_the_horns:t3:

You sir are a leg-end… finally got it working :smiley::smiley::smiley:

Breathes a sigh of relief, that is awesome, truly awesome. Thank you!

.

And thank you @smarthomesven for the tip on the response card… I’m going to create a :poop: tone of flows using that now, just cos I can :zany_face:

Thank you kindly gentlemen for your valued assistance.