Sunshine Time

714 views
Skip to first unread message

Stefan Schnidrig

unread,
Jul 22, 2019, 5:50:28 AM7/22/19
to weewx-user
Hello everybody.

I have found this link (https://github.com/brewster76/util-archer/blob/master/user/radiationhours.py) where is described how to display the sunshine time. Now I would like to show this value in numbers (eg 4:15 h). Is that possible?

Thank you


Thomas Keffer

unread,
Jul 22, 2019, 7:47:39 AM7/22/19
to weewx-user
I'm not sure what you mean by "show this value in numbers." Do you mean formatting the value as "4:15 h", versus "4.25"?

-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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/e4b49519-f227-4cfa-9151-7a3aafccc813%40googlegroups.com.

Stefan Schnidrig

unread,
Jul 22, 2019, 8:48:02 AM7/22/19
to weewx-user
Hello Thomas.
Thanks for your message. No. I would like to use the solar sensor to display the sunshine time. But I want that in numbers, so I can put it in my xml.

Thank you


Am Montag, 22. Juli 2019 13:47:39 UTC+2 schrieb Thomas Keffer:
I'm not sure what you mean by "show this value in numbers." Do you mean formatting the value as "4:15 h", versus "4.25"?

-tk

On Mon, Jul 22, 2019 at 2:50 AM Stefan Schnidrig <sschn...@bluewin.ch> wrote:
Hello everybody.

I have found this link (https://github.com/brewster76/util-archer/blob/master/user/radiationhours.py) where is described how to display the sunshine time. Now I would like to show this value in numbers (eg 4:15 h). Is that possible?

Thank you


--
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...@googlegroups.com.

Thomas Keffer

unread,
Jul 22, 2019, 8:56:03 AM7/22/19
to weewx-user
If you just want the raw number, use the "raw" suffix:

$current.sunshine_hours.raw

-tk

To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/5dfbcab1-9b7a-4b0c-9048-8a9add486ce9%40googlegroups.com.

Stefan Schnidrig

unread,
Jul 22, 2019, 9:03:35 AM7/22/19
to weewx-user
So about?
Unbenannt.JPG

Thanks



Am Montag, 22. Juli 2019 14:56:03 UTC+2 schrieb Thomas Keffer:
If you just want the raw number, use the "raw" suffix:

$current.sunshine_hours.raw

-tk

On Mon, Jul 22, 2019 at 5:48 AM Stefan Schnidrig <sschn...@bluewin.ch> wrote:
Hello Thomas.
Thanks for your message. No. I would like to use the solar sensor to display the sunshine time. But I want that in numbers, so I can put it in my xml.

Thank you


Am Montag, 22. Juli 2019 13:47:39 UTC+2 schrieb Thomas Keffer:
I'm not sure what you mean by "show this value in numbers." Do you mean formatting the value as "4:15 h", versus "4.25"?

-tk

On Mon, Jul 22, 2019 at 2:50 AM Stefan Schnidrig <sschn...@bluewin.ch> wrote:
Hello everybody.

I have found this link (https://github.com/brewster76/util-archer/blob/master/user/radiationhours.py) where is described how to display the sunshine time. Now I would like to show this value in numbers (eg 4:15 h). Is that possible?

Thank you


--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/e4b49519-f227-4cfa-9151-7a3aafccc813%40googlegroups.com.

--
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...@googlegroups.com.

Stefan Schnidrig

unread,
Jul 22, 2019, 9:13:55 AM7/22/19
to weewx-user
Now it looks like this. I think that's not true yet?
Unbenannt.JPG

Thanks for watching

Am Montag, 22. Juli 2019 14:56:03 UTC+2 schrieb Thomas Keffer:
If you just want the raw number, use the "raw" suffix:

$current.sunshine_hours.raw

-tk

On Mon, Jul 22, 2019 at 5:48 AM Stefan Schnidrig <sschn...@bluewin.ch> wrote:
Hello Thomas.
Thanks for your message. No. I would like to use the solar sensor to display the sunshine time. But I want that in numbers, so I can put it in my xml.

Thank you


Am Montag, 22. Juli 2019 13:47:39 UTC+2 schrieb Thomas Keffer:
I'm not sure what you mean by "show this value in numbers." Do you mean formatting the value as "4:15 h", versus "4.25"?

-tk

On Mon, Jul 22, 2019 at 2:50 AM Stefan Schnidrig <sschn...@bluewin.ch> wrote:
Hello everybody.

I have found this link (https://github.com/brewster76/util-archer/blob/master/user/radiationhours.py) where is described how to display the sunshine time. Now I would like to show this value in numbers (eg 4:15 h). Is that possible?

Thank you


--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/e4b49519-f227-4cfa-9151-7a3aafccc813%40googlegroups.com.

--
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...@googlegroups.com.

Andrew Milner

unread,
Jul 22, 2019, 9:46:42 AM7/22/19
to weewx-user
From the output you provided I read that as saying .08 hours of sunshine today - does that correspond with reality??

What output are you wanting??  I read the extension install instructions and what you have posted seems to correspond with what I would expect.  What exactly are you wanting??  Perhaps you should contact the creator of the extension!!

Stefan Schnidrig

unread,
Jul 22, 2019, 9:54:54 AM7/22/19
to weewx-user
Hello.

I would like to have the sunshine hours for the current day. Format in hours and minutes.

Thanks

Andrew Milner

unread,
Jul 22, 2019, 11:28:13 AM7/22/19
to weewx-user
what does day.sunshine_hours.raw give you instead of current.sunshine_hours.raw ???

Thomas Keffer

unread,
Jul 22, 2019, 11:39:08 AM7/22/19
to weewx-user
You could do something like this (NOT TESTED):

#set hours = int($current.sunshine_hours.raw)
#set minutes = int(($current.sunshine_hours.raw - $hours)*60 + 0.5)
<sun value="$hours h $minutes m"/>

-tk

To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/06eb2e2b-bc53-4bc1-8e67-515a2094cdf6%40googlegroups.com.

Andrew Milner

unread,
Jul 22, 2019, 12:43:59 PM7/22/19
to weewx-user
Tom - I think sunshine_hours is a schema extension which is set to archive interval if the interval radiation in the interval exceeds a configurable threshold and so is regarded as being sunny, so I think one would need to do a sum to get the day's total before doing your formatting calculation into hrs and minutes.

Stefan Schnidrig

unread,
Jul 22, 2019, 12:47:57 PM7/22/19
to weewx-user
Hello

@Andrew

If I enter day.sunshine_hours.raw, then I get an error message.

@Thomas
Excuse the stupid question, but where should I paste? In my xml that will not work?

Thanks for your inputs

Stefan Schnidrig

unread,
Jul 22, 2019, 1:07:46 PM7/22/19
to weewx-user
@Thomas

It works

<solar>
<solar value="196"/>
<solar_max value="916"/>
<solar_max_time value="13:39"/>
<sun value="0 h 5 m"/>
</solar>


Now it would be great if you had the day, not 24 hours. Then you would always have the daily value.

Thanks!

Am Montag, 22. Juli 2019 17:39:08 UTC+2 schrieb Thomas Keffer:

Andrew Milner

unread,
Jul 22, 2019, 1:43:27 PM7/22/19
to weewx-user
sorry - it should have been day.sunshine_hours.sum I think

Stefan Schnidrig

unread,
Jul 22, 2019, 1:55:45 PM7/22/19
to weewx-user
"day.sunshine_hours.sum" does not work. An error message appears that the day does not exist

gjr80

unread,
Jul 22, 2019, 4:51:21 PM7/22/19
to weewx-user
Just to get the obvious question out of the way first; you did use $day.sunshine_hours.sum didn’t you (as opposed to day.sunshine_hours.sum), the ‘$’ matters? Might help to post a copy of the actual template code used, you would be surprised how often transcription or spelling errors are made and not noticed.

If you did use the ‘$’, did you follow the instructions you linked earlier in their entirety; in particular steps 3 and 4 to add sunshine_hours to your database schema?

Gary



current will give you the amount of sunshine hours in the last archive period. Based on the code linked it will be either the archive period or zero, depending on whether the threshold was reached. That’s a bit like $current.rain, the rainfall in the last archive period, not really what most folks want. I suspect you really want to use an aggregate in there, if you have followed the linked instructions then something like $day.sunshine_hours.sum will give you today’s total sunshine hours.

If you use $day.sunshine_hours.sum.raw you will get the number of seconds, eg 5 hours would show 18000. Have a read of the Customization Guide (http://weewx.com/docs/customizing.htm#Tags) and learn about tags, their formatting and unit conversion and you should be able to do most of what you want.

Gary

Stefan Schnidrig

unread,
Jul 23, 2019, 1:14:19 AM7/23/19
to weewx-user
Good morning Gary.
Thank you for your help. Here is the code:
<solar>
#set hours = int($current.sunshine_hours.raw)
#set minutes = int(($current.sunshine_hours.raw - $hours)*60 + 0.5)
<sun value="$hours h $minutes m"/>
</solar>

That works with the current. But now I need the daylight sunshine.
If I take day, then I get an error message when processing.

Stefan

unread,
Jul 23, 2019, 1:17:24 AM7/23/19
to weewx-user
Here the error message

Unbenannt.JPG



Am Montag, 22. Juli 2019 22:51:21 UTC+2 schrieb gjr80:

Andrew Milner

unread,
Jul 23, 2019, 1:44:12 AM7/23/19
to weewx-user
what does $day.sunshine_hours.sum give you (without raw, and without trying to convert to hours and minutes - if an error then what error??  Is the value the approximate minutes of sunlight you would expect for the day??

can you post the template that you are using please.

gjr80

unread,
Jul 23, 2019, 2:35:37 AM7/23/19
to weewx-user
The answer is in the error message. You are using $day.sunshine_hours.raw, you should be using $day.sunshine_hours.sum or perhaps $day.sunshine_hours.sum.raw

Gary

Stefan

unread,
Jul 23, 2019, 6:32:44 AM7/23/19
to weewx-user
Hello.

Here is the Code:

<solar>
        <solar value="$current.radiation.formatted"/>
        <solar_max value="$day.radiation.max.formatted"/>
        <solar_max_time value="$day.radiation.maxtime.format("%H:%M")"/>
        #set hours = int($day.sunshine_hours.sum.raw)
        #set minutes = int(($day.sunshine_hours.sum.raw - $hours)*60 + 0.5)
        <sun value="$hours h $minutes m"/>
</solar>

With $current.sunshine_hours.raw it works! With $day.sunshine_hours.sum.raw nothing.

The failure Code:

Jul 23 12:30:23 raspberrypi weewx[31508]: cheetahgenerator: **** Ignoring template /etc/weewx/skins/Seasons/XML/daten.xml.tmpl
Jul 23 12:30:23 raspberrypi weewx[31508]: cheetahgenerator: **** Reason: cannot find 'sum' while searching for 'day.sunshine_hours.sum'
Jul 23 12:30:23 raspberrypi weewx[31508]: ****  Traceback (most recent call last):
Jul 23 12:30:23 raspberrypi weewx[31508]: ****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 332, in generate
Jul 23 12:30:23 raspberrypi weewx[31508]: ****      fd.write(str(compiled_template))
Jul 23 12:30:23 raspberrypi weewx[31508]: ****    File "/usr/lib/python2.7/dist-packages/Cheetah/Template.py", line 1005, in __str__
Jul 23 12:30:23 raspberrypi weewx[31508]: ****      rc = getattr(self, mainMethName)()
Jul 23 12:30:23 raspberrypi weewx[31508]: ****    File "_etc_weewx_skins_Seasons_XML_daten_xml_tmpl.py", line 309, in respond
Jul 23 12:30:23 raspberrypi weewx[31508]: ****  NotFound: cannot find 'sum' while searching for 'day.sunshine_hours.sum'

Stefan

unread,
Jul 23, 2019, 7:00:35 AM7/23/19
to weewx-user
This is with $current.sunshine_hours.raw. It works!

<solar>
<solar value="861"/>
<solar_max value="861"/>
<solar_max_time value="12:51"/>
<sun value="0.0833333333333"/>
</solar>

But with $day.sunshine_hours.raw or $day.sunshine_hours.sum.raw or $day.sunshine_hours.raw.sum
The Problem always turns up when replacing $current by $day.



Am Dienstag, 23. Juli 2019 08:35:37 UTC+2 schrieb gjr80:

Thomas Keffer

unread,
Jul 23, 2019, 7:09:25 AM7/23/19
to weewx-user
The type "sunshine_hours" is not in your database. It will work with "$current" because you have a current record, so weewx is using that. But, because it is not in your database, weewx cannot sum over the day.

See the section Adding a new type to the database in the Customizing Guide for how to do this.

-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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/5ddf5a22-a565-4e12-9093-5c69d187e420%40googlegroups.com.

gjr80

unread,
Jul 23, 2019, 7:11:07 AM7/23/19
to weewx-user
So, back to my earlier question. Did you follow the instructions you linked earlier in their entirety; in particular steps 3 and 4 to add sunshine_hours to your database schema?

On looking at those instructions again there is no mention of rebuilding the daily summaries after changing the schema. You might want to try stopping WeeWX then using wee_database with the --rebuild_daily action (http://weewx.com/docs/utilities.htm#wee_database utility)

Gary

Stefan

unread,
Jul 23, 2019, 8:09:06 AM7/23/19
to weewx-user
Hello Thomas.

I found the mistake. When we create the new table, we use the name weewx.sdb_new instead of the weewx.sdb. Have this now adjusted in the weewx.conf and lo and behold, num works it. The rest I had done, but unfortunately not this detail. Many thanks to all helpers. Class like that works.

Your code also works great:
     #set hours = int ($ current.sunshine_hours.raw)
     #set minutes = int (($ current.sunshine_hours.raw - $ hours) * 60 + 0.5)
     <sun value = "$ hours h $ minutes m" />

Many Thanks


Am Dienstag, 23. Juli 2019 13:09:25 UTC+2 schrieb Thomas Keffer:
The type "sunshine_hours" is not in your database. It will work with "$current" because you have a current record, so weewx is using that. But, because it is not in your database, weewx cannot sum over the day.

See the section Adding a new type to the database in the Customizing Guide for how to do this.

-tk


On Tue, Jul 23, 2019 at 4:00 AM Stefan <sschn...@bluewin.ch> wrote:
This is with $current.sunshine_hours.raw. It works!

<solar>
<solar value="861"/>
<solar_max value="861"/>
<solar_max_time value="12:51"/>
<sun value="0.0833333333333"/>
</solar>

But with $day.sunshine_hours.raw or $day.sunshine_hours.sum.raw or $day.sunshine_hours.raw.sum
The Problem always turns up when replacing $current by $day.



Am Dienstag, 23. Juli 2019 08:35:37 UTC+2 schrieb gjr80:
The answer is in the error message. You are using $day.sunshine_hours.raw, you should be using $day.sunshine_hours.sum or perhaps $day.sunshine_hours.sum.raw

Gary

--
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...@googlegroups.com.

Andrew Milner

unread,
Jul 23, 2019, 8:18:15 AM7/23/19
to weewx-user
Stefan
You need to forget $current.sunshine_hours.raw as that will only give you the sunshine in the interval which will always be either 0 or 5 in your case.

For the daily total you need to use $day.sunshine_hours.sum in order to get the total sunshine hours for the day from midnight up to the current time.

Stefan

unread,
Jul 23, 2019, 3:05:35 PM7/23/19
to weewx-user
Hello Andrew.

Yes you are right. Of course it is true:

#set hours = int ($ day.sunshine_hours.sum.raw)
#set minutes = int (($ day.sunshine_hours.sum.raw - $ hours) * 60 + 0.5)

<sun value = "$ hours h $ minutes m" />

That's how it works perfectly. Now I will try to show it as a graphic.

Thank you diligent helpers

Stefan

unread,
Jul 25, 2019, 5:28:15 AM7/25/19
to weewx-user
Good Morning.

The hours of sunshine work well. Now I wanted to ask if I can change the width of the bars? Every attempt so far failed.

daysun.png


Likewise, the link above is now the name of the Wm / 2. Is it possible to change or suppress this? Here is my code:

[[[daysun]]]
            # Make sure the y-axis increment is at least 0.02 for the sun plot
            yscale = 0.0, 1.0, 0.1
            plot_type = bar
            [[[[sunshine_hours]]]]
                aggregate_type = sum
                aggregate_interval = 3600
                label = Sonnenschein in Stunden (Stundentotal)

Thanks for Help

gjr80

unread,
Jul 25, 2019, 2:02:39 PM7/25/19
to weewx-user
Unfortunately you cannot explicitly set the width of the bars plotted by the imagegenerator, the width is set automatically based on the aggregate interval being used in the plot

Gary

Stefan

unread,
Jul 26, 2019, 2:10:38 AM7/26/19
to weewx-user
Hello Gary.
Yes I know that. That does not bother me either. I want to change the color of the bars. Can I do that somehow? These should appear in yellow. Thanks

gjr80

unread,
Jul 26, 2019, 3:54:44 PM7/26/19
to weewx-user
To change the bar colour try using the config option ‘fill_color’. The config option ‘color’ will set the outline colour of the bar.

Gary

gjr80

unread,
Jul 26, 2019, 4:01:16 PM7/26/19
to weewx-user
As for changing the W/m2 try setting the config option ‘y_label’ to an empty string, something like (untested):

y_label = “”

Gary

Stefan

unread,
Oct 12, 2019, 4:19:35 AM10/12/19
to weewx-user
Hello

I have a question. The documentation says, you can change the threshold of 120 in the weewx.conf. However, I do not find the weewx.conf this described point. 120 are too few. I want to set the value to 200. If I change this in the radiationshours.py, then I get, as soon as the solar value 0 W / m2 is an error message and weewx stops.

Here's the place:
When [sunshine_hours] is summed over a day, the result is the number of hours during the day when radiation
exceeded 120 W / m2, or 'hours of sunshine'.
The threshold of 120 W / m2 can be overwritten in weewx.conf:
     [Radiation Days]
         min_sunshine = 120


Thanks for Help

gjr80

unread,
Oct 12, 2019, 4:54:08 AM10/12/19
to weewx-user
So did you put the following in weewx.conf:

[Radiation Days]
min_sunshine = 200

then save weewx.conf and restart WeeWX? Why do you think it is not working? The author gives you a means to set the threshold value in weewx.conf rather than modifying code. Try setting debug = 1 and see what appears in the log, it should show you the radiation value seems and the threshold used.

If you can’t work out what is wrong post a log extract with debug = 1 as well as a sanitised copy of weewx.conf.

Gary

PS. Make sure you put the code back how it was.

Stefan

unread,
Oct 12, 2019, 5:10:59 AM10/12/19
to weewx-user
Hello Gary.

No I did not write anything to the weewx.conf. Where should I insert this? So under what class?

gjr80

unread,
Oct 12, 2019, 5:24:03 AM10/12/19
to weewx-user
The single [ ] tell you it needs to be its own top level stanza. Easiest thing is to put it at the end of the file.

Gary

Stefan

unread,
Oct 12, 2019, 5:39:02 AM10/12/19
to weewx-user
OK thanks. But if I change the value in radiationshours.py, would that work out well? Replace the yellow marked value with 200?

import weewx
from weewx.wxengine import StdService

class RadiationHours(StdService):
def __init__(self, engine, config_dict):
# Pass the initialization information on to my superclass:
super(RadiationHours, self).__init__(engine, config_dict)

# Default threshold value is 120 W/m2
self.min_sunshine = 120.0
import syslog

gjr80

unread,
Oct 12, 2019, 5:46:57 AM10/12/19
to weewx-user
If you must modify the code then yes that will do what you want provided there is no min_sunshine setting in weewx.conf.

Gary

Stefan

unread,
Oct 16, 2019, 1:26:42 AM10/16/19
to weewx-user
Hello.

The problem has reappeared today. Weewx stops the work. I have not changed the script, not adjusted to the threshold. This is still on 120W min. It ran until this morning without problems. But again this error message.

Oct 16 07:22:48 raspberrypi weewx[14709]: engine: Caught unrecoverable exception in engine:
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****  float argument required, not NoneType
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****  Traceback (most recent call last):
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****    File "/usr/share/weewx/weewx/engine.py", line 890, in main
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****      engine.run()
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****    File "/usr/share/weewx/weewx/engine.py", line 160, in run
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****      self.dispatchEvent(weewx.Event(weewx.STARTUP))
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****    File "/usr/share/weewx/weewx/engine.py", line 224, in dispatchEvent
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****      callback(event)
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****    File "/usr/share/weewx/weewx/engine.py", line 520, in startup
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****      self._catchup(self.engine.console.genStartupRecords)
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****    File "/usr/share/weewx/weewx/engine.py", line 635, in _catchup
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****      origin='hardware'))
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****    File "/usr/share/weewx/weewx/engine.py", line 224, in dispatchEvent
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****      callback(event)
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****    File "/usr/share/weewx/user/radiationhours.py", line 203, in newArchiveRecord
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****      (event.record['sunshine_hours'], radiation, self.min_sunshine))
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****  TypeError: float argument required, not NoneType
Oct 16 07:22:48 raspberrypi weewx[14709]:     ****  Exiting.

gjr80

unread,
Oct 16, 2019, 1:47:43 AM10/16/19
to weewx-user
Chances are field radiation does not exist in an archive record or it is set to None. I am afraid if you want any further help you are going to have to post the copy of radiationhours.py that you are using; the version in the repo you linked only has 106 lines of code and the error trace you posted indicates the error is at line 203.

Gary

Stefan

unread,
Oct 16, 2019, 2:50:00 AM10/16/19
to weewx-user
Hello Gray.

Here is the Script. Thx for Help.
radiationhours.py

gjr80

unread,
Oct 16, 2019, 3:27:48 AM10/16/19
to weewx-user
OK, essentially the same file but double spaced. The problem looks like it is due to field radiation being either missing or None. Try changing the following line:

syslog.syslog(syslog.LOG_DEBUG, "Calculated sunshine_hours = %f, based on radiation = %f, and min_sunshine = %f" %

to

syslog.syslog(syslog.LOG_DEBUG, "Calculated sunshine_hours = %f, based on radiation = %s, and min_sunshine = %f" %

You will need to restart WeeWX for the change to take effect.

Gary

Stefan

unread,
Oct 16, 2019, 7:57:33 AM10/16/19
to weewx-user
Thx Gary.
I made the change. However, it does not work either. There is still the error message:

Oct 16 13:54:28 raspberrypi weewx[12153]: engine: Caught unrecoverable exception in engine:
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****  name 'v' is not defined
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****  Traceback (most recent call last):
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****    File "/usr/share/weewx/weewx/engine.py", line 884, in main
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****      engine = engine_class(config_dict)
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****    File "/usr/share/weewx/weewx/engine.py", line 78, in __init__
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****      self.loadServices(config_dict)
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****    File "/usr/share/weewx/weewx/engine.py", line 142, in loadServices
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****      self.service_obj.append(weeutil.weeutil._get_object(svc)(self, config_dict))
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****    File "/usr/share/weewx/weeutil/weeutil.py", line 1130, in _get_object
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****      mod = __import__(module)
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****    File "/usr/share/weewx/user/radiationhours.py", line 174, in <module>
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****      v
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****  NameError: name 'v' is not defined
Oct 16 13:54:28 raspberrypi weewx[12153]:     ****  Exiting.

Andrew Milner

unread,
Oct 16, 2019, 9:08:35 AM10/16/19
to weewx-user
check your file - it looks as though there is now a 'stray' letter v in the file as a result of your editing!!  A typo of somekind clearly!!

Stefan

unread,
Nov 1, 2019, 6:59:54 AM11/1/19
to weewx-user
Hello Andrew.

Yes.Thats it. Thank you very Much. It works!

Thanks
Stefan

peter

unread,
Nov 14, 2019, 5:58:22 AM11/14/19
to weewx-user
I admit I don't follow the discussion frequently. I was thinking about the sunshine hours log - from the posts I understand the interval is considered "sunny" if the solar radiation is above a fixed threshold (e.g. 120 W/m2). I have second thoughts. For one of my stations I use Weather Display and there the logic is different. An interval is sunny if the solar radiation is 75% or above expected maximum solar radiation for the given latitude/longitude and time of day & year.
I haven't done this to other stations where I use weewx yet but I plan to write a simple (bash) script that would compare the current/max solar radiation every minute and log 0 or 1 to the database. I can then simply make a sum and get sunshine minutes per day. Does this make any sense?
I have a script that does a similar calculation already but has more threshold values (in %) that tell me sky conditions. And it works very well. I guess I could write a python script and integrate it with weewx but don't have enough knowledge.
Cheers.

Dne petek, 01. november 2019 11.59.54 UTC+1 je oseba Stefan napisala:

Jacques Terrettaz

unread,
Nov 14, 2019, 7:34:16 AM11/14/19
to weewx-user
I agree with peter's comment.
The Davis solar radiation sensor, or any comparable sensor, is measuring a global radiation ( direct + diffuse) and the surface of the sensor is parallel to the ground.  A fixed threshold, such as 120 W/m2, can be used only with sensors measuring direct radiation and that have their surface always pointing to the sun (i.e surface of sensor is always perpendicular to the axis sun-sensor).
With a Davis solar sensor, applying a fixed threshold to estimate sunshine duration give innacurate values. Why?  A simple example, taken from the measurements of my Davis solar sensor, will make you understand:
- On December 20, at 9:30, the sun was shining, and my solar sensor, in full sun, measured 105 W / m2.
- On June 11, at 10 am, the sky was cloudy, and my solar probe measured 301 W / m2.
How to choose a fixed threshold so that the sun of December with 105 W / m2 is considered as sunny and that a radiation of 301W / m2 under a cloudy sky of end of June is not considered as sunny?
A measurement of the global solar radiation on a plane parallel to the ground is very dependent on the elevation of the sun. This elevation changes according to the time of day and according to the seasons.
So with this type of solar sensors, a valid calculation of the sunshine duration  can only be done with methods taking into account the elevation of the sun at the time of the measurement, calculated according to the latitude, longitude, date and the time of observation.

Here is the weewx extension I am using, that I  modified from https://github.com/brewster76/util-archer/blob/master/user/radiationhours.py  by applying a formula developed by MeteoFrance to estimate sunshine duration from Davis sensors. (https://forums.infoclimat.fr/f/topic/17151-calcul-duree-ensoleillement/?do=findComment&comment=1216053).  The idea is to determine at each measurements a  threshold value that is calculated depending on the date, time and geographic location (latitude and longitude) of the sensor. If the measured solar radiation is higher than the calculated threshold, the sunshine duration for this measurement will be equal to the archive interval, otherwise it will be 0.
"""
Adds a new observation field to weewx: [sunshine_time]
Installation:
    1. Save this file to your user customisations directory (which is often /usr/share/weewx/user)
    2. Enable this service in weewx.conf by adding user.sunduration.SunshineDuration to the process_services list.
        [Engine]
            [[Services]]
                # This section specifies the services that should be run. They are
                # grouped by type, and the order of services within each group
                # determines the order in which the services will be run.
                prep_services = weewx.engine.StdTimeSynch
                process_services = user.sunduration.SunshineDuration, weewx.engine.StdConvert, weewx.engine.StdCalibrate, weewx.engine.StdQC, weewx.wxservices.StdWXCalculate
    3. Add [sunshine_time] to the database schema so tables include this new observation field.
       In weewx.conf, change the wx_binding schema from schemas.wview.schema to user.sunduration.schema_with_sunshine_time
        [DataBindings]
            [[wx_binding]]
                # The database must match one of the sections in [Databases].
                # This is likely to be the only option you would want to change.
                database = archive_sqlite
                # The name of the table within the database
                table_name = archive
                # The manager handles aggregation of data for historical summaries
                manager = weewx.wxmanager.WXDaySummaryManager
                # The schema defines the structure of the database.
                # It is *only* used when the database is created.
                #schema = schemas.wview.schema
                schema = user.sunduration.schema_with_sunshine_time
    4. Shutdown Weewx and update your database to bring in the new field.
       wee_database weewx.conf --reconfigure
       Make sure you know what you're doing at this point, you can potentially corrupt/lose your archive data.
       The weewx customization guide covers this in a lot more detail.
    5. Tell Weewx about the units for this new type
        Add this to user/extensions.py:
        #
        # Units for sunshine_days calculated field
        #
        import weewx.units
        weewx.units.obs_group_dict['sunshine_time'] = 'group_interval'

    6. Use [sunshine_time] in your graphs and html template tags.
    Lots more detail on this process can be found here:
        http://www.weewx.com/docs/customizing.htm#Adding_a_new_observation_type
"""

import syslog
from math import sin,cos,pi,asin
from datetime import datetime
import time

import weewx
from weewx.wxengine import StdService
import schemas.wview

class SunshineDuration(StdService):

    def __init__(self, engine, config_dict):
        # Pass the initialization information on to my superclass:
        super(SunshineDuration, self).__init__(engine, config_dict)

        # Start intercepting events:
        self.bind(weewx.NEW_ARCHIVE_RECORD, self.newArchiveRecord)

    def newArchiveRecord(self, event):
        """Gets called on a new archive record event."""
        seuil = 0
        tempe = float(event.record.get('outTemp'))
        radiation = event.record.get('radiation')
        event.record['sunshine_time'] = 0.0
        if radiation is not None:
            utcdate = datetime.utcfromtimestamp(event.record.get('dateTime'))
            dayofyear = int(time.strftime("%j",time.gmtime(event.record.get('dateTime'))))
            theta = 360 * dayofyear / 365
            equatemps = 0.0172 + 0.4281 * cos((pi / 180) * theta) - 7.3515 * sin(
                (pi / 180) * theta) - 3.3495 * cos(2 * (pi / 180) * theta) - 9.3619 * sin(
                2 * (pi / 180) * theta)

            latitude= float(self.config_dict["Station"]["latitude"])
            longitude = float(self.config_dict["Station"]["longitude"])
            corrtemps = longitude * 4
            declinaison = asin(0.006918 - 0.399912 * cos((pi / 180) * theta) + 0.070257 * sin(
                (pi / 180) * theta) - 0.006758 * cos(2 * (pi / 180) * theta) + 0.000908 * sin(
                2 * (pi / 180) * theta)) * (180 / pi)

            minutesjour = utcdate.hour*60 + utcdate.minute
            tempsolaire = (minutesjour + corrtemps + equatemps) / 60
            angle_horaire = (tempsolaire - 12) * 15
            hauteur_soleil = asin(sin((pi / 180) * latitude) * sin((pi / 180) * declinaison) + cos(
                (pi / 180) * latitude) * cos((pi / 180) * declinaison) * cos((pi / 180) * angle_horaire)) * (180 / pi)
            if hauteur_soleil > 3:
                seuil = (0.73 + 0.06 * cos((pi / 180) * 360 * dayofyear / 365)) *1080 * pow((sin(pi / 180) * hauteur_soleil), 1.25) * 0.90
                mesure = (((tempe * 1 - 25) * (-0.0012) * radiation) + radiation)
                if mesure > seuil:
                    event.record['sunshine_time'] = event.record['interval']

        syslog.syslog(syslog.LOG_DEBUG, "Calculated sunshine_time = %f, based on radiation = %f, and threshold = %f" %
                      (event.record['sunshine_time'], radiation, seuil))


schema_with_sunshine_time = schemas.wview.schema + [('sunshine_time', 'REAL')]




Stefan

unread,
Jan 1, 2020, 7:22:36 AM1/1/20
to weewx-user


Hello everybody
I have a question about graphic design. I would like to include the sunshine time in the graphics. Currently the value of 0.08 in sunshine always appears there. This is my current code in use.
[[chart6]]
title = Sonnenschein

# Make sure the y-axis increment is at least 0.02 for the sun plot
yscale = 0.0, 1.0, 0.1
        type = column
[[[sunshine_hours]]]
aggregate_type = sum
aggregate_interval = 300
color = "#e4d354"
name = Sonnenschein in Minuten

Unbenannt.PNG



I would like to do this now, because the interval 300s is 5min as sunshine. Can one make it like this?

Many thanks for your help

peter

unread,
Mar 11, 2020, 5:37:10 AM3/11/20
to weewx-user
I have a question about how to log the sunshine hours.
I thought to log "1" for every minute the radiation is above 75% expected maximum radiation and 0 when it is below. When I do a daily sum of this parameter, I'd get a number of sunshine minutes for a day.

I chose to log these "sunny minutes" in the "hailRate" parameter. In the database, it is logged OK (1 or 0). However, when I display the value in the html, it gives completely different value. I suspect it does some internal pre-calculation.
This is how I want to show the daily sunshine minutes: $day.hailRate.sum.raw

How to get a real sum (not recalculated) from the hailRate?
Shall I use another non-used parameter in the default weewx.sdb for this? I'd like to avoid adding a new custom field and database recompilation.

Thank you!

Meteo Oberwallis

unread,
Mar 26, 2020, 8:32:06 AM3/26/20
to weewx-user
Hello everbody

Unfortunately I haven't been able to solve the problem yet. I still have the problem that I want to include the sunshine time in my solar graphics. The value 0.08 is always given instead of 5min. How can you adjust that?

Meteo Oberwallis

unread,
Mar 27, 2020, 7:15:07 AM3/27/20
to weewx-user
Hi there.
I have recently taken the template for the hours of sunshine from the example under. Now I have noticed that my sunshine time in the xml is no longer correct. I think it's because of the conversion?

The Result:
<solar>
<solar value="831"/>
<solar_max value="877"/>
<solar_max_time value="11:39"/>
<sun_unformatted value="135.0"/>
<sun value="135 h 0 m"/>
</solar>

The Code:
<solar value="$current.radiation.formatted"/>
<solar_max value="$day.radiation.max.formatted"/>
<solar_max_time value="$day.radiation.maxtime.format("%H:%M")"/>
<sun_unformatted value="day.sunshine_hours.sum.raw"/>
#set hours = int($day.sunshine_hours.sum.raw)
#set minutes = int(($day.sunshine_hours.sum.raw - $hours)*60 + 0.5)
<sun value="$hours h $minutes m"/>

It is also said to divide the 130 minutes into hours and minutes. That means doing it with the existing code, but unfortunately it doesn't work anymore. Can someone help me?

Jacques Terrettaz

unread,
Mar 27, 2020, 7:49:17 AM3/27/20
to weewx-user

Hi,
With this extension, the sunshine time is recorded as minutes.

So in your case, to have the number of hours, you should divide the sum by 60:
 
#set hours = int($day.sunshine_hours.sum.raw/60)
#set minutes =
$day.sunshine_hours.sum.raw - ($hours*60)

With a daily sum of 135 minutes , this give:
hours = int(135/60) = 2
minutes = 135-(2*60)= 15

So

<sun value="$hours h $minutes m"/> should give now 2 h 15 m


 

Jacques Terrettaz

unread,
Mar 27, 2020, 8:03:02 AM3/27/20
to weewx-user

Hi,
Another way to go, if you want to have the sunshine time recorded as hours, is to mofify the end of the extension to divide  it by 60,  as follows :

 if mesure > seuil:
                    event.record['sunshine_time'] = event.record['interval']/60


Meteo Oberwallis

unread,
Mar 27, 2020, 8:14:05 AM3/27/20
to weewx-user
Hello.

Thx. Thats Work! I have another Problem.
A coming point now appears at the minutes, which should not be there. How can I remove it?

<sun_unformatted value="195.0"/>
<sun value="3 h 15.0 m"/>

Thank you

Jacques Terrettaz

unread,
Mar 27, 2020, 8:17:34 AM3/27/20
to weewx-user
May be :

#set minutes = int($day.sunshine_hours.sum.raw - ($hours*60))


Meteo Oberwallis

unread,
Mar 27, 2020, 8:20:58 AM3/27/20
to weewx-user
Great. That’s it. thank you very much

Meteo Oberwallis

unread,
Mar 27, 2020, 10:27:14 AM3/27/20
to weewx-user

I have another question. Is it possible that the entire database can now be run once in order to have the hours of sun generated by the past? The graphics are not up to date right now because the 5min sun was displayed as 0.8 before renewal.


Am Freitag, 27. März 2020 13:17:34 UTC+1 schrieb Jacques Terrettaz:
Reply all
Reply to author
Forward
0 new messages