Calculate the sum of a weekly energy production for a solar panel

84 views
Skip to first unread message

Marco Biner

unread,
Mar 30, 2018, 1:45:34 PM3/30/18
to weewx-user
Hello
I need help to calculate in a weekly report the sum of energy production from a solar panel.
The collection of the data works fine with with a selfmade added second data source as given in the electricity.py exemple.
Now my issue is, that the the solar panels feeds:

the actual voltage: current.electric_psol in [V]
the actual power: current.electric_ed in [W¨]

the value week.electric_ed.sum summarizes all records during the period of a week, which is not the sum of the daily production i a week.
I need only the sum of the latest record of a day.
googling did give any serious hints to solve my wish.
Actually I a running weewx version 3.6.2

Thanks in advance for any help
Marco HB9UQC

http://hb9y.dyndns.org/weewx/

Thomas Keffer

unread,
Mar 30, 2018, 8:17:28 PM3/30/18
to weewx-user
If I understand your question correctly, you want the energy production for the week, summarized by day. Is that correct?

If so, you can do something like (NOT TESTED)

#for $day in $week.days
<p>The energy production for $day.dateTime is $day.electric_ed.sum</p>
#end for

See if that helps.

-tk

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marco Biner

unread,
Mar 31, 2018, 8:31:00 AM3/31/18
to weewx-user
Hi Tom
thank you for the fast reply.
I added your code to my report, but it summarisez all stored values from a day, not the last value.
I have to clarify that the logger of the solar panel gives everytime it is polled the sum of the daily solar production.
The modification of your code, like this:

#for $day in $week.days
<p>The energy production for $day.dateTime is $day.electric_ed.sum</p>
     <p>The energy production for $day.dateTime is $day.electric_ed.last</p>
#end for
gives the following output:

The energy production for 00:00 is 2777070.68 Wh

The energy production for 00:00 is 4105.47 Wh

The energy production for 00:00 is 1814408.75 Wh

The energy production for 00:00 is 2380.86 Wh

The energy production for 00:00 is 2188879.96 Wh

The energy production for 00:00 is 3105.47 Wh

The energy production for 00:00 is 2349953.71 Wh

The energy production for 00:00 is 3298.83 Wh

The energy production for 00:00 is 3153128.84 Wh

The energy production for 00:00 is 4515.62 Wh

The energy production for 00:00 is 112733.52 Wh

The energy production for 00:00 is 1305.66 Wh

The energy production for 00:00 is N/A

The energy production for 00:00 is N/A


there I have two issues:

1. for today I get N/A and all other results are one day shiftet, means the value of 1305.66 is actual production of today,  4515.62 is from yesterday

2. I need the sum for the last seven days, which is the sum of $day.electric_ed.last

3. Question by the way, why is $day.dateTime alway 00:00

Kind regards
Marco

Thomas Keffer

unread,
Mar 31, 2018, 11:13:48 AM3/31/18
to weewx-user
1. This may be resulting from confusion of what the timestamps represent. In weeWX, all data in a time period is timestamped by the end of that period. As an example, data for a 5 minute archive period with a timestamp 0950 Tuesday, is the data from (but not including) 0945 up to and including 0950. 

That's for a single archive record. Now think about aggregations over a day. Take a day like Tuesday. The tag $day.outTemp.avg is the average temperature for Tuesday, which is the average temperature for times greater than midnight Tuesday through times less than or equal to midnight Wednesday. So, $day.outTemp.last is the temperature for the very last record in that aggregation interval, which is going to be timestamped midnight Wednesday. That is, it represents the temperature from 2355 Tuesday to 0000 Wednesday. By contrast, $day.dateTime is the time of the beginning of that period, which is midnight Tuesday.

If $day.electric_ed.last is the data for the following day (Wednesday, in our example), then it is being timestamped wrong. 

2. There is no tag for something like that. You would have to keep your own running total, or write a search list extension.

