I need to start a flow from a script. I have been experimenting with the code below, I partly found in this community and partly used the help from copilot. However it will not work, it finds the correct flow id, however it throws an error Script Error:warning: null . I have no clue anymore what’s wrong. here is my simple script. The error arises from await Homey.flow.runFlowCardAction({.
I have a 2019 Homey pro. Any ideas what I’m not seeing ?
const flow_name = ‘LogToTimeline’
log (‘start script’);
// filter flow object by flow name
const flows = await Homey.flow.getFlows();
//Find the flow name
const flow_obj = Object.values(flows).find(f => f.name === flow_name);
log(flow_obj);
// fetch flow id from flow object
const flow_id = flow_obj.id;
log (flow_id);
// start flow if there is a flowid found
if (flow_id){
await Homey.flow.runFlowCardAction({
uri: ‘homey:manager:flow’,
id: ‘programmatic_trigger’,
args: { flow: { id: flow_id } }
});
}
To overcome the issue, I now use a workaround, I trigger the flow when a variable has changed, and change the variable from the script. From software development perspective an awful solution, but I did not see another one, and end of the day it works. Here is my updated script :
const varsObj = await Homey.logic.getVariables();
const vars = Object.values(varsObj);