I'm using the attached file, which I found somewhere here in this user 
forum. 
I've slightly adapted it to bette fit my needs. 

Don't get confused by the filed name 'EmptyReal'. That was just a spare 
field I had in my database.

The calculation of the theoretical radiation level is not 100% perfect, but 
it does the job.


[email protected] schrieb am Mittwoch, 10. März 2021 um 20:05:55 UTC+1:

> ok, i will try it locally before, but vserver is also a good (cheap) 
> option :-)
>
> another question to you: how do you calculate sun hours on your site, is 
> it from here? https://github.com/gjr80/weewx-weewx-wd
>
> Manfred Maier schrieb am Mittwoch, 10. März 2021 um 19:23:40 UTC+1:
>
>> No, I didn't.
>>
>> I'm (unfortunately) sitting behind fiberglass without a static IPv4. 
>> So I anyway had to rent a vServer for running my own tunneling solution 
>> for my local webcam.
>>
>> [email protected] schrieb am Mittwoch, 10. März 2021 um 19:12:12 UTC+1:
>>
>>> hi manfred,
>>>
>>> did you try to run the broker locally before? 
>>>
>>> i have a static ip with symmetric bandwidth. or are there other reasons 
>>> why it doesnt work?
>>>
>>> regards,
>>> chris
>>>
>>> Manfred Maier schrieb am Mittwoch, 10. März 2021 um 15:16:35 UTC+1:
>>>
>>>> Hi Chris,
>>>> I've been in a similar situation to you.
>>>> My web hosting service didn't allow me to run a MQTT broker and the 
>>>> (free) public brokers didn't perform very well. The majority of MQTT 
>>>> packages got lost and were not delivered to the web client.
>>>> So in the end I've decided to rent an additional vServer and run my own 
>>>> MQTT broker. The setup was really easy, but there's a server cost of 
>>>> approx. 2€ per month.
>>>>
>>>> Manfred  
>>>>
>>>> [email protected] schrieb am Mittwoch, 10. März 2021 um 11:59:33 UTC+1:
>>>>
>>>>> You need a publicly available MQTT broker. Either you install one on 
>>>>> your webhoster's webspace (if possible), or you use a public broker like 
>>>>> test.mosquitto.org.
>>>>>
>>>>> [email protected] schrieb am Mittwoch, 10. März 2021 um 07:46:52 
>>>>> UTC+1:
>>>>>
>>>>>> hello,
>>>>>>
>>>>>> i am uploading the reports via FTP to my webhoster. can i use mqtt 
>>>>>> then for live data oder do i need a locally webserver?
>>>>>>
>>>>>> regards,
>>>>>> chris
>>>>>>
>>>>>

-- 
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/f3f7ac18-e49e-4b3c-9406-00538bfd0cf3n%40googlegroups.com.
"""
Adds three new observation fields to weewx: [sunshineTime], [sunshineTheoretical], [emptyReal]
Installation:
    1. Save this file to your user customisations directory (which is often /usr/share/weewx/user)
    2. Follow these instructions for adding the three new data columns to your database:
       https://github.com/poblabs/weewx-belchertown/wiki/Adding-a-new-observation-type-to-the-WeeWX-database
       CAUTION: Have a backup of your database before trying to add the new data fields!
    3. Use [sunshineTime], [sunshineTheoretical], [emptyReal] in your graphs and html template tags.

Prerequisite: 
a. sun radiation field in database (radiation)
b. theoretical maximum radiation in database (maxSolarRad) 

[sunshineTime] = Time of sunshine (in minutes)
[sunshineTheoretical] = Time, when sunshine theoretically could have been (in Minutes)
[emptyReal] = Ratio of radiation / theoretical maximum radiation (only calculated during daytime)

Settings:
a. Sunshine can only occur when radiation is greater than 50 W/m2  (thresholdRadiation)
b. If radiation is 80-90% of maximum radiation, the radiation time counts half
c. If radiation is >90% of maximum radiation, the radiation time fully counts

Radiation time = archive interval

"""

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 RadiationHours(StdService):

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

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


    ''' New, simplified calculation '''

    def newArchiveRecord(self, event):
        thresholdRadiation = 50
        thresholdRatioLow = 75
        thresholdRatioHigh = 85
        radiation = event.record.get('radiation')
        maximum = event.record.get('maxSolarRad')
        event.record['sunshineTime'] = 0.0
        event.record['sunshineTheoretical'] = 0.0
        if radiation is not None:
            if maximum is not None:
                if maximum > thresholdRadiation:
                    ratio = (radiation / maximum) * 100
                    if ratio > 100:
                        ratio = 100
                    event.record['emptyReal'] = ratio
                    event.record['sunshineTheoretical'] = event.record['interval']
                    if ratio > thresholdRatioLow:
                        event.record['sunshineTime'] = event.record['interval'] / 2
                    if ratio > thresholdRatioHigh:
                        event.record['sunshineTime'] = event.record['interval']



    ''' Original calculation - not used anymore

    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['sunshineTime'] = 0.0
        event.record['sunshineTheoretical'] = 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:
                event.record['sunshineTheoretical'] = event.record['interval']
                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['sunshineTime'] = event.record['interval']

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

'''


'''  Not used, when new data fields are added in the above described way
schema_with_sunshine_time = schemas.wview.schema + [('sunshine_time', 'REAL')]
'''

Reply via email to