element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
N-gaged Design Challenge
  • Challenges & Projects
  • Design Challenges
  • N-gaged Design Challenge
  • More
  • Cancel
N-gaged Design Challenge
N-Gaged Blog PVMonitor #8 - Anomaly detection (2)
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Leaderboard
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: amgalbu
  • Date Created: 29 May 2022 7:48 AM Date Created
  • Views 465 views
  • Likes 1 like
  • Comments 0 comments
  • n-gaged design challenge
  • pvmonitor
  • iot system
  • OMEGA’s Layer N EcoSystem
  • n-gaged
  • remote monitoring
Related
Recommended

PVMonitor #8 - Anomaly detection (2)

amgalbu
amgalbu
29 May 2022
Blogs in this series
PVMonitor #1 - Unboxing and project description
PVMonitor #2 - Getting started
PVMonitor #3 - The great pretender (1)
PVMonitor #4 - The great pretender (2)
PVMonitor #5 - Installation and preliminary data
PVMonitor #6 - Anomaly detection
PVMonitor #7 - System performances
PVMonitor #8 - Anomaly detection (2)
PVMonitor #9 - Conclusions
 
 

This is the second part of the anomaly detection implementation. In the first part, I explained how I gathered data from the Omega Cloud N servers and analyzed data to create a prediction model for the daily yield

In this part, I will explain how I am going to run the prediction model every day in order to promptly report any abnormal condition detected by the model

1. The prediction model

According to my experiments, two approaches look valid to make a prediction of the expected daily yield

  • the first model is based tries to fit the input variables (luminance and temperature) with the output variables (DC power) with a curve that minimizes the squared error. This approach predicts wring values when production is low due to weather conditions (i.e. cloudy days)
  • the second model is based on LSTM neural network and tries to predict power production based on previous data considered as a time series. This model works good in almost all the weather conditions but has an obvious dependency on seasons which can be mitigated by training the model with data collected over a period of at least 6 months   

For the moment, I will focus on the LSTM model because looks more promising

The steps the run the prediction model are

1.1 Load data

Data for the current day. I will use the same REST APIs I described in my previous post

1.2 Load model parameters

During the data analysis phase, model parameters have been dumped to my Google Drive, so I can reload it quite easily

# load model
from google.colab import drive
drive.mount('/content/drive')

import shutil
shutil.copy('drive/MyDrive/lstm_model.h5','.')

import tensorflow as tf
model = tf.keras.models.load_model('lstm_model.h5')

1.3 Make predicition

To make the prediction, we need to extract data from the Pandas dataframe where I stored data collected from Omega Cloud N server. 

# get DC_POWER_SMA data
dataframe= pdata_sma["DC_POWER_SMA"]
dataset = dataframe.values
dataset = dataset.astype('float32')
dataset= dataset.reshape(-1, 1)
Data is then scaled because neural networks works better with normalized data
# normalize the dataset
scaler = MinMaxScaler(feature_range=(0, 1))
dataset = scaler.fit_transform(dataset)
Finally, we can make the prediction
# make prediction
prediction = model.predict(dataX)

prediction = scaler.inverse_transform(prediction)
Here is the result. The plot shows actual values and predicted values. The green line is the error, i.e. the difference between actual and predicted values at a certain time
image
.
1.4 Check for anomalies
Model prediction is compared with actual values. After some experiments with "fake" data, I think the best approach is the compare the mean error over a day with a fixed threshold. If the mean error is above a threshold, then something is wrong with the PV system 
MEAN_THRESHOLD = 1.0

if (abs(mean) > MEAN_THRESHOLD):
  sendNotification
.
1.5 Send notification
In case of anomaly, send a notification email. I will use my gmail account to send the notification email. First of all, you need an application password. Go to your Google account's management console and click "Security"
image
Click "App passwords"
image
Select an "Mail" in the "App type" combobox, select the device type and click "Generate"
image
The application password will be generated. Copy the password and paste in the sendNotification function shown below

import smtplib

def sendNotification():  
  # creates SMTP session
  s = smtplib.SMTP('smtp.gmail.com', 587)
  
  # start TLS for security
  s.starttls()
  
  # Authentication
  s.login("xxx at gmail.com", "yourapplicationkey")
  
  # message to be sent
  message = "An anomaly has been detected on your PV plant"
  
  # sending the mail
  s.sendmail("sender at anymail.com", "receiver at anymail.com", message)
  
  # terminating the session
  s.quit()

.

2. The scheduler

After many attempts to schedule a daily execution of the anomaly detection Python notebook, I finally moved the notebook itself to Kraggle, which provides a convenient scheduler

image

Now the anomaly detection algorithm will be executed every day and I will receive an email when daily power production is below the value predicted by the model

The source code of the Python notebook for anomaly detection is available on my github

<< Prev: System performances

Next: Conclusions >>

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube