This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Daily logging of produced energy from solar inverter
#1
Hi,

I'd like to log the daily energy production (kWh) of my solar inverter.
I created a scheduled script running once a day. This script reads the energy production of the previous day from the inverter.

Is it possible to save daily data consisting of a timestamp and a value?

I tried to save it with the following script, but obviously the value of 'pv' gets overriden every time.


Code:
save = {
  ["Pac"] = PV_Pac,  -- PV_Pac is set to the energy value coming from the inverter
  ["timestamp"] = os.date('%Y-%m-%d', os.time()-24*60*60)  -- yesterday's timestamp
}
result = storage.set('pv', save)

Can data be appended with the storage object? Or how could this be accomplished?

The goal of this logging is to produce bar charts later on.

thanks!
Valentin
Reply
#2
Maybe better create table in storage:
Code:
pvLogs = storage.get('pvLogs')

toAdd = {
timestamp = os.time(),
Pac = PV_Pac
}

table.insert(pvLogs, toAdd)
storage.set('pvLogs', pvLogs)

In such logs it is enough to use only os.time() and only when show you can then convert it to readable format.
Done is better than perfect
Reply
#3
Why not use trend logs?
Reply
#4
All in all, the admin has rightWink
Done is better than perfect
Reply
#5
Hi,
thanks buuuudzik for the hint how to append values to a table. I tested it and it works as expected.

admin: I tried to achieve this by using trends and ran into the following limitations:
- Trend resolution is too small, I need to log one value once a day.
- I'm logging the total amount of kWh produced on every day. This value increases throughout the current day until it reaches a maximum value (when the inverter deactivates itself). So 
when I create a trend of the produced kWh's there's too much information in it. As far as I read here in the forum, an averaging is performed on the trend data when it dates back more than 30 days (or whatever value was chosen when creating the trend). This averaging is not apropriate in this case, as the maximum value is wanted.
- Finally it's going to be displayed as a bar chart, with daily/monthly/yearly values.

thanks again. Here's the script and the view of the storage attached as png. 

Code:
-- Log PV-Production
-- get value of object named 'PV Yesterday kWh'
-- Config:
logVariable = '_PV_Energy_daily'  -- custom value so it shows on top of the Storage Viewer App

-- Script start:
value = grp.getvalue('PV Yesterday kWh')
pvLogs = storage.get(logVariable)

toAdd = {
 timestamp = os.time(),
 Energy = value
}

if (pvLogs == nil) then
 -- create table first
 saveTable = {}
 table.insert(saveTable, toAdd)
 storage.set(logVariable, saveTable)
else
 table.insert(pvLogs, toAdd)
 storage.set(logVariable, pvLogs)
end

Attached Files Thumbnail(s)
   
Reply
#6
I like in LM controller that it is amazingly elastic and with some knowledge you can do nearly everything in not only one wayWink And when you add to this unlimited power on the client you can do much moreWink
Done is better than perfect
Reply


Forum Jump: