Jump to content

Sunrise Time Question


macjeff

Recommended Posts

Posted

I want to add sunrise time to an email that goes out late afternoon.

In email you can add sunrise and sunset from the list of options but I can tell from the time that even though its late afternoon the sunrise is still what happened this morning.

If I go into programs there is an option for Sunrise today and sunrise tomorrow but those are in seconds.

I have no idea how to write a program to convert the tomorrow back to a real time but even if I did, how would I add the result into email?

I also could calculate the difference from today to tomorrow (seconds) in a program but how would you add that (or subtract if negative number) to the time value already in email for today.

So is there no easy way to get Sunrise tomorrow?   Even the climate module and the Dark Sky Node I run does not have tomorrow sunrise.

Any suggestions would be great and if some complicated program is required I would be happy to donate towards it.

Posted
14 minutes ago, macjeff said:

I want to add sunrise time to an email that goes out late afternoon.

In email you can add sunrise and sunset from the list of options but I can tell from the time that even though its late afternoon the sunrise is still what happened this morning.

If I go into programs there is an option for Sunrise today and sunrise tomorrow but those are in seconds.

I have no idea how to write a program to convert the tomorrow back to a real time but even if I did, how would I add the result into email?

I also could calculate the difference from today to tomorrow (seconds) in a program but how would you add that (or subtract if negative number) to the time value already in email for today.

So is there no easy way to get Sunrise tomorrow?   Even the climate module and the Dark Sky Node I run does not have tomorrow sunrise.

Any suggestions would be great and if some complicated program is required I would be happy to donate towards it.

Maybe this would be more helpful assuming you have a RPi / Polyisy in operations: 

 

Posted

Good suggestion but it does not have sunrise time tomorrow.

I have Polisy and Nodelink running.

I was running ISYData from Nodelink but switched to that TimeData node for Polisy.  I love it and I will put a request in for sunrise tomorrow on the authors GitHub page.

So thanks for the suggestion but at this time that wont fix issue

Posted
1 hour ago, macjeff said:

I love it and I will put a request in for sunrise tomorrow on the authors GitHub page.

My thought would be that the Sun nodeserver by @xKingmight be a more logical place for this calculation, as it already uses Lat & Long and the python astral library.  Just my 2¢, feel free to ignore.

Posted

I tried the SUN one and I could probably do the calculation but again converting it to a time AND putting the time into an email is fine.

I will ask the Sun server person too if they could add it as a text field then I can easily add to email.

 

Posted

Well, I can calculate the time no problem, but how would I return it back to ISY? ISY does not have text nor "timestamp" fields.

Posted
8 minutes ago, xKing said:

Well, I can calculate the time no problem, but how would I return it back to ISY? ISY does not have text nor "timestamp" fields.

Was thinking to give me 2 numbers      

Number 1     0-24 for the hour

Number 2      0-60 for the minute

 

So then I assign #1 and #2 to variables

Then I put   Sunrise is Variable 1  :   Variable 2

Now I have the time.

I could even figure out 12 hour format from it.

If hour is 12:00 -24:00 then its pm and 00:00 to 11:59 then its AM

I just need to get the seconds into the two numbers

This would be great in the TimeData Nodeserver if he would do it but so far no response there.

Jeff

Posted
6 minutes ago, xKing said:

Well, I can calculate the time no problem, but how would I return it back to ISY? ISY does not have text nor "timestamp" fields.

