Starting flows from a script

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 :cross_mark: 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);

const variable = vars.find(v => v.name === ‘TimeLineMessage’);
const varlog = vars.find(v => v.name === ‘PublishLog’);
log(variable);
log(varlog);

if (!variable || !varlog) {
throw new Error(“Logic variable not found”);
}

if (variable.type !== ‘string’) {
throw new Error(Variable 'TimeLineMessage' must be of type 'string', but got '${variable.type}');
}

if (varlog.type !== ‘boolean’) {
throw new Error(Variable 'TimeLineMessage' must be of type 'boolean', but got '${varlog.type}');
}

const message = "Sensor restarted at " + new Date().toLocaleString();

await Homey.logic.updateVariable({id: variable.id, variable: {value: message}})
await Homey.logic.updateVariable({id: varlog.id, variable: {value: true}})
await Homey.logic.updateVariable({id: varlog.id, variable: {value: false}})