Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Notifications
Login / Register
Community
Community
Notifications
close
  • Forums
  • Knowledge Center
  • Events & Webinars
  • Ideas
  • Blogs
Help
Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Login / Register
Sustainability
Sustainability

Join our "Ask Me About" community webinar on May 20th at 9 AM CET and 5 PM CET to explore cybersecurity and monitoring for Data Center and edge IT. Learn about market trends, cutting-edge technologies, and best practices from industry experts.
Register and secure your Critical IT infrastructure

Spacelynk: How to export data from trend logs to a .xls file?

SpaceLogic KNX Forum

Schneider Electric SpaceLogic KNX forum to get support and share knowledge including selection, installation and troubleshooting for spaceLYnk, Wiser for KNX, eConfigure KNX, SpaceLogic KNX Hybrid module and other topics.

cancel
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Home
  • Schneider Electric Community
  • EcoStruxure Building
  • Light and Room Control
  • SpaceLogic KNX Forum
  • Spacelynk: How to export data from trend logs to a .xls file?
Options
  • Mark Topic as New
  • Mark Topic as Read
  • Float this Topic for Current User
  • Bookmark
  • Subscribe
  • Mute
  • Printer Friendly Page
Invite a Co-worker
Send a co-worker an invite to the portal.Just enter their email address and we'll connect them to register. After joining, they will belong to the same company.
You have entered an invalid email address. Please re-enter the email address.
This co-worker has already been invited to the Exchange portal. Please invite another co-worker.
Please enter email address
Send Invite Cancel
Invitation Sent
Your invitation was sent.Thanks for sharing Exchange with your co-worker.
Send New Invite Close
Top Experts
User Count
Thomas_Rohde
Sisko Thomas_Rohde Sisko
121
Erwin-vd-Zwart
Sisko Erwin-vd-Zwart Sisko
54
Heribert_Dölger
Lt. Commander Heribert_Dölger Lt. Commander
30
FZetina
Lt. Commander FZetina Lt. Commander
27
View All
Related Products
product field
SpaceLogic KNX - 4ʺ Touch Unit
product field
KNX Push Button Dynamic Labeling, universal
product field
Wiser for KNX : logic controller

Invite a Colleague

Found this content useful? Share it with a Colleague!

Invite a Colleague Invite
Solved Go to Solution
Back to SpaceLogic KNX Forum
Solved
Anonymous user
Not applicable

Posted: ‎2016-08-29 07:55 AM . Last Modified: ‎2024-07-14 11:54 PM

0 Likes
6
693
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2016-08-29 07:55 AM

Spacelynk: How to export data from trend logs to a .xls file?

I have a energy counter and i would like to save data during a month and then export everything to .xls format and send by e-mail. can anyone help me please

  • Thumbnail of SpaceLogic KNX - 4ʺ Touch Unit
    SpaceLogic KNX - 4ʺ Touch Unit
  • Thumbnail of KNX Push Button Dynamic Labeling, universal
    KNX Push Button Dynamic Labeling, universal
  • Thumbnail of Wiser for KNX : logic controller
    Wiser for KNX : logic controller
View products (3)
Reply
  • All forum topics
  • Previous Topic
  • Next Topic

Accepted Solutions
Thomas_Rohde
Sisko Thomas_Rohde Sisko
Sisko

Posted: ‎2016-08-31 11:42 PM

0 Likes
0
603
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2016-08-31 11:42 PM

Hi Pedro, attached you will find an updated version of a script which fits to the new internal SW and has now a clear structure in terms of script area where you need to make your adaptations and the other which doesnt need to be changed.

Kind regards

Thomas Rohde

--**************************************************************************--

--** Email trendlog data as CSV attachment created by Erwin van der Zwart **--

--************ For HL from FW 1.5 and SL from FW 1.2 with NGINX ************--

--**************************************************************************--

--*************************** Start of parameters **************************--

--**************************************************************************--

--Gmail (smtp) username !IMPORTANT!

user = 'YOUR EMAIL ADRESS'

--Gmail (smtp) password !IMPORTANT!

password = 'YOUR PASSWORD'

--Sender for e-mail

from = '<' .. user .. '>'

alias_from = 'YOUR ALIAS'

--Recipient for e-mail

to = '<receiver@domain.com>'

alias_to = 'receiver'

--Subject for e-mail

subjectpart1 = 'Trend export file'

