Hello Gray.

Here is the Script. Thx for Help.

Am Mittwoch, 16. Oktober 2019 07:47:43 UTC+2 schrieb gjr80:
>
> 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
>
> On Wednesday, 16 October 2019 15:26:42 UTC+10, Stefan wrote:
>>
>> 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.
>>
>>
>> Am Samstag, 12. Oktober 2019 11:46:57 UTC+2 schrieb gjr80:
>>>
>>> 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
>>>
>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/aa34ab3f-b442-4c00-8b57-362a73c9eb0b%40googlegroups.com.
"""

Adds a new observation field to weewx: [sunshine_hours]



If the radiation observed during an interval of time exceeds 120 W/m2, then the interval is considered sunny,

and [sunshine_hours] is set the length of the time interval.



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:



    [RadiationDays]

        min_sunshine = 200



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.radiationhours.RadiationHours 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.radiationhours.RadiationHours, weewx.engine.StdConvert, weewx.engine.StdCalibrate, weewx.engine.StdQC, weewx.wxservices.StdWXCalculate



    3. Add [sunshine_hours] 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.radiationhours.schema_with_sunshine_hour



        [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.radiationhours.schema_with_sunshine_hour



    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_hours'] = 'group_radiation'





        I've cheated here since Weewx doesn't have a unit for hours. So any graphs of sunshine hours will have the

        units W/m2, which I have hidden on the graph by setting the colour of the unit text to the background colour

        of the graph.



    6. Use [sunshine_hours] 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



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



        if 'RadiationDays' in config_dict:

            self.min_sunshine = float(config_dict['RadiationDays'].get('min_sunshine', self.min_sunshine))



        # Start intercepting events:

        self.bind(weewx.NEW_ARCHIVE_RECORD, self.newArchiveRecord)





    def newArchiveRecord(self, event):

        """Gets called on a new archive record event."""



        radiation = event.record.get('radiation')

        if (radiation is not None) and (radiation > self.min_sunshine):

            event.record['sunshine_hours'] = event.record['interval'] / 60.0

        else:

            event.record['sunshine_hours'] = 0.0



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

                      (event.record['sunshine_hours'], radiation, self.min_sunshine))





import schemas.wview

schema_with_sunshine_hours = schemas.wview.schema + [('sunshine_hours', 'REAL')]

Reply via email to