diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index e25884a9..aafe0a51 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -3274,7 +3274,24 @@ exports.motorAction = async (req, reply) => { } } else if (action === "stop") { - await stopMotor(motorId, customerId, start_instance_id); + // Dynamically find start_instance_id from tank + const tankWithMotor = await Tank.findOne({ + customerId, + "connections.inputConnections.motor_id": motorId + }); + + let dynamicInstanceId = null; + + if (tankWithMotor) { + const connection = tankWithMotor.connections.inputConnections.find(conn => conn.motor_id === motorId); + if (connection && connection.start_instance_id) { + dynamicInstanceId = connection.start_instance_id; + } + } + + await stopMotor(motorId, customerId, dynamicInstanceId); + + try {