Reason for this is that domoticz uses in my opinion the wrong type of sunrise/sunset.
For example today I see in domoticz ☀▲08:01 ▼18:03
While the civil twilight is 7:27 to 18:35.
At the sunset of domoticz it's already completely light outside. I rather use civil twilight so I can see the sunrise/sunset.
Anyway, the code...
from cron3600: Every hour I fetch the sunrise/sunset and store that.
Code: Select all
$sunrise=json_decode(
file_get_contents(
'https://api.sunrise-sunset.org/json?lat='
.$lat.'&lng='
.$lon.'&date=today&formatted=0'
),
true
);
if (isset($sunrise['results']['civil_twilight_begin'])) {
if (strtotime($sunrise['results']['civil_twilight_begin'])!=$d['civil_twilight']['s']) {
store('civil_twilight', strtotime($sunrise['results']['civil_twilight_begin']), basename(__FILE__).':'.__LINE__);
}
if (strtotime($sunrise['results']['civil_twilight_end'])!=$d['civil_twilight']['m']) {
storemode('civil_twilight', strtotime($sunrise['results']['civil_twilight_end']), basename(__FILE__).':'.__LINE__);
}
}
This is an optional step. You could also just use the if statement everywhere. I just tought it would be easier to just have to if($d['auto']['m']==true) than each time the complete if civil...
Code: Select all
if (TIME>=$d['civil_twilight']['s']&&TIME<=$d['civil_twilight']['m']) {
if ($d['auto']['m']!=true) {
storemode('auto', true, basename(__FILE__).':'.__LINE__);
$d['auto']['m']=true;
}
} else {
if ($d['auto']['m']!=false ) {
storemode('auto', false, basename(__FILE__).':'.__LINE__);
$d['auto']['m']=false;
}
}