[_CODE_] DAD - Display of Astronomical Data V1.2

EOL, unsupported.

[b]http://bugs.micasaverde.com/view.php?id=1451[/b]

WARNING:
There is a bug in the firmware for Vera V2 (including 1.1.1338) which leads to wrong calculations due to rounding errors (the Lua implementation uses ‘float’ instead of ‘double’). You are definitely affected by the bug, if the seconds for moonrise and/or moonset are different from ‘00’. Vera V1 users should be fine.

DAD displays the times for sunrise/sunset and moonrise/moonset, the current zodiac sign and the current moon phase on the GUI.

DAD provides the following times as UPnP variables (format: Unix timestamp and Human Understandable Format (HUF)) via UPnP service [tt]urn:upnp-ap15e-com:serviceId:DAD1[/tt]:

[ul][li]astronomical/nautical/civil twilight begin/end[/li]
[li]sunrise/sunset[/li]
[li]moonrise/moonset[/li]
[li]fraction of the moon illuminated at midnight/noon[/li][/ul]

DAD provides the following radiation data as UPnP variables (Germany only):

[ul][li]postcode and name of station[/li]
[li]height of station AMSL[/li]
[li]status of station[/li]
[li]total equivalent dose rate[/li]
[li]user defined threshold for total equivalent dose rate[/li]
[li]flag for total equivalent dose rate above threshold[/li][/ul]

DAD provides the following earthquake data as UPnP variables:

[ul][li]region[/li]
[li]date (UTC, local time, Unix timestamp)[/li]
[li]link to map[/li]
[li]magnitude[/li]
[li]location (latitude, longitude, depth)[/li]
[li]distance[/li]
[li]table of raw earthquake data[/li][/ul]

DAD provides the following Luup events:

[ul][li]astronomical/nautical/civil twilight begin/end[/li]
[li]sunrise/sunset[/li]
[li]moonrise/moonset[/li]
[li]possible impact of asteroid[/li][/ul]

[ul][li]total equivalent dose rate above/below user defined value[/li]
[li]total equivalent dose rate above user defined threshold[/li][/ul]

[ul][li]distance from earthquake less than user-defined value[/li]
[li]magnitude of earthquake greater than user-defined value[/li][/ul]

Dashboard layout for UI5:

                    [sunrise]        [sunset]

                    [moonrise]       [moonset]

[earthquake region] [magnitude]      [distance]

[total dose rate]   [station status] [zodiac sign]

Installation:

[ul][li]Upload the six files from the ZIP file to your box: ‘MiOS Developers’ → ‘Luup files’ → ‘Upload files’,[/li]
[li]check ‘Restart Luup after upload’, click ‘Go’, wait for Lua to restart,[/li]
[li]‘Create device’ tab-> ‘UpnpDevFilename’: [tt]D_DAD_UI5.xml[/tt] for UI5, [tt]D_DAD_UI4.xml[/tt] for earlier UI versions → click ‘Create device’,[/li]
[li]restart the Lua engine several times to initialise the UPnP variables,[/li]
[li]German users: go to [tt]http://odlinfo.bfs.de/laenderliste.php[/tt], select your state, set the UPnP variable [tt]DoseRateStationURL[/tt] to the URL for your state, and set the UPnP variable [tt]DoseRateStationID[/tt] to the ‘Kennung’ of the station nearest to your location,[/li]
[li]restart the Lua engine several times to initialise the UPnP variables,[/li]
[li]European users: set the UPnP variable [tt]EarthquakeProviderEU[/tt] to [tt]1[/tt] and restart the Lua engine.[/li]
[li]Displaying icons for the moon phases: install/configure [tt]http://www.quivira-font.com/files/Quivira.ttf[/tt] for your web client, set the UPnP variable [tt]DisplayMoonPhase[/tt] to [tt]1[/tt] and restart the the Lua engine. If the moon icon shows up as a rectangle, set [tt]DisplayMoonPhaseFont[/tt] to [tt]Quivira[/tt] (or to whatever font you are using for displaying moon phases) and restart the Lua engine. Please note that setting [tt]DisplayMoonPhaseFont[/tt] to a non-empty string triggers bug [tt]http://bugs.micasaverde.com/view.php?id=1447[/tt].
[/li][/ul]

Limitations:

[ul][li]DAD makes extensive use of Luup timers: all limitations of Luup timers apply to DAD.[/li]
[li]DAD won’t work for dates after 2038-01-19 (see http://forum.micasaverde.com/index.php?topic=5776.0).[/li]
[li]Currently, events do not work for UPnP variables with floating point values (see http://bugs.micasaverde.com/view.php?id=1444).[/li]
[li]The zodiac sign may be off by two days.[/li]
[li]When the [tt]EarthquakeDistance[/tt] event fires, the earthquake data set is consistent, when the [tt]EarthquakeMagnitude[/tt] event fires, the earthquake data set is guaranteed to be inconsistent :frowning: (see http://forum.micasaverde.com/index.php?topic=6213.0).[/li]
[li]The update interval for radiation data is 24 hours.[/li]
[li]The update interval for earthquake data is 5 minutes (DAD will miss earthquakes, which are less than 5 minutes apart).[/li]
[li]Do not base your decisions on the radiation/earthquake data from DAD.[/li][/ul]

Download:
[tt]https://docs.google.com/open?id=0Bz4omZm4gYcsMGE3NzAyYzMtOWYxZC00NDQxLThjOWUtNTc3MzBiNzM5NDdj[/tt]

Edit:
V0.02 adds support for civil, nautical, and astronomical twilight (see DAD_Advanced.jpg)
V0.03 adds support for moonrise and moonset (via U.S. Naval Observatory - Astronomical Applications Department)
V0.04 cosmetic changes
V0.05 bugfix for more than one moonrise/moonset per day (thanks to JOD), new variable DAD_USNO_URL
V0.06 bugfix for moorise/moonset for locations west of Greenwich (thanks to JOD)
V0.07 last :wink: bugfix for moonrise/moonset, adds fraction of the moon illuminated for midnight and noon
V0.08 adds load-balancing for all users within a specific timezone
V0.1 adds Luup events for astronomical/nautical/civil twilight, sunrise/sunset, moonrise/moonset, and possible impacts of asteroids
V0.11 adds equivalent dose rate for about 1800 locations in Germany (see http://odlinfo.bfs.de/)
V0.11a fix for new ODL number format …
V0.12 adds data for earthquakes (see http://earthquake.usgs.gov/earthquakes/catalogs/eqs1hour-M0.txt)
V0.13 BETA adds Luup events for radiation and earthquakes
V0.14 bugfix for DST issue (thanks to futzle for finding and fixing the bug)
V1.0 bugfix for DST issue for days on which the clocks shift (thanks to futzle for the suggestion), local time for latest earthquake
V1.0a bugfix for local time for latest earthquake …
V1.0b bugfix for moon illumination for the West, ‘workaround’ for Y2K38 bug (thanks to oTi@ for finding and fixing the bugs)
V1.0c bugfix for pattern matcher for timestamp of last earthquake
V1.0d adds support for earthquake data from http://www.seismicportal.eu/
V1.0e adds more robustness against error conditions and makes sure that the earthquake data set for the distance event is consistent (the earthquake data set for the magnitude event is inconsistent, this is a limitation of MiOS, see http://forum.micasaverde.com/index.php?topic=6213.0)
V1.0f adds support for zodiac signs
V1.0g adds support for moon icons that correspond to the moon phase
V1.0h bugfix for moon phases for the South (thanks to futzle)
V1.0i Unicode workaround for browser quirks (Chrome, IE, Safari) (thanks to oTi@ for the suggestion and for beta-testing)
V1.0j fix for new ODL site structure; change microSv/h to nSv/h (workaround for MiOS bug #1444);
remove variables Message and EarthquakeRawData from lu_sdata (as requested by TimAlls);
change the thresholds for moon illumination from 1/49/51/99 to 3/47/53/97 (as suggested by futzle)
V1.1 adds support for UI5: new variables Sunrise_HHMMSS, Sunset_HHMMSS, Moonrise_HHMMSS, Moonset_HHMMSS, MoonIcon, ZodiacSign
V1.2 bugfix for sunset events earlier than sunrise events (thanks to dchoe and CMRancho for finding the bug)

Hey Ap,

You always came with cool and useful plugins. Thanks!

AP

Thank you pretty cool

V0.03 adds support for moonrise and moonset.

Ap15e,

I added this yesterday. I get sunrise / set but not moonrise / set. Is that related to this link?
http://forum.micasaverde.com/index.php?topic=5482.0

JOD.

There are days without moonrise and without moonset …

Please check the data at:
http://aa.usno.navy.mil/data/docs/RS_OneYear.php

Both days, yesterday and today has data.

Jan 26 0026 1137

Jan 27 0130 1223

JOD.

Thanks for checking.

Please add [tt]luup.log(url)[/tt] to I_DAD.xml just after the statement [tt]local url = …[/tt] and please send me the url.

There are days with more than one moorise/moonset, e. g.:

http://aa.usno.navy.mil/cgi-bin/aa_rstablew.pl?FFX=2&xxy=2011&type=1&place=&xx0=-1&xx1=117&xx2=38&yy0=1&yy1=81&yy2=8&zz0=-1&zz1=11&ZZZ=END

DAD V0.04 assumes that there is one line per day. This may explain JOD’s problem.
Will be fixed with DAD V0.05.

Please upgrade to DAD V0.05 (contains a bugfix for moonrise/moonset).

@JOD
Please send me the value of the DAD_USNO_URL variable from the ‘Advanced’ tab, if your problem persists.

Please upgrade to V0.06 (contains a bugfix for moorise/moonset for locations west of Greenwich (thanks to JOD)).

Please upgrade to V0.07 (contains the last :wink: bugfix for moonrise/moonset and adds ‘fraction of the moon illuminated’ for midnight and noon.

Save energy, no need to switch on the outdoor lights if the moon is lit and the sky is clear:

local moon_delay         = 1800  -- activate moon_delay seconds after moonrise/up to moon_delay seconds before moonset
local illu_threshold     =   80  -- activate if illumination >= illu_threshold

local moon_rise          = luup.variable_get( 'urn:upnp-ap15e-com:serviceId:DAD1'          , 'Moonrise'                , 16847 )
local moon_set           = luup.variable_get( 'urn:upnp-ap15e-com:serviceId:DAD1'          , 'Moonset'                 , 16847 )
local moon_illu          = luup.variable_get( 'urn:upnp-ap15e-com:serviceId:DAD1'          , 'MoonIlluminationMidnight', 16847 )
local weather_condition  = luup.variable_get( 'urn:upnp-micasaverde-com:serviceId:Weather1', 'Condition'               , 16824 )

local moon_rise = tonumber( moon_rise )
local moon_set  = tonumber( moon_set  )
local moon_illu = tonumber( moon_illu ) or 0

local current_time       = os.time()

return  luup.is_night()
       and
         (  not ( ( moon_illu >= illu_threshold ) and ( weather_condition == 'Clear' ) ) 
           or
            (  ( ( moon_rise == nil ) and ( moon_set == nil ) ) -- no moonrise and no moonset today; we do not know where the moon is ...
              or
               ( ( moon_rise == nil ) and ( moon_set ~= nil ) and ( current_time > moon_set - moon_delay ) )
              or
               ( ( moon_rise ~= nil ) and ( moon_set == nil ) and ( current_time < moon_rise + moon_delay ) )
              or
               ( ( moon_rise ~= nil ) and ( moon_set ~= nil ) and ( current_time < moon_rise + moon_delay ) and ( current_time > moon_set - moon_delay ) )
            )
         )

Requirements:

[ul][li]DAD: http://forum.micasaverde.com/index.php?topic=5466.msg31383#msg31383[/li]
[li]Weather plugin: http://code.mios.com/trac/mios_weather[/li][/ul]

MCV,

what about adjusting the moon image in the banner to the illumination, if DAD is installed?

Ap15e,

V0.07 worked. Thank you.

JOD.

@Ap15e: I installed this according to your directions, and much to my surprise, it works! Maybe these Luup thingamabobs of yours aren’t as crazy as I thought.

Thanks for sharing your work with me!

@Ap15e: another happy customer… v0.08 worked perfectly.

You should have the icon change to be the current zodiac sign… hehe :wink:

.//A.

This looks great! Any ideas why my DAD device doesn’t show up as a device when trying to add an event to a scene? It also doesn’t show up as a device in the commands tab for a scene.

The google weather devices all show up fine.

Thanks!

Not yet implemented.

Which events and commands are you interested in?

AFAIK guessed’s weather device doesn’t show up in the ‘Command’ tab.

[quote=“Ap15e, post:17, topic:167457”]Not yet implemented.

Which events and commands are you interested in?

AFAIK guessed’s weather device doesn’t show up in the ‘Command’ tab.[/quote]

Hi Ap15e,

Thanks for the reply. What I was looking to do was to be able to activate lights by running a scene when the time hits twilight and/or sunset as reported by DAD. I sniffed around the LUA code resources last night and tried a little bit of writing but I am not sure how to test code beyond the Test Luup Code tab in the MIOS Developers area. It doesn’t seem very helpful as I either get a success or code error pop up which doesn’t tell me values in variables etc.

I am learning Python for work right now so trying to learn LUA at the same time doesn’t seem like the best course of action as I worry I’ll start mixing the two up. I am going to continue to poke around with this but I am sure the gurus could do this in a snap, I hate to ask for someone to do it for me without having at least dabbled in it myself a little bit. :slight_smile:

Thanks,
Chad

Something to try (without having to fiddle around with Luup devices):

Create a new scene with an absolute timer (every day, 00:02:00) and with Luup code that calls a function at twilight that runs a scene.

Use

[ul][li]luup.varariable_get (to get the unix timestamp for twilight)[/li]
[li]luup.call_timer(to call a function at twilight)[/li]
[li]luup.call_action(to run a scene)[/li][/ul]

Extremely ugly, but should work …

DAD V0.1 is available.

New feature:
Events for astronomical/nautical/civil twilight, sunrise/sunset, moonrise/moonset, and possible impacts of asteroids. Please download the files for DAD V0.1 from page 1 of this thread.