3. Documented in the Customizing Guide. Timestamps use strftime formatting.

Putting it all together, and it should look something like (NOT TESTED):

#set $week_total=0
#for $day in $week.days
     <p>The energy production for $day.dateTime.format("%A") is $day.electric_ed.last</p>
#set $week_total += $day.electric_ed.last.raw
#end for
<p>Energy production for the week: $week_total</p>

Note that $week_total will be just a raw number. It would be up to you to provide any formatting.

-tk

--

Marco Biner

unread,
Apr 1, 2018, 7:18:43 AM4/1/18
to weewx-user
Hi Tom
my answers between your lines.


Am Samstag, 31. März 2018 17:13:48 UTC+2 schrieb Tom Keffer:
1. This may be resulting from confusion of what the timestamps represent. In weeWX, all data in a time period is timestamped by the end of that period. As an example, data for a 5 minute archive period with a timestamp 0950 Tuesday, is the data from (but not including) 0945 up to and including 0950. 

That's for a single archive record. Now think about aggregations over a day. Take a day like Tuesday. The tag $day.outTemp.avg is the average temperature for Tuesday, which is the average temperature for times greater than midnight Tuesday through times less than or equal to midnight Wednesday. So, $day.outTemp.last is the temperature for the very last record in that aggregation interval, which is going to be timestamped midnight Wednesday. That is, it represents the temperature from 2355 Tuesday to 0000 Wednesday. By contrast, $day.dateTime is the time of the beginning of that period, which is midnight Tuesday.

If $day.electric_ed.last is the data for the following day (Wednesday, in our example), then it is being timestamped wrong. 

I could revise the timestamping in the electricity script.
 

2. There is no tag for something like that. You would have to keep your own running total, or write a search list extension.

3. Documented in the Customizing Guide. Timestamps use strftime formatting.

Putting it all together, and it should look something like (NOT TESTED):

#set $week_total=0
#for $day in $week.days
     <p>The energy production for $day.dateTime.format("%A") is $day.electric_ed.last</p>
#set $week_total += $day.electric_ed.last.raw
#end for
<p>Energy production for the week: $week_total</p>

Note that $week_total will be just a raw number. It would be up to you to provide any formatting.

It works great, thanks for your help!
Next task will be upgrading to 3.8.0

Regards and congratulation for weeWX
Marco


-tk

To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.

Marco Biner

unread,
Apr 2, 2018, 7:13:37 AM4/2/18
to weewx-user
Hi Tom
I am again disturbing you.
As I said I managed it to summarize my energy production with your hint, but it is still not satisfiying my wish.
Here my code to summarize the production of a month:
#set $month_total=0
                        #for $day in $month.days
                            <tr><td>$day.dateTime.format("%A %d.%m.%y")</td><td>$day.electric_ed.last</td><td>
                            #if $day.electric_ed.last.raw is not None
                            #set $month_total  += $day.electric_ed.last.raw
                            #end if
                        #end for
                        #set $month_total = $month_total / 1000
                        #set $month_total = "%.2f" % $month_total
                        <tr><td>Total des Monats </td><td>$month_total KWh</td><td>

starting the sum with:
#for $day in $month.days
starts the first day of a month, what I need is to set the starting time one month back from today.
I tried to set the starting day with $month($months_ago=1)
 #for $day in $month($months_ago=1).days
gives an error:
TypeError: month() got an unexpected keyword argument 'months_ago'

As the graphic shows the values of the last week, rsp. the last month I would like to present in the table also the values of the last week, resp. the last month, not the values starting from monday or the the 1. of a month. So how do I set the correct start day for the summarisation?

Regards
Marco

Thomas Keffer

unread,
Apr 2, 2018, 11:45:39 AM4/2/18
to weewx-user
The "months_ago" feature was not introduced until V3.7. You are using V3.6.2. 

Upgrade!

-tk


--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages