Template help please - time difference **solved**

All about the standard Meteobridge devices based on mobile routers from TP-Link, D-Link, ASUS

Moderator: Mattk

glennpm
Senior Boarder
Senior Boarder
Posts: 54
Joined: Sun Aug 03, 2014 8:47 pm

Template help please - time difference **solved**

Post by glennpm »

Hi,

I am struggling with common expressions. I would like to have a service report on the difference in hours and minutes for present sunset subtracted from the latest sunset of the year. I have tried many times but get nothing meaningful, below is one attempt. I am using the instructions posted on this link, http://www.meteobridge.com/wiki/index.php/Templates.The latest sunset is 20:26

Hours and minutes lost = {*20:26-[mbsystem-Sunset]=hh:mm*} \n

Thank you
Mattk
Platinum Boarder
Platinum Boarder
Posts: 1392
Joined: Mon Sep 22, 2014 3:24 am

Re: Template help please - time difference

Post by Mattk »

Might require a little more explanation?

"Present sunset"? Is that for today?
"Latest sunset"? 20:26 relates to what sunset, yesterday? Where does the 20:26 come from and how do you intend to use a fixed format value in an expression as I image this value will be variable? based on your expression what do you expect the result to look like?

Anyway for now dealing with your expression =hh:mm is not a date/time convertor, see Time/date variables on the template page. 20:26 is not a numeric number, it is a format so subtraction (maths expressions) probably not applicable, similar with [mbsystem-Sunset] which returns a time format not a numeric expression.

For what you are trying to do you may have to use the convertor "epoch" to return a numeric value in seconds, subtract from whatever then reformat as a time format output?
glennpm
Senior Boarder
Senior Boarder
Posts: 54
Joined: Sun Aug 03, 2014 8:47 pm

Re: Template help please - time difference

Post by glennpm »

Hi Mattk,

The "present sunset" is the sunset for the day I run the service.
The "latest sunset" is the latest sunset for the year and never changes. For me it is a fixed time of 20:26 or 73,560 seconds.

What I need to do is convert the value of [mbsystem-Sunset] into seconds and subtract that from 73,560 then change that number into a time format hh:mm as you mention.

Epoch is a date "... the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT) ..."

Thanks for your help.
User avatar
wvdkuil
Platinum Boarder
Platinum Boarder
Posts: 605
Joined: Sun Jul 24, 2011 8:00 pm
Location: Belgium
Contact:

Re: Template help please - time difference

Post by wvdkuil »

It would be dead-simple doing it in PHP on your webserver.
But if the meteobridge has to do it:

Code: Select all

