A smart grid is a new type of power system based on modern information technology, which utilises advanced communication, computing and control technologies and employs advanced sensors, measurement, communication and control devices that can monitor the status and operation of various devices in the power system in real-time and optimise the dispatch of the power system through intelligent algorithms to achieve efficient operation of the power system. However, due to its complexity and uncertainty, how to effectively perform real-time prediction is an important challenge. This paper proposes a smart grid real-time prediction model based on the attention mechanism of convolutional neural network (CNN) combined with bi-directional long and short-term memory BiLSTM.The model has stronger spatiotemporal feature extraction capability, more accurate prediction capability and better adaptability than ARMA and decision trees. The traditional prediction models ARMA and decision tree can often only use simple statistical methods for prediction, which cannot meet the requirements of high accuracy and efficiency of real-time load prediction, so the CNN-BiLSTM model based on Bayesian optimisation has the following advantages and is more suitable for smart grid real-time load prediction compared with ARMA and decision tree. CNN is a hierarchical neural network structure containing several layers such as a convolutional layer, pooling layer and fully connected layer. The convolutional layer is mainly used for extracting features from data such as images, the pooling layer is used for the dimensionality reduction of features, and the fully connected layer is used for classification and recognition. The core of CNN is the convolutional operation, a locally weighted summation operation on the input data that can effectively extract features from the data. In the convolution operation, different features can be extracted by setting different convolution kernels to achieve feature extraction and classification of data. BiLSTM can capture semantic dependencies in both directions. The BiLSTM structure consists of two LSTM layers that process the input sequence in the forward and backward directions to combine the information in both directions to obtain more comprehensive contextual information. BiLSTM can access both the front and back inputs at each time step to obtain more accurate prediction results. It effectively prevents gradient explosion and gradient disappearance while better capturing longer-distance dependencies. The CNN-BiLSTM extracts features of the data and then optimises them by Bayes. By collecting real-time data from the power system, including power, load, weather and other factors, our model uses the features of CNN-BiLSTM to deeply learn real-time load data from smart grids and extract key features to achieve future load prediction. Meanwhile, the Bayesian optimisation algorithm based on the model can optimise the model’s hyperparameters, thus improving the model’s prediction performance. The model can achieve accurate prediction of a real-time power system load, provide an important reference for the dispatch and operation of the power system, and help optimise the operation efficiency and energy utilisation efficiency of the power system.