Already requested. We need a substString function in I/O.
Eg. substString($sMonth,'Jan', 'Feb', 'Mar', ,'Apr',...…...''Dec')

but then we would have to deal with date variable in number form inside ISY.

Posted

It think it would be easier to put together a python program to do that (send e-mail) vs trying to come up with ISY solution.

Posted
13 minutes ago, macjeff said:

Was thinking to give me 2 numbers      

Number 1     0-24 for the hour

Number 2      0-60 for the minute

 

So then I assign #1 and #2 to variables

Then I put   Sunrise is Variable 1  :   Variable 2

Now I have the time.

I could even figure out 12 hour format from it.

If hour is 12:00 -24:00 then its pm and 00:00 to 11:59 then its AM

I just need to get the seconds into the two numbers

This would be great in the TimeData Nodeserver if he would do it but so far no response there.

Jeff

https://forum.universal-devices.com/topic/27913-determine-season-of-the-year/?do=findComment&comment=273841

 

Posted
5 minutes ago, xKing said:

It think it would be easier to put together a python program to do that (send e-mail) vs trying to come up with ISY solution.

Yeah. A bank of predefined strings might work. Maybe a variable that could be inserted in any text string, and possibly a style of conversion field. It would get too abstract for most users though.

Posted
9 hours ago, larryllix said:

Yeah. A bank of predefined strings might work. Maybe a variable that could be inserted in any text string, and possibly a style of conversion field. It would get too abstract for most users though.

I agree thats too abstract and that a python program is better.  And thank you Larry for sending the season program but the TimeServer does that.   But for now a program to convert seconds to time (in two separate numbers is fine as I said  12    and    31 for example)    Then we could get the seconds for ANYTHING and convert it to a time and put that into email using variables.  Thats all I need and if someone is willing to do it, I will assist all I can though I am a basic programmer.  I consider myself more of a beta tester.  Apple calls me the BugMeister because I find bugs for them and a lot of time find the fix also.   Just found one and the solution last night in the TotalConnect node server and sent to both Github and UDI.    

So if someone wants to write it, I can chip in time for testing and assist a little in writing. I dont mind making a small financial contribution also so PM me if interested.

Posted
8 hours ago, macjeff said:

I agree thats too abstract and that a python program is better.  And thank you Larry for sending the season program but the TimeServer does that.   But for now a program to convert seconds to time (in two separate numbers is fine as I said  12    and    31 for example)    Then we could get the seconds for ANYTHING and convert it to a time and put that into email using variables.  Thats all I need and if someone is willing to do it, I will assist all I can though I am a basic programmer.  I consider myself more of a beta tester.  Apple calls me the BugMeister because I find bugs for them and a lot of time find the fix also.   Just found one and the solution last night in the TotalConnect node server and sent to both Github and UDI.    

So if someone wants to write it, I can chip in time for testing and assist a little in writing. I dont mind making a small financial contribution also so PM me if interested.

I prefer not to depend on so many external boxes (from ISY) for critical functions,  data, and core data, like time functions. Once polisy contains both portions of polyglot and ISY in one box, then it should be more dependable.

Posted

It's not a complicated program.  You just need to create a program that takes "Sunrise Tomorrow (seconds)" and converts it to an hour and minute and puts those values into variables, then make sure that program is called before your email is sent.  Here's a program that fills two integer variables:

Sunrise_Tomorrow - [ID 00B5][Parent 0001][Run At Startup]

If
   - No Conditions - (To add one, press 'Schedule' or 'Condition')
 
Then
        $iSunrise_Hr_Tomorrow  = [Sunrise Tomorrow (seconds)]
        
        // Divide by 3600 because there are 3600 seconds in an hour
 
        $iSunrise_Hr_Tomorrow /= 3600
        
        // To get the minute value we need to substract off all the
        // seconds that represent the hour.  Instead of using a
        // scratch variable we'll do that by taking the hour we
        // calculated above and multiply it by 3600.  Next we'll
        // multiple it by -1 so that we'll effectively be
        // subtracting it when we add "Sunrise Tomorrow (Seconds)"
 
        $iSunrise_Min_Tomorrow  = $iSunrise_Hr_Tomorrow
        $iSunrise_Min_Tomorrow *= 3600
        $iSunrise_Min_Tomorrow *= -1
        $iSunrise_Min_Tomorrow += [Sunrise Tomorrow (seconds)]
        
        // Now that we're left with just the seconds that represent
        // the minutes and seconds, we divide by 60 because there
        // are 60 seconds in a minute.
 
        $iSunrise_Min_Tomorrow /= 60
 
Else
   - No Actions - (To add one, press 'Action')

So now you can either call this program from the program that sends your email, or you can schedule it to run at some point before your program that sends the email.  If you call it from the program that sends your email, you'll need to add a WAIT to make sure this program finishes before you try to use the hour and minute values that it calculates.

Posted
On 2/13/2020 at 7:51 AM, macjeff said:

I want to add sunrise time to an email that goes out late afternoon.

In email you can add sunrise and sunset from the list of options but I can tell from the time that even though its late afternoon the sunrise is still what happened this morning.

If I go into programs there is an option for Sunrise today and sunrise tomorrow but those are in seconds.

I have no idea how to write a program to convert the tomorrow back to a real time but even if I did, how would I add the result into email?

I also could calculate the difference from today to tomorrow (seconds) in a program but how would you add that (or subtract if negative number) to the time value already in email for today.

So is there no easy way to get Sunrise tomorrow?   Even the climate module and the Dark Sky Node I run does not have tomorrow sunrise.

Any suggestions would be great and if some complicated program is required I would be happy to donate towards it.

If you pull the weekly forecast from Darksky, it has the sunrise and sunset for each day.

https://api.darksky.net/forecast/<<yourkeyhere>>/<<yourlat>>,<<yourlong>>?exclude=minutely,hourly

image.png.69545423935ee26ee580aa7f5a61a8c3.png

image.png.2e29d18934ccaf317397270af6ee34d9.png

I truncated each days data for brevity.

To continue...

If you have a Pi running already, you could do it easily in a few minutes in Node-Red. Yeah, some of you may be tired of my preaching it but I am really starting to like it.

image.thumb.png.66e7d5a8a92645f2f2bb9eae9f1075c4.png

Here is the javascript in the "Split To CSV" block to take the above data (day 0) and put it in my desired format and then send to a database. If you don't care much about the format, this could be condensed to about 10 3 lines using the pre-canned javascript date/time formats.

The "hanadb" block could easily be an email function.

 

var wudata = msg.payload;
var moonph=wudata.daily.data[0].moonPhase;
var astrondate=epochtodatestr(wudata.daily.data[0].sunriseTime);
var sunrise=epochtotimestr(wudata.daily.data[0].sunriseTime);
var sunset=epochtotimestr(wudata.daily.data[0].sunsetTime);
msg.topic="INSERT INTO Astron VALUES (0,'" + astrondate + "','" + moonph + "','" + sunrise + "','" + sunset + "');";
return msg;

function epochtotimestr(invald)
{
    var ets;
    var tmsg=invald;
    var tdate=new Date(tmsg*1000);
    var obtimehr = tdate.getHours();
    var obtimemn = tdate.getMinutes();
    var obtimesc = tdate.getSeconds();
    var obtimehrlz="";
    var obtimemnlz="";
    if(obtimehr<10)
        obtimehrlz="0";
    if(obtimemn<10)
        obtimemnlz="0";
    obtime=obtimehrlz+obtimehr + ":" + obtimemnlz + obtimemn;
    ets=obtime;
    return ets;
}
function epochtodatestr(invald)
{
    var ets;
    var tmsg=invald;
    var tdate=new Date(tmsg*1000);
    var obdateyr = tdate.getFullYear();
    var obdatemo = tdate.getMonth()+1;
    var obdateda = tdate.getDate();
    var obdatedalz="";
    var obdatemolz="";
    if(obdatemo<10)
        obdatemolz="0";
    if(obdateda<10)
        obdatedalz="0";
    obdate=obdateyr + "-" + obdatemolz + obdatemo + "-" + obdatedalz + obdateda;
    ets=obdate;
    return ets;
}

 

Posted

TimeData went to 2.0 and added sunrise and sunset hours which work great BUT they wont assign to a variable.  So strange because I can assign the regular time nodes like day or the week or week of the year but I cant assign ANY of the Sunrise and Sunset to the same variable (or any variable)

The reason I need to do this is to convert the 24 hour time to 12 hour time.

I put an issue in GitHub but if any of you guys can confirm this, or suggest a workaround, it would be nice.

https://github.com/ve7gel/Timedata/issues/4

Posted
11 minutes ago, asbril said:

When I try to update the Time-Date nodeserver, in Polisy,  I get the error message Pullrepo-undefined

I hate to tell you this but for that issue there was a bug in previous version.  The fix is easy but make sure you follow the instructions. 
 

delete node in Polisy for time data (configure and hit delete)

uninstall node sever in polisy

quit admin console. 
open  admin console

reinstall node sever in polisy  

install node into ISY IMPORTANT TO ISTALL IN SAME SLOT

Quit admin console

open admin console

if you followed the above instructions it should now work and your programs should all be fine as the slot stayed the same  

2.0 does require longitude and latitude settings   you put that under the configure section. A simple google of your address can get you the longitude and latitude where the ISY is   
 

then if you could write a quick program and test my issue that would be great  

create a variable

under then put variable = and choose some field in timedata

run then and that should work

now edit the program and use anything from the new sunrise sunset node   Run program again  your variable should not change   (Either zero or the result of previous time data test)   

Driving me crazy why it won’t work   Just want to know it’s not me  

if it does work try with another sunrise or sunset number and see if it works  I think I tested them all and none worked

Posted

Thanks macjeff, I am going to hold off on this for the moment. I just realized that this error also shows when trying to update another nodeserver, so it may be an issue that I have in my Polisy and not specific to Time-Date.

Posted

I have had three do this so far.  One was dark sky.   Can’t remember the other.   Worked with UDI tech support and they said do this.  Did for all three and it worked. 
 

Timedata is the easiest to do because very little config to do after install.   
 

I did this and was able to update to 2.0 with no issues so looks like once you reinstall it updates after that.  
 

yoir call but this is the same issue I had with several node servers.   

Posted

OK, I followed your instructions and Time-Date 2.0 works !!!!!  Thanks.

Now I have to do the same with Dark Sky.

Posted
38 minutes ago, macjeff said:

Driving me crazy why it won’t work   Just want to know it’s not me  

It's not just you.  It looks like there might be a problem with the "UOM" values in the profile for the "Sunrise and Sunset" nodes, but I'm not an expert.  Probably should flag @glarsen about this.

Posted
11 minutes ago, macjeff said:

It will work too.  I would screenshot your settings first.  Dark sky has a few.   

Dark Sky done as well, thanks for your guidance and update.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...