{*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60*t}
:
{*60*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60-floor((1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60)*t}
You should combine the three lines to one line. So that the uotput would look like 0:34 in the example code below.
To test at my place I had to modify the latest sunset time to 22:30 => that explains the 1350 in the calculation. Your value would be 1226 for 20 hours plus 26 gives a total of 1226 minutes.

Sunset today at my place is at 21:56 so the "the difference in hours and minutes for present sunset subtracted from the latest sunset of the year" at my place would be zero hours and 34 minutes.

Calculations and the use of ab and de for the hours and minute postion are explained in the wiki=>templates=>Numerical Expressions

Wim
Testfile:

Code: Select all

latest sunset for test 22:30 => 1350 minutes
[mbsystem-Sunset]
[mbsystem-Sunset.ab]
[mbsystem-Sunset.de]

{*(1350-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60*t}
:
{*60*(1350-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60-floor((1350-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60)*t}
Results after Meteobridge processed it:

Code: Select all

latest sunset for test 22:30 => 1350 minutes
21:56
21
56

0
:
34
glennpm
Senior Boarder
Senior Boarder
Posts: 54
Joined: Sun Aug 03, 2014 8:47 pm

Re: Template help please - time difference

Post by glennpm »

Thank you Wim!

It worked fine for me. Now I'll add an entry for sunrise lost too.

Hours & Minutes of Sunset lost on [M]-[DD] – 34 Acorn#\n Hours:Minutes lost = {*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60*t}:{*60*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60-floor((1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60)*t}

email results:

Hours & Minutes of Sunset lost on 7-07 – 34 Acorn
Hours:Minutes lost = 0:2

Thanks for your help!
glennpm
Senior Boarder
Senior Boarder
Posts: 54
Joined: Sun Aug 03, 2014 8:47 pm

Re: Template help please - time difference

Post by glennpm »

Here is a service report that I'll run daily now for daylength, sunrise and sunset records.

Weather at 34 Acorn at [hh]:[mm] – Yesterday’s Day Length Report# Report run on: [MM]-[DD]\n\n Daylength is [mbsystem-Daylength.ab:--] hours [mbsystem-Daylength.de:--] minutes\n Hours & Minutes of daylength lost from June 21st, the longest at 15 hours and 29 minutes is {*(929-60*[mbsystem-Daylength.ab]-[mbsystem-Daylength.de])/60*t}:{*60*(929-60*[mbsystem-Daylength.ab]-[mbsystem-Daylength.de])/60-floor((929-60*[mbsystem-Daylength.ab]-[mbsystem-Daylength.de])/60)*t}\n Sunrise occured at [mbsystem-Sunrise:--]\n Hours & Minutes of Sunrise lost from earliest on June 18th (04:55) is {*(-295+60*[mbsystem-Sunrise.ab]+[mbsystem-Sunrise.de])/60*t}:{*60*(-295+60*[mbsystem-Sunrise.ab]+[mbsystem-Sunrise.de])/60-floor((-295+60*[mbsystem-Sunrise.ab]+[mbsystem-Sunrise.de])/60)*t}\n Sunset occured at [mbsystem-Sunset:--]\n Hours & Minutes of sunset time lost from June 21st (20:26) is {*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60*t}:{*60*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60-floor((1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60)*t}

email results:

Report run on: 07-08

Daylength is 15 hours 19 minutes
Hours & Minutes of daylength lost from June 21st, the longest at 15 hours and 29 minutes is 0:10
Sunrise occured at 05:05
Hours & Minutes of Sunrise lost from earliest on June 18th (04:55) is 0:10
Sunset occured at 20:23
Hours & Minutes of sunset time lost from June 21st (20:26) is 0:3
glennpm
Senior Boarder
Senior Boarder
Posts: 54
Joined: Sun Aug 03, 2014 8:47 pm

Re: Template help please - time difference

Post by glennpm »

Well all was good until the daylength time difference from the longest day was greater than one hour. The report now shows one hour but a total of the minutes and not those greater than an hour. In months to come this will be two, three, four hours, etc,
I'm not knowledgeble enough to fix this and seek help here please.

This:

Hours & Minutes of daylength lost from June 21st, the longest at 15 hours and 29 minutes is {*(929-60*[mbsystem-Daylength.ab]-[mbsystem-Daylength.de])/60*t}:{*60*(929-60*[mbsystem-Daylength.ab]-[mbsystem-Daylength.de])/60-floor((929-60*[mbsystem-Daylength.ab]-[mbsystem-Daylength.de])/60)*t}

yields:

Daylength is 14 hours 21 minutes
Hours & Minutes of daylength lost from June 21st (15 hours and 29 minutes) is 1:67

It should have yielded 1:08

Glenn
glennpm
Senior Boarder
Senior Boarder
Posts: 54
Joined: Sun Aug 03, 2014 8:47 pm

Re: Template help please - time difference

Post by glennpm »

Can anyone help me with this please?
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7854
Joined: Mon Oct 01, 2007 10:51 pm

Re: Template help please - time difference

Post by admin »

It would make your formular more generic, if Meteobridge would support "latest sunset" and "earliest sunrise" depending on the longitude/latitude you specified in Meteobridge settings. In addition having a converter that transfers time durations from astronomical variables into a "seconds" format might also help. Anybody apart from Glenn interested in this?
glennpm
Senior Boarder
Senior Boarder
Posts: 54
Joined: Sun Aug 03, 2014 8:47 pm

Re: Template help please - time difference

Post by glennpm »

Well I would welcome the additions!!
hymrog
Expert Boarder
Expert Boarder
Posts: 83
Joined: Sat Feb 01, 2014 1:25 am
Contact:

Re: Template help please - time difference

Post by hymrog »

Yep. I would like to see added. Thanks
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7854
Joined: Mon Oct 01, 2007 10:51 pm

Re: Template help please - time difference

Post by admin »

I started adding that features. Please see here: http://meteobridge.com/wiki/index.php/Forum

Can someone please give me remote access to his system, so that I can install beta code and give it a test drive?
As I am on vacation and powered down all my stuff when leaving home, I don't have my own rig test test with. :?

Please send login credentials to "info(at)smartbedded.com".
glennpm
Senior Boarder
Senior Boarder
Posts: 54
Joined: Sun Aug 03, 2014 8:47 pm

Re: Template help please - time difference

Post by glennpm »

link and password sent.

Thanks,
Glenn
glennpm
Senior Boarder
Senior Boarder
Posts: 54
Joined: Sun Aug 03, 2014 8:47 pm

Re: Template help please - time difference

Post by glennpm »

Seems to be working well.

Thank you!

This service event:

Weather at 34 Acorn at [hh]:[mm] – Yesterday’s Day Length Report# Report run on: [MM]-[DD]\n\n Daylength is [mbsystem-Daylength.ab:--] hours [mbsystem-Daylength.de:--] minutes\n
Minutes of daylength lost from June 21st (15 hours and 29 minutes) is {* [mbsystem-daylengthmax=mins.0] - [mbsystem-daylength=mins.0] *0}\n
Hours of daylength lost from June 21st (15 hours and 29 minutes) is {* ([mbsystem-daylengthmax=mins.0] - [mbsystem-daylength=mins.0])/60 *2}\n
Sunrise occurred at [mbsystem-Sunrise:--]\n
Minutes of Sunrise lost from earliest on June 18th (04:55) is {*60*(-295+60*[mbsystem-Sunrise.ab]+[mbsystem-Sunrise.de])/60-floor((-295+60*[mbsystem-Sunrise.ab]+[mbsystem-Sunrise.de])/60)*t}\n
Hours of Sunrise lost from earliest on June 18th (04:55) is {*(-295+60*[mbsystem-Sunrise.ab]+[mbsystem-Sunrise.de])/60*2}\n
Sunset occurred at [mbsystem-Sunset:--]\n
Minutes of sunset time lost from June 21st (20:26) is {*60*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60-floor((1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60)*t}\n
Hours of sunset time lost from June 21st (20:26) is {*(1226-60*[mbsystem-Sunset.ab]-[mbsystem-Sunset.de])/60*2}

Yields:

Daylength is 13 hours 57 minutes
Minutes of daylength lost from June 21st (15 hours and 29 minutes) is 92
Hours of daylength lost from June 21st (15 hours and 29 minutes) is 1.53
Sunrise occurred at 05:44
Minutes of Sunrise lost from earliest on June 18th (04:55) is 49
Hours of Sunrise lost from earliest on June 18th (04:55) is 0.82
Sunset occurred at 19:42
Minutes of sunset time lost from June 21st (20:26) is 44
Hours of sunset time lost from June 21st (20:26) is 0.73
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7854
Joined: Mon Oct 01, 2007 10:51 pm

Re: Template help please - time difference

Post by admin »

I added an option to specify number of leading zeros, which helps to display time difference in an "HH:MM" style:

Code: Select all

{*([mbsystem-daylengthmax=mins.0]-[mbsystem-daylength=mins.0])/60*00t}:{*([mbsystem-daylengthmax=mins.0]-[mbsystem-daylength=mins.0])% 60*00t}
Post Reply