Using sunrise and sunset times within a service

15 views
Skip to first unread message

Peter Fletcher

unread,
Mar 26, 2023, 4:36:16 PM3/26/23
to weewx-development
weewx obviously 'knows' the sunrise and sunset times for the current date and location, since almost all available skins display them. Are their values accessible from within a service?

Tom Keffer

unread,
Mar 26, 2023, 6:54:11 PM3/26/23
to Peter Fletcher, weewx-development
Unfortunately, no, there's no easy way to get at the searchlist instance that does almanac tags.

Your best bet would be to create a private instance of weewx.almanac.Almanac and use that. That will require the time you want the almanac to be valid for and your position. Altitude is optional. These can be obtained from the engine. Something like this (NOT TESTED):

import time
import weewx.engine
import weewx.almanac

class MyService(weewx.engine.StdService):
    def __init__(self, engine, config_dict):
        super(MyService, self).__init__(engine, config_dict)

        latitude_f = engine.stn_info.latitude_f
        longitude_f = engine.stn_info.longitude_f
        altitude_vt = engine.stn_info.altitude_vt

        almanac = weewx.almanac.Almanac(time.time(),          # The time you want to use
                                        latitude_f,           # The latitude
                                        longitude_f,          # The longitude
                                        altitude=altitude_vt) # The altitude as a ValueTuple (optional)

        print("Jupiter will rise at", almanac.jupiter.rise)

The values can be further refined by adding the horizon angle, pressure, etc. See the initializer for Almanac, and the doctests for the class.

Hopefully, that will get you started!

-tk


On Sun, Mar 26, 2023 at 1:36 PM 'Peter Fletcher' via weewx-development <weewx-de...@googlegroups.com> wrote:
weewx obviously 'knows' the sunrise and sunset times for the current date and location, since almost all available skins display them. Are their values accessible from within a service?

--
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-development/c2bde934-9c69-431e-8fd1-e899067af581n%40googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages