Please login or register.

Login with username, password and session length
Advanced search  

News:

The X10Hub (PiX10Hub) is here! Created by the Community, for the Community.:)% #:)

Author Topic: Lights set to Moon Phases  (Read 402 times)

LostDog88

  • Sr. Member
  • ****
  • Helpful Post Rating: 1
  • Posts: 144
Lights set to Moon Phases
« on: September 27, 2019, 10:21:37 PM »

So........In my quest to automate everything I can.......LOL........I have decided to attach the fish tank next.

Currently I have a hood lamp that does sunlight (mimics of course) and a hood lamp that does Moon Lights. I use a module to turn off the sun light at sunset and turn it back on at sunrise.

For my next trick I would like to dim/brighten the moon lights based on the phases of the moon. For instance full moon, full bright, 1/2 moon, half light. No moon, no light. Etc. etc.

Does anything in JKUTILS do something like this?
Logged

bkenobi

  • PI Expert
  • Hero Member
  • ******
  • Helpful Post Rating: 18
  • Posts: 1727
Re: Lights set to Moon Phases
« Reply #1 on: October 01, 2019, 02:12:39 PM »

I've never seen nor looked for anything on moon phase.  But, since the moon is on a 27 day cycle (memory could be wrong), you could technically write your own schedule event.

EDIT:  I was close, but not good enough for a scheduled event.

Quote
It takes 27 days, 7 hours, and 43 minutes for our Moon to complete one full orbit around Earth. This is called the sidereal month, and is measured by our Moon's position relative to distant “fixed” stars. However, it takes our Moon about 29.5 days to complete one cycle of phases (from new Moon to new Moon).

https://www.lpi.usra.edu/education/skytellers/moon-phases/
« Last Edit: October 01, 2019, 02:15:13 PM by bkenobi »
Logged

bkenobi

  • PI Expert
  • Hero Member
  • ******
  • Helpful Post Rating: 18
  • Posts: 1727
Re: Lights set to Moon Phases
« Reply #2 on: October 01, 2019, 02:20:33 PM »

Since I was curious, you can also just use the following C# code in a HG module (assuming that's your HA software).  It will require framing correctly since HG uses HG code in a slightly different format.

https://gist.github.com/adrianstevens/776530e198734b34a9c8a43aaf880041

Code: [Select]
        public int GetJulianDate(int day, int month, int year)
        {
            year = year - (12 - month) / 10;

            month = month + 9;

            if (month >= 12)
                month = month - 12;

            var k1 = (int)(365.25 * (year + 4712));
            var k2 = (int)(30.6001 * month + 0.5);
           
            // 'j' for dates in Julian calendar:
            var julianDate = k1 + k2 + day + 59;

            //Gregorian calendar
            if (julianDate > 2299160)
            {
                var k3 = (int)((year / 100 + 49) * 0.75) - 38;
                julianDate = julianDate - k3; //at 12h UT (Universal Time)
            }

            return julianDate;
        }

        public double GetMoonAge(int day, int month, int year)
        {
            double ip, age;

            int julianDate = GetJulianDate(day, month, year);

            ip = (julianDate + 4.867) / 29.53059;
            ip = ip - Math.Floor(ip);

            age = ip * MoonCycleLength + MoonCycleLength / 2;

            if (age > MoonCycleLength)
                age -= MoonCycleLength;

            return age;
        }

LostDog88

  • Sr. Member
  • ****
  • Helpful Post Rating: 1
  • Posts: 144
Re: Lights set to Moon Phases
« Reply #3 on: October 05, 2019, 05:24:16 PM »

Oh man........

I have no clue what framing means?

I am using HG as my automation on a RPi3. I can only guess that you want me to bind this code to the module and it should work after saving it?

Please don't confuse my ignorance for intelligence. I want to learn this stuff, but it is hard. But rewarding. But hard. :-). But I'm trying.


Logged

bkenobi

  • PI Expert
  • Hero Member
  • ******
  • Helpful Post Rating: 18
  • Posts: 1727
Re: Lights set to Moon Phases
« Reply #4 on: October 07, 2019, 11:49:52 AM »

No intent at all.  I just meant that C# code has to be encased in other code to work.  I was just providing the functional part/snippet that should do what you need.  You'd have to write a few lines beyond that and drop it in a HG C# module in order to use.  The nitty-gritty part is taken care of, but linking it to HG is still required.

If you wanted to do something similar another way, you could probably source a Python or even cron-tab set of code to do the same thing.

LostDog88

  • Sr. Member
  • ****
  • Helpful Post Rating: 1
  • Posts: 144
Re: Lights set to Moon Phases
« Reply #5 on: October 07, 2019, 11:06:10 PM »

Okay. I will work on this when I have some free time this weekend.

Exciting. I will be able to automate even more things! My wife says I'm just a big boy. Duh. I thought she already knew that!
Logged

petera

  • PI Expert
  • Hero Member
  • ******
  • Helpful Post Rating: 19
  • Posts: 1093
Re: Lights set to Moon Phases
« Reply #6 on: October 08, 2019, 07:24:03 AM »

This post reminded me of something similar from the old forum from a while back http://old.homegenie.club:8080/www.homegenie.it/forum/index3f86.html?topic=55.0
Logged

bkenobi

  • PI Expert
  • Hero Member
  • ******
  • Helpful Post Rating: 18
  • Posts: 1727
Re: Lights set to Moon Phases
« Reply #7 on: October 08, 2019, 11:51:01 AM »

Wow, that was a while ago!  Nice to know I've learned a thing or two over the years.   :)%

petera

  • PI Expert
  • Hero Member
  • ******
  • Helpful Post Rating: 19
  • Posts: 1093
Re: Lights set to Moon Phases
« Reply #8 on: October 08, 2019, 02:10:49 PM »

I knew that would stir a memory or two. Used to enjoy those C# code exchanges  :)%
Logged
 

X10.com | About X10 | X10 Security Systems | Cameras| Package Deals
© Copyright 2014-2016 X10.com All rights reserved.