subjectpart2 = 'automaticly send by homeLYnk'

--Message on bottom of email (will only be showed when client don't understand attachment)

epilogue = 'End of message'

--Set export mode (selected trend(s) or all trends)

export_all = false

--Set trend names if not all trends need to be exported (only used when export_all = false)

trendnames = {

  "Total Electric Usage",

  "Total Water Usage",

  "Total Gas Usage",

}

--**************************************************************************--

--**************************** End of parameters ***************************--

--**************************************************************************--

--****************** DON'T CHANGE ANYTHING UNDER THIS LINE *****************--

--**************************************************************************--

require('trends')

-- Get all trend names from DB

trends_table = db:getall('SELECT name FROM trends ORDER BY name DESC')

-- Check if all trends or selection neeed to be exported

if export_all == false then

  -- Loop through trends_table

  i = 1

    for _, trend_names in ipairs(trends_table) do

    delete_from_table = true

    -- Loop through trendnames

    for _, trendname in ipairs(trendnames) do

      if trendname == trend_names.name then

            delete_from_table = false

      end

    end

    if delete_from_table == true then

      table.remove(trends_table, i)

      end

      i = i + 1

  end

end

-- Check if the is at least 1 trend to be exported

if #trends_table < 1 then

  log("No trends available, Could not export trends")

  return

end

-- csv buffer

buffer = {}

-- Add to buffer

table.insert(buffer, '"This file contains the export data of ' .. #trends_table .. ' trend(s) and is automaticly created on ' .. os.date("%A",os.time()) .. ' ' .. os.date("%d-%m-%y at %H:%M") .. '"')

-- Add empty line

table.insert(buffer, '""')

-- months

local months = { "Januari", "Februari", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }

-- Loop through trends_table

for _, trend_names in ipairs(trends_table) do

  -- Grab trend name from DB table

  trend_name = trend_names.name

 

  -- Add to buffer

  table.insert(buffer, '"##### START OF TREND ' .. _ .. ': ' .. trend_name .. ' #####"')

  -- Add empty line

  table.insert(buffer, '""')

  -- Get current timestamp

  timestamp = os.time()

  now = os.date('*t', timestamp)

 

  -- get data for the past year

    dates = {}

  dates['start'] = now

  if dates['start'].month == 1 then

      dates['start'].month = 12

    dates['start'].year = dates['start'].year - 1

  else

    dates['start'].month = dates['start'].month - 1

  end

  dates['end'] = os.date('*t')

 

  -- Set resolution to dayly data

  resolution = 86400

 

  -- Get last month for data by each days in this month

  trenddatamonth = trends.fetch(trend_name, dates, resolution)

 

  -- Get last month total avarage data

  trenddatamonthavg = trends.fetchone(trend_name, dates, resolution)

 

  -- Add to buffer

  table.insert(buffer, '"Export of the average usage of the month ' .. months[dates['start'].month] .. ' from trend ' .. trend_name .. '"')

  -- Add empty line

  table.insert(buffer, '""')

  -- Add header

  table.insert(buffer, '"Start date","End Date","Average month value"')

  -- Add to buffer

  table.insert(buffer, '"01-' .. string.format("%02d", dates['start'].month) .. "-" .. dates['start'].year .. '","' .. #trenddatamonth .. '-' .. string.format("%02d", dates['start'].month) .. "-" .. dates['start'].year .. '","' .. trenddatamonthavg .. '"')

  -- Add empty line

  table.insert(buffer, '""')

  -- Add to buffer

  table.insert(buffer, '"Detailed export of the daily usage of the month ' .. months[dates['start'].month] .. ' from trend ' .. trend_name .. '"')

  -- Add empty line

  table.insert(buffer, '""')

  -- Add header

  table.insert(buffer, '"Weekday","Date","Average day value"')

  for _, row in ipairs(trenddatamonth) do

    stamp = dates['start'].year .. '-' .. dates['start'].month .. '-' .. string.format("%02d", _)

        local y, m, d = stamp:match("(%d+)%-(%d+)%-(%d+)")

        local t = { year = y, month = m, day = d} 

    -- format csv row

    csv = string.format('%q,%q,%q', os.date("%A",os.time(t)), "" .. string.format("%02d", _) .. "-" .. string.format("%02d", dates['start'].month) .. "-" .. dates['start'].year, row)

    -- add to buffer

    table.insert(buffer, csv)

  end

  -- Add empty line

  table.insert(buffer, '""')

  -- Add header

  table.insert(buffer, '"##### END OF TREND ' .. _ .. ': ' .. trend_name .. ' #####"')

  -- Add empty line

  table.insert(buffer, '""')

end

--Create table to include mail settings

local settings = {

    from = from,

    rcpt = to,

    user = user,

    password = password,

    server = 'smtp.gmail.com',

    port = 465,

    secure = 'sslv23',

}

--Create attachment inside FTP server

src = 'Trend Export '.. os.date('%Y-%m-%d %H#%M#%S') .. '.csv'

dst = '/home/ftp/' .. src

io.writefile(dst, buffer)

--Create subject

subject = subjectpart1 .. ": " .. src .. " " .. subjectpart2

--Load required modules to send email with attachment

local smtp = require("socket.smtp")

local mime = require("mime")

local ltn12 = require("ltn12")

--Create e-mail header

settings.source = smtp.message{

headers = {

          from = '' .. alias_from .. ' ' .. from .. '',

          to = '' .. alias_to .. ' ' .. to .. '',

          subject = subject

},

--Load attachment inside body    

body = {

preamble = "",

[1] = { 

        headers = {

           ["content-type"] = 'text/plain',

           ["content-disposition"] = 'attachment; filename="'..src..'"',

           ["content-description"] = '.. src ..',

           ["content-transfer-encoding"] = "BASE64",

        },

        body = ltn12.source.chain(

          ltn12.source.file(io.open(dst, "rb")),

          ltn12.filter.chain(

          mime.encode("base64"),

          mime.wrap()

        )

      )

    },

      epilogue = epilogue

  }

}

--Send the email

r, e = smtp.send(settings)

--Create alert when sending gives an error with error message

if (e) then

  log (e)

  log (r)

  alert("Could not send email: ", e, "\n")

end

--Delete created backup file from ftp folder inside HL

os.remove(dst)

Kind regards
Thomas

Application Design Engineer

See Answer In Context

Reply
Replies 6
Benji
Administrator Benji Administrator
Administrator

Posted: ‎2016-08-30 01:31 AM

0 Likes
1
603
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2016-08-30 01:31 AM

For your convenience, in the future please place your question in the corresponding sub community as more people will see it there. This question had been placed in "Community Help", and only people following this sub Community will get notified. You find the sub communities in the top left part. Click "Communities" and then select the area your question is about.

I've moved this question for you.

Reply
Thomas_Rohde
Sisko Thomas_Rohde Sisko
Sisko

Posted: ‎2016-08-30 06:07 AM

0 Likes
0
603
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2016-08-30 06:07 AM

Hi Benjamin, thanks a lot for placing this topic into the right section!

Kind regards
Thomas

Application Design Engineer
Reply
Thomas_Rohde
Sisko Thomas_Rohde Sisko
Sisko

Posted: ‎2016-08-30 06:14 AM

0 Likes
1
603
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2016-08-30 06:14 AM

Hi Pedro, where are you struggling in detail?

- Are you able to sent an email in general?

     => if the answer is no please check out this application-note first AN011_SL - Email, SMS and FTP in spaceLYnk

     => if the answer is yes than I will work with you on a script which realizes the monthly trend-report.

Please let me know.

Kind regards

Thomas

Kind regards
Thomas

Application Design Engineer
Reply
Thomas_Rohde
Sisko Thomas_Rohde Sisko
Sisko

Posted: ‎2016-08-31 05:20 AM . Last Modified: ‎2022-10-18 10:32 PM

0 Likes
0
603
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2016-08-31 05:20 AM

Hi Pedro,

I found within the community here already an example to store all scripts on regular base to a ftp. Means the script needs to be updated.

With the following link you will find script for all trends:

https://community.se.com/message/79811#79811

With the following link you will find script for a single trend:

https://community.se.com/message/79812#79812

Please let me know if this is helpful for you and you can adapt the script to sending an email by yourself.

Otherwise we will go ahead ;o)

Kind regards

Thomas 

Kind regards
Thomas

Application Design Engineer
Reply
Thomas_Rohde
Sisko Thomas_Rohde Sisko
Sisko

Posted: ‎2016-08-31 11:42 PM

0 Likes
0
604
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2016-08-31 11:42 PM

Hi Pedro, attached you will find an updated version of a script which fits to the new internal SW and has now a clear structure in terms of script area where you need to make your adaptations and the other which doesnt need to be changed.

Kind regards

Thomas Rohde

--**************************************************************************--

--** Email trendlog data as CSV attachment created by Erwin van der Zwart **--

--************ For HL from FW 1.5 and SL from FW 1.2 with NGINX ************--

--**************************************************************************--

--*************************** Start of parameters **************************--

--**************************************************************************--

--Gmail (smtp) username !IMPORTANT!

user = 'YOUR EMAIL ADRESS'

--Gmail (smtp) password !IMPORTANT!

password = 'YOUR PASSWORD'

--Sender for e-mail

from = '<' .. user .. '>'

alias_from = 'YOUR ALIAS'

--Recipient for e-mail

to = '<receiver@domain.com>'

alias_to = 'receiver'

--Subject for e-mail

subjectpart1 = 'Trend export file'

subjectpart2 = 'automaticly send by homeLYnk'

--Message on bottom of email (will only be showed when client don't understand attachment)

epilogue = 'End of message'

--Set export mode (selected trend(s) or all trends)

export_all = false

--Set trend names if not all trends need to be exported (only used when export_all = false)

trendnames = {

  "Total Electric Usage",

  "Total Water Usage",

  "Total Gas Usage",

}

--**************************************************************************--

--**************************** End of parameters ***************************--

--**************************************************************************--

--****************** DON'T CHANGE ANYTHING UNDER THIS LINE *****************--

--**************************************************************************--

require('trends')

-- Get all trend names from DB

trends_table = db:getall('SELECT name FROM trends ORDER BY name DESC')

-- Check if all trends or selection neeed to be exported

if export_all == false then

  -- Loop through trends_table

  i = 1

    for _, trend_names in ipairs(trends_table) do

    delete_from_table = true

    -- Loop through trendnames

    for _, trendname in ipairs(trendnames) do

      if trendname == trend_names.name then

            delete_from_table = false

      end

    end

    if delete_from_table == true then

      table.remove(trends_table, i)

      end

      i = i + 1

  end

end

-- Check if the is at least 1 trend to be exported

if #trends_table < 1 then

  log("No trends available, Could not export trends")

  return

end

-- csv buffer

buffer = {}

-- Add to buffer

table.insert(buffer, '"This file contains the export data of ' .. #trends_table .. ' trend(s) and is automaticly created on ' .. os.date("%A",os.time()) .. ' ' .. os.date("%d-%m-%y at %H:%M") .. '"')

-- Add empty line

table.insert(buffer, '""')

-- months

local months = { "Januari", "Februari", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }

-- Loop through trends_table

for _, trend_names in ipairs(trends_table) do

  -- Grab trend name from DB table

  trend_name = trend_names.name

 

  -- Add to buffer

  table.insert(buffer, '"##### START OF TREND ' .. _ .. ': ' .. trend_name .. ' #####"')

  -- Add empty line

  table.insert(buffer, '""')

  -- Get current timestamp

  timestamp = os.time()

  now = os.date('*t', timestamp)

 

  -- get data for the past year

    dates = {}

  dates['start'] = now

  if dates['start'].month == 1 then

      dates['start'].month = 12

    dates['start'].year = dates['start'].year - 1

  else

    dates['start'].month = dates['start'].month - 1

  end

  dates['end'] = os.date('*t')

 

  -- Set resolution to dayly data

  resolution = 86400

 

  -- Get last month for data by each days in this month

  trenddatamonth = trends.fetch(trend_name, dates, resolution)

 

  -- Get last month total avarage data

  trenddatamonthavg = trends.fetchone(trend_name, dates, resolution)

 

  -- Add to buffer

  table.insert(buffer, '"Export of the average usage of the month ' .. months[dates['start'].month] .. ' from trend ' .. trend_name .. '"')

  -- Add empty line

  table.insert(buffer, '""')

  -- Add header

  table.insert(buffer, '"Start date","End Date","Average month value"')

  -- Add to buffer

  table.insert(buffer, '"01-' .. string.format("%02d", dates['start'].month) .. "-" .. dates['start'].year .. '","' .. #trenddatamonth .. '-' .. string.format("%02d", dates['start'].month) .. "-" .. dates['start'].year .. '","' .. trenddatamonthavg .. '"')

  -- Add empty line

  table.insert(buffer, '""')

  -- Add to buffer

  table.insert(buffer, '"Detailed export of the daily usage of the month ' .. months[dates['start'].month] .. ' from trend ' .. trend_name .. '"')

  -- Add empty line

  table.insert(buffer, '""')

  -- Add header

  table.insert(buffer, '"Weekday","Date","Average day value"')

  for _, row in ipairs(trenddatamonth) do

    stamp = dates['start'].year .. '-' .. dates['start'].month .. '-' .. string.format("%02d", _)

        local y, m, d = stamp:match("(%d+)%-(%d+)%-(%d+)")

        local t = { year = y, month = m, day = d} 

    -- format csv row

    csv = string.format('%q,%q,%q', os.date("%A",os.time(t)), "" .. string.format("%02d", _) .. "-" .. string.format("%02d", dates['start'].month) .. "-" .. dates['start'].year, row)

    -- add to buffer

    table.insert(buffer, csv)

  end

  -- Add empty line

  table.insert(buffer, '""')

  -- Add header

  table.insert(buffer, '"##### END OF TREND ' .. _ .. ': ' .. trend_name .. ' #####"')

  -- Add empty line

  table.insert(buffer, '""')

end

--Create table to include mail settings

local settings = {

    from = from,

    rcpt = to,

    user = user,

    password = password,

    server = 'smtp.gmail.com',

    port = 465,

    secure = 'sslv23',

}

--Create attachment inside FTP server

src = 'Trend Export '.. os.date('%Y-%m-%d %H#%M#%S') .. '.csv'

dst = '/home/ftp/' .. src

io.writefile(dst, buffer)

--Create subject

subject = subjectpart1 .. ": " .. src .. " " .. subjectpart2

--Load required modules to send email with attachment

local smtp = require("socket.smtp")

local mime = require("mime")

local ltn12 = require("ltn12")

--Create e-mail header

settings.source = smtp.message{

headers = {

          from = '' .. alias_from .. ' ' .. from .. '',

          to = '' .. alias_to .. ' ' .. to .. '',

          subject = subject

},

--Load attachment inside body    

body = {

preamble = "",

[1] = { 

        headers = {

           ["content-type"] = 'text/plain',

           ["content-disposition"] = 'attachment; filename="'..src..'"',

           ["content-description"] = '.. src ..',

           ["content-transfer-encoding"] = "BASE64",

        },

        body = ltn12.source.chain(

          ltn12.source.file(io.open(dst, "rb")),

          ltn12.filter.chain(

          mime.encode("base64"),

          mime.wrap()

        )

      )

    },

      epilogue = epilogue

  }

}

--Send the email

r, e = smtp.send(settings)

--Create alert when sending gives an error with error message

if (e) then

  log (e)

  log (r)

  alert("Could not send email: ", e, "\n")

end

--Delete created backup file from ftp folder inside HL

os.remove(dst)

Kind regards
Thomas

Application Design Engineer
Reply
Thomas_Rohde
Sisko Thomas_Rohde Sisko
Sisko

Posted: ‎2016-10-25 10:49 PM

0 Likes
0
603
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2016-10-25 10:49 PM

Hi Pedro,

is this topic solved or do you need still support?

In case this topic is answered please mark it accordingly

so that we can get a better view on which kind of topics are really still open.

Thanks a lot for your understanding and support.

Kind regards

Thomas

Kind regards
Thomas

Application Design Engineer
Reply
Preview Exit Preview

never-displayed

You must be signed in to add attachments

never-displayed

 
To The Top!

Forums

  • APC UPS Data Center Backup Solutions
  • EcoStruxure IT
  • EcoStruxure Geo SCADA Expert
  • Metering & Power Quality
  • Schneider Electric Wiser

Knowledge Center

Events & webinars

Ideas

Blogs

Get Started

  • Ask the Community
  • Community Guidelines
  • Community User Guide
  • How-To & Best Practice
  • Experts Leaderboard
  • Contact Support
Brand-Logo
Subscribing is a smart move!
You can subscribe to this board after you log in or create your free account.
Forum-Icon

Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.

Register today for FREE

Register Now

Already have an account? Login

Terms & Conditions Privacy Notice Change your Cookie Settings © 2025 Schneider Electric

This is a heading

With achievable small steps, users progress and continually feel satisfaction in task accomplishment.

Usetiful Onboarding Checklist remembers the progress of every user, allowing them to take bite-sized journeys and continue where they left.

of