daylength delta?

This section covers the Meteobridge PRO, PRO2, NANO SD, Raspberry Pi and VM platforms exclusively

Moderator: Mattk

Post Reply
baobab
Junior Boarder
Junior Boarder
Posts: 37
Joined: Sat Dec 25, 2010 11:00 pm

daylength delta?

Post by baobab »

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
Mattk
Platinum Boarder
Platinum Boarder
Posts: 1387
Joined: Mon Sep 22, 2014 3:24 am

Re: daylength delta?

Post by Mattk »

Not aware of any function that will provide day length for yesterday to make a comparative difference.
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7854
Joined: Mon Oct 01, 2007 10:51 pm

Re: daylength delta?

Post by admin »

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?
svampen
Junior Boarder
Junior Boarder
Posts: 32
Joined: Fri Aug 16, 2019 10:57 am
Location: Sweden
Contact:

Re: daylength delta?

Post by svampen »

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:

Code: Select all

[mbsystem-daylength]
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.

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...";
	}
?>
Maybe this helps or gives some ideas to someone. :)
PWS Villshärad/Halmstad, Sweden: vader.fishmoose.se DavisVPro + MB NanoSD.
baobab
Junior Boarder
Junior Boarder
Posts: 37
Joined: Sat Dec 25, 2010 11:00 pm

Re: daylength delta?

Post by baobab »

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()
Post Reply