Hello,
Is there a way to obtain the day length delta value between now and a stated point in time in the past? I tried this: [mbsystem-daylength-delta24h:--] in a template but it does not work. I am trying to display the increase/decrease in the length of day compared to yesterday in a dashboard.
Thanks,
Baobab
daylength delta?
Moderator: Mattk
Re: daylength delta?
Not aware of any function that will provide day length for yesterday to make a comparative difference.
Re: daylength delta?
I also don't know a way to do this. Meteobridge computes data like this just on demand and does not store any history on that. As it is not related to changing weather condition, you might use an external program for that on your web space or alike?
Re: daylength delta?
I also needed/wanted this calculation.
I solved it as such:
At just before midnight, Meteobridge runs an event, creating a file on my webspace, called "daylength.txt". The template is only one line:
A few minutes later, it is the next day. By doing a comparision between the current daylength and the file daylength.txt, the difference between today and yesterday can be calculated.
I use php to do the calculation. A relevant snippet from my site is below.
Note that this info is not shown between 2300h and midnight, because of the calculation overlap.
Maybe this helps or gives some ideas to someone. 
I solved it as such:
At just before midnight, Meteobridge runs an event, creating a file on my webspace, called "daylength.txt". The template is only one line:
Code: Select all
[mbsystem-daylength]
I use php to do the calculation. A relevant snippet from my site is below.
Note that this info is not shown between 2300h and midnight, because of the calculation overlap.
Code: Select all
<?php
$myfile = fopen("daylength.txt", "r") or die("Cannot calculate! Err: daylength.txt missing");
$yesterday = strtotime( fgets($myfile) );
fclose($myfile);
$today = strtotime([mbsystem-daylength]);
$curr_tim = $timeh;
// *** Calc change from yesterday ***
// OBS !!!!
// mbsystem-daylength in daylength.txt :: Make this in meteobridge cirka 23.00h
$timediff = $today - $yesterday;
$timediff_min = round( ($timediff / 60) ,0);
if (($curr_tim != 23) && ($curr_tim != 0)) {
if ($timediff_min == 0) {
echo "Today is equal in length as yesterday.";
}
else {
echo 'Today is '.abs($timediff_min).' min ';
if ($timediff_min < 0) {
echo "shorter";
}
else {
echo "longer";
}
echo " than yesterday.";
}
}
else {
echo "It is night...";
}
?>

PWS Villshärad/Halmstad, Sweden: vader.fishmoose.se DavisVPro + MB NanoSD.
Re: daylength delta?
In case anyone is looking for a solution, here is how I solved it. The python script below gets executed via a cron job at 23:55 of every day. The resulting json file contains the change in day length and can then be processed in many different ways.
Code: Select all
#!/usr/bin/env python3
import requests
import json
import time
url = 'http://192.168.1.122/cgi-bin/template.cgi?templatefile=json_template.html&contenttype=text/plain;charset=utf-8'
username = 'meteobridge'
password = 'xyx'
output = json.loads(requests.get(url, auth=(username, password)).content)
yest = output["astro"]["daylength"]
yest_min = int(yest[:-3]) * 60 + int(yest[-2:])
time.sleep(600)
output1 = json.loads(requests.get(url, auth=(username, password)).content)
tday = output1["astro"]["daylength"]
tday_min = int(tday[:-3]) * 60 + int(tday[-2:])
delta = tday_min - yest_min
f = open("/root/docker-compose-lamp/www/dashboard/daylight_delta.json", "w")
f.write("{\"daylight_delta\" :" + str(delta) + "}")
f.close()