<?php
-function getWeather() {
- $place = 623;
- $apikey = 'fM7z3yrWwnUuXuAPPYIM5EqTl2iBAGB6';
-
- $cache = ROOT . '/cache/accuweather.json';
- $limit = max(time() - 3600, 0);
-
- if (!file_exists($cache) || filemtime($cache) < $limit) {
- copy('http://dataservice.accuweather.com/currentconditions/v1/' . $place . '?apikey=' . $apikey . '&language=fr-FR&details=true', $cache);
- }
-
- $res = [];
- $weather = json_decode(file_get_contents($cache), true);
- $weather = $weather[0];
- $res['temp'] = round(($weather['Temperature']['Metric']['Value']/* + getState('airtemperature')*/));
- $res['outdoor_temp'] = toNumber(haGetState(['sensor.indoor_outdoor_meter_ddf7_temperature', 'sensor.w340001x_tempc']), 1);
- $res['outdoor_humidity'] = toNumber(haGetState(['sensor.indoor_outdoor_meter_ddf7_humidity', 'sensor.w340001x_hum']), true);
- $res['outdoor_pressure'] = toNumber(haGetState('sensor.0x00158d000464c885_pressure'), true);
- $res['backyard_temp'] = toNumber(haGetState('sensor.0x00158d000464c885_temperature'), 1);
- $res['backyard_humidity'] = toNumber(haGetState('sensor.0x00158d000464c885_humidity'), true);
- $res['backyard_pressure'] = toNumber(haGetState('sensor.0x00158d000464c885_pressure'), true);
- $res['bathroom_temp'] = toNumber(haGetState('sensor.0x00158d0004658cc2_temperature'), 1);
- $res['bathroom_humidity'] = toNumber(haGetState('sensor.0x00158d0004658cc2_humidity'), true);
- $res['bedroom_temp'] = toNumber(haGetState('sensor.0x54ef4410003596e5_temperature'), 1);
- $res['bedroom_humidity'] = toNumber(haGetState('sensor.0x54ef4410003596e5_humidity'), true);
- $res['bedroom_airquality'] = toNumber(haGetState('sensor.0x54ef4410003596e5_voc'), true);
- $res['livingroom_temp'] = toNumber(haGetState('sensor.temperature_salon_temperature'), 1);
- $res['livingroom_humidity'] = toNumber(haGetState('sensor.temperature_salon_humidity'), true);
- $res['kitchen_temp'] = toNumber(haGetState('sensor.0x00158d000418441f_temperature'), 1);
- $res['kitchen_humidity'] = toNumber(haGetState('sensor.0x00158d000418441f_humidity'), true);
- $res['wc_temp'] = toNumber(haGetState('sensor.0x00158d00046574da_temperature'), 1);
- $res['wc_humidity'] = toNumber(haGetState('sensor.0x00158d00046574da_humidity'), true);
- $res['office_temp'] = toNumber(haGetState(['sensor.meter_c7c3_temperature', 'sensor.thx1_w230150x_tempc']), 1);
- $res['office_humidity'] = toNumber(haGetState(['sensor.meter_c7c3_humidite', 'sensor.thx1_w230150x_hum']), true);
- // $res['cellar_humidity'] = toNumber(getDomoticzDeviceStatus(4818), true);
- // $res['cellar_temp'] = toNumber(getDomoticzDeviceStatus(4817), 1);
- $res['cellar_humidity'] = 0;
- $res['cellar_temp'] = 0;
- $res['pressure'] = round($weather['Pressure']['Metric']['Value']);
- $res['pressureTendency'] = $weather['PressureTendency']['Code'];
- $res['precipitations24'] = round($weather['PrecipitationSummary']['Past24Hours']['Metric']['Value']);
- $res['cloudCover'] = $weather['CloudCover'];
- $res['ceiling'] = $weather['Ceiling']['Imperial']['Value'];
- $res['icon'] = $weather['WeatherIcon'];
- if ($res['icon'] < 10) {
- $res['icon'] = '0' . $res['icon'];
- }
-
- $cache = ROOT . '/cache/accuforecasts.json';
- if (!file_exists($cache) || filemtime($cache) < $limit) {
- copy('http://dataservice.accuweather.com/forecasts/v1/daily/5day/' . $place . '?apikey=' . $apikey . '&language=fr-FR&metric=true&details=true', $cache);
- }
- $forecasts = json_decode(file_get_contents($cache), true);
- $f = $forecasts['DailyForecasts'][0];
- $res['dayIcon'] = $f['Day']['Icon'];
-
- if ($res['dayIcon'] < 10) {
- $res['dayIcon'] = '0' . $res['dayIcon'];
- }
- $res['nightIcon'] = $f['Night']['Icon'];
- if ($res['nightIcon'] < 10) {
- $res['nightIcon'] = '0' . $res['nightIcon'];
- }
- $res['min'] = round($f['Temperature']['Minimum']['Value']);
- $res['max'] = round($f['Temperature']['Maximum']['Value']);
-
- $res['sunrise'] = $f['Sun']['EpochRise'];
- $res['sunset'] = $f['Sun']['EpochSet'];
- $res['moon'] = $f['Moon']['Phase'];
- $res['moonage'] = $f['Moon']['Age'];
- $res['moonrise'] = $f['Moon']['EpochRise'];
- $res['moonset'] = $f['Moon']['EpochSet'];
-
- $res['forecasts'] = [];
- $days = ['D', 'L', 'M', 'M', 'J', 'V', 'S'];
- for ($i = 1; $i <= 4; $i++) {
- $j = $i - 1;
- $res['forecasts'][$j] = [];
- $f = $forecasts['DailyForecasts'][$i];
- $res['forecasts'][$j]['dayIcon'] = $f['Day']['Icon'];
-
- if ($res['forecasts'][$j]['dayIcon'] < 10) {
- $res['forecasts'][$j]['dayIcon'] = '0' . $res['forecasts'][$j]['dayIcon'];
- }
- $res['forecasts'][$j]['nightIcon'] = $f['Night']['Icon'];
- if ($res['forecasts'][$j]['nightIcon'] < 10) {
- $res['forecasts'][$j]['nightIcon'] = '0' . $res['forecasts'][$j]['nightIcon'];
- }
- $res['forecasts'][$j]['min'] = round($f['Temperature']['Minimum']['Value']);
- $res['forecasts'][$j]['max'] = round($f['Temperature']['Maximum']['Value']);
- $res['forecasts'][$j]['day'] = $days[date('w', $f['EpochDate'])];
- }
-
- file_put_contents(ROOT . '/cache/weather.json', json_encode($res));
- return $res;
+function getWeather()
+{
+ $place = 623;
+ $apikey = 'fM7z3yrWwnUuXuAPPYIM5EqTl2iBAGB6';
+
+ $cache = ROOT . '/cache/accuweather.json';
+ $limit = max(time() - 3600, 0);
+
+ if (!file_exists($cache) || filemtime($cache) < $limit) {
+ copy('http://dataservice.accuweather.com/currentconditions/v1/' . $place . '?apikey=' . $apikey . '&language=fr-FR&details=true', $cache);
+ }
+
+ $res = [];
+ $weather = json_decode(file_get_contents($cache), true);
+ $weather = $weather[0];
+ $res['temp'] = round(($weather['Temperature']['Metric']['Value']/* + getState('airtemperature')*/));
+ $res['outdoor_temp'] = toNumber(haGetState(['sensor.indoor_outdoor_meter_ddf7_temperature', 'sensor.w340001x_tempc']), 1);
+ $res['outdoor_humidity'] = toNumber(haGetState(['sensor.indoor_outdoor_meter_ddf7_humidity', 'sensor.w340001x_hum']), true);
+ $res['outdoor_pressure'] = toNumber(haGetState('sensor.0x00158d000464c885_pressure'), true);
+ $res['backyard_temp'] = toNumber(haGetState('sensor.indoor_outdoor_meter_1719'), 1);
+ $res['backyard_humidity'] = toNumber(haGetState('sensor.indoor_outdoor_meter_1719_humidite'), true);
+ $res['backyard_pressure'] = toNumber(haGetState('sensor.0x00158d0004658cc2_pressure'), true);
+ $res['bathroom_temp'] = toNumber(haGetState('sensor.0x00158d0004658cc2_temperature'), 1);
+ $res['bathroom_humidity'] = toNumber(haGetState('sensor.0x00158d0004658cc2_humidity'), true);
+ $res['bedroom_temp'] = toNumber(haGetState('sensor.0x54ef4410003596e5_temperature'), 1);
+ $res['bedroom_humidity'] = toNumber(haGetState('sensor.0x54ef4410003596e5_humidity'), true);
+ $res['bedroom_airquality'] = toNumber(haGetState('sensor.0x54ef4410003596e5_voc'), true);
+ $res['livingroom_temp'] = toNumber(haGetState('sensor.temperature_salon_temperature'), 1);
+ $res['livingroom_humidity'] = toNumber(haGetState('sensor.temperature_salon_humidity'), true);
+ $res['kitchen_temp'] = toNumber(haGetState('sensor.0x00158d000418441f_temperature'), 1);
+ $res['kitchen_humidity'] = toNumber(haGetState('sensor.0x00158d000418441f_humidity'), true);
+ $res['wc_temp'] = toNumber(haGetState('sensor.0x00158d00046574da_temperature'), 1);
+ $res['wc_humidity'] = toNumber(haGetState('sensor.0x00158d00046574da_humidity'), true);
+ $res['office_temp'] = toNumber(haGetState(['sensor.meter_c7c3_temperature', 'sensor.thx1_w230150x_tempc']), 1);
+ $res['office_humidity'] = toNumber(haGetState(['sensor.meter_c7c3_humidite', 'sensor.thx1_w230150x_hum']), true);
+ // $res['cellar_humidity'] = toNumber(getDomoticzDeviceStatus(4818), true);
+ // $res['cellar_temp'] = toNumber(getDomoticzDeviceStatus(4817), 1);
+ $res['cellar_humidity'] = 0;
+ $res['cellar_temp'] = 0;
+ $res['pressure'] = round($weather['Pressure']['Metric']['Value']);
+ $res['pressureTendency'] = $weather['PressureTendency']['Code'];
+ $res['precipitations24'] = round($weather['PrecipitationSummary']['Past24Hours']['Metric']['Value']);
+ $res['cloudCover'] = $weather['CloudCover'];
+ $res['ceiling'] = $weather['Ceiling']['Imperial']['Value'];
+ $res['icon'] = $weather['WeatherIcon'];
+ if ($res['icon'] < 10) {
+ $res['icon'] = '0' . $res['icon'];
+ }
+
+ $cache = ROOT . '/cache/accuforecasts.json';
+ if (!file_exists($cache) || filemtime($cache) < $limit) {
+ copy('http://dataservice.accuweather.com/forecasts/v1/daily/5day/' . $place . '?apikey=' . $apikey . '&language=fr-FR&metric=true&details=true', $cache);
+ }
+ $forecasts = json_decode(file_get_contents($cache), true);
+ $f = $forecasts['DailyForecasts'][0];
+ $res['dayIcon'] = $f['Day']['Icon'];
+
+ if ($res['dayIcon'] < 10) {
+ $res['dayIcon'] = '0' . $res['dayIcon'];
+ }
+ $res['nightIcon'] = $f['Night']['Icon'];
+ if ($res['nightIcon'] < 10) {
+ $res['nightIcon'] = '0' . $res['nightIcon'];
+ }
+ $res['min'] = round($f['Temperature']['Minimum']['Value']);
+ $res['max'] = round($f['Temperature']['Maximum']['Value']);
+
+ $res['sunrise'] = $f['Sun']['EpochRise'];
+ $res['sunset'] = $f['Sun']['EpochSet'];
+ $res['moon'] = $f['Moon']['Phase'];
+ $res['moonage'] = $f['Moon']['Age'];
+ $res['moonrise'] = $f['Moon']['EpochRise'];
+ $res['moonset'] = $f['Moon']['EpochSet'];
+
+ $res['forecasts'] = [];
+ $days = ['D', 'L', 'M', 'M', 'J', 'V', 'S'];
+ for ($i = 1; $i <= 4; $i++) {
+ $j = $i - 1;
+ $res['forecasts'][$j] = [];
+ $f = $forecasts['DailyForecasts'][$i];
+ $res['forecasts'][$j]['dayIcon'] = $f['Day']['Icon'];
+
+ if ($res['forecasts'][$j]['dayIcon'] < 10) {
+ $res['forecasts'][$j]['dayIcon'] = '0' . $res['forecasts'][$j]['dayIcon'];
+ }
+ $res['forecasts'][$j]['nightIcon'] = $f['Night']['Icon'];
+ if ($res['forecasts'][$j]['nightIcon'] < 10) {
+ $res['forecasts'][$j]['nightIcon'] = '0' . $res['forecasts'][$j]['nightIcon'];
+ }
+ $res['forecasts'][$j]['min'] = round($f['Temperature']['Minimum']['Value']);
+ $res['forecasts'][$j]['max'] = round($f['Temperature']['Maximum']['Value']);
+ $res['forecasts'][$j]['day'] = $days[date('w', $f['EpochDate'])];
+ }
+
+ file_put_contents(ROOT . '/cache/weather.json', json_encode($res));
+ return $res;
}
-function weatherStationScreenSaver() {
- $weather = json_decode(file_get_contents(ROOT . '/cache/weather.json'), true);
-
- $pressureTendency = $weather['pressureTendency'] == 'F' ? 'down' : 'up';
- $pressure = $weather['outdoor_pressure'] == '--' ? $weather['backyard_pressure'] : $weather['outdoor_pressure'];
-
- $res = '<div id="weatherstation" class="screensaver">';
- $res .= '<div class="contents">';
- $res .= '<div class="time"></div>';
- $res .= '<div class="current">';
- $res .= '<div class="icon">' . accuweatherIcon($weather['icon']) . '</div>';
- $res .= '<div class="icons">';
- $res .= '<div class="night">' . accuweatherIcon($weather['nightIcon']) . '</div>';
- $res .= '<div class="day">' . accuweatherIcon($weather['dayIcon']) . '</div>';
- $res .= '</div>';
- $res .= '<div class="temps">';
- $res .= '<div class="temp-min">' . $weather['min'] . '°C</div>';
- $res .= '<div class="temp"> ' . $weather['outdoor_temp'] . '°C <span style="font-size:20%;"> ' . $weather['temp'] . '°C</span></div>';
- $res .= '<div class="temp-max">' . $weather['max'] . '°C</div>';
- $res .= '</div>';
- $res .= '<div class="pp">';
- $res .= '<i class="fas fa-cloud-rain"></i> ' . $weather['precipitations24'] . ' mm | <i class="fas fa-tachometer-alt"></i> ' . $pressure . ' hPa <i class="fa fa-arrow-circle-' . $pressureTendency . '"></i> | <i class="fa fa-tint"></i> ' . $weather['outdoor_humidity'] . '%';
- $res .= '</div>';
- $res .= '<table class="house">';
- $res .= '<tr><td class="hicon backyard"><i class="fa fa-flower-tulip"></i></td><td class="backyard">' . $weather['backyard_temp'] . ' °C</td><td class="hicon hum backyard"><i class="fa fa-tint"></i></td><td class="hum backyard">' . $weather['backyard_humidity'] . '%</td>';
- $res .= '<td class="sep"></td><td class="hicon kitchen"><i class="fa fa-knife-kitchen"></i></td><td class="kitchen">' . $weather['kitchen_temp'] . ' °C</td><td class="hicon hum kitchen"><i class="fa fa-tint"></i></td><td class="hum kitchen">' . $weather['kitchen_humidity'] . '%</td></tr>';
- $res .= '<tr><td class="hicon livingroom"><i class="fa fa-cocktail"></i></td><td class="livingroom">' . $weather['livingroom_temp'] . ' °C</td><td class="hicon hum livingroom"><i class="fa fa-tint"></i></td><td class="hum livingroom">' . $weather['livingroom_humidity'] . '%</td>';
- $res .= '<td class="sep"></td><td class="hicon office"><i class="fa fa-plane"></i></td><td class="office">' . $weather['office_temp'] . ' °C</td><td class="hicon hum office"><i class="fa fa-tint"></i></td><td class="hum office">' . $weather['office_humidity'] . '%</td></tr>';
- $res .= '<tr><td class="hicon wc"><i class="fa fa-toilet"></i></td><td class="wc">' . $weather['wc_temp'] . ' °C</td><td class="hicon hum wc"><i class="fa fa-tint"></i></td><td class="hum wc">' . $weather['wc_humidity'] . '%</td>';
- $res .= '<td class="sep"></td><td class="hicon bedroom"><i class="fa fa-bed"></i></td><td class="bedroom">' . $weather['bedroom_temp'] . ' °C</td><td class="hicon hum bedroom"><i class="fa fa-tint"></i></td><td class="hum bedroom">' . $weather['bedroom_humidity'] . '%</td>';
- $res .= '<tr><td class="hicon bathroom"><i class="fa fa-bath"></i></td><td class="bathroom">' . $weather['bathroom_temp'] . ' °C</td><td class="hicon hum bathroom"><i class="fa fa-tint"></i></td><td class="hum bathroom">' . $weather['bathroom_humidity'] . '%</td>';
- $res .= '<td class="sep"></td><td class="hicon cellar"><i class="fa fa-bat"></i></td><td class="cellar">' . $weather['cellar_temp'] . ' °C</td><td class="hicon hum cellar"><i class="fa fa-tint"></i></td><td class="hum cellar">' . $weather['cellar_humidity'] . '%</td></tr>';
- $res .= '</table>';
- $res .= '</div>';
- $res .= '<div class="forecasts">';
- foreach ($weather['forecasts'] as $forecast) {
- $res .= '<div class="forecast">';
- $res .= '<div class="weekday">' . $forecast['day'] . '</div>';
- $res .= '<div class="night">' . accuweatherIcon($forecast['nightIcon']) . '</div>';
- $res .= '<div class="day">' . accuweatherIcon($forecast['dayIcon']) . '</div>';
- $res .= '<div class="temp-min">' . $forecast['min'] . '°C</div>';
- $res .= '<div class="temp-max">' . $forecast['max'] . '°C</div>';
- $res .= '</div>';
- }
- $res .= '</div>';
-
- $res .= '<div class="curves">';
- $res .= _curve($weather, 'sun');
- $res .= _curve($weather, 'moon');
- $res .= '</div>';
- $res .= '</div>';
-
- return $res;
+function weatherStationScreenSaver()
+{
+ $weather = json_decode(file_get_contents(ROOT . '/cache/weather.json'), true);
+
+ $pressureTendency = $weather['pressureTendency'] == 'F' ? 'down' : 'up';
+ $pressure = $weather['outdoor_pressure'] == '--' ? $weather['backyard_pressure'] : $weather['outdoor_pressure'];
+
+ $res = '<div id="weatherstation" class="screensaver">';
+ $res .= '<div class="contents">';
+ $res .= '<div class="time"></div>';
+ $res .= '<div class="current">';
+ $res .= '<div class="icon">' . accuweatherIcon($weather['icon']) . '</div>';
+ $res .= '<div class="icons">';
+ $res .= '<div class="night">' . accuweatherIcon($weather['nightIcon']) . '</div>';
+ $res .= '<div class="day">' . accuweatherIcon($weather['dayIcon']) . '</div>';
+ $res .= '</div>';
+ $res .= '<div class="temps">';
+ $res .= '<div class="temp-min">' . $weather['min'] . '°C</div>';
+ $res .= '<div class="temp"> ' . $weather['outdoor_temp'] . '°C <span style="font-size:20%;"> ' . $weather['temp'] . '°C</span></div>';
+ $res .= '<div class="temp-max">' . $weather['max'] . '°C</div>';
+ $res .= '</div>';
+ $res .= '<div class="pp">';
+ $res .= '<i class="fas fa-cloud-rain"></i> ' . $weather['precipitations24'] . ' mm | <i class="fas fa-tachometer-alt"></i> ' . $pressure . ' hPa <i class="fa fa-arrow-circle-' . $pressureTendency . '"></i> | <i class="fa fa-tint"></i> ' . $weather['outdoor_humidity'] . '%';
+ $res .= '</div>';
+ $res .= '<table class="house">';
+ $res .= '<tr><td class="hicon backyard"><i class="fa fa-flower-tulip"></i></td><td class="backyard">' . $weather['backyard_temp'] . ' °C</td><td class="hicon hum backyard"><i class="fa fa-tint"></i></td><td class="hum backyard">' . $weather['backyard_humidity'] . '%</td>';
+ $res .= '<td class="sep"></td><td class="hicon kitchen"><i class="fa fa-knife-kitchen"></i></td><td class="kitchen">' . $weather['kitchen_temp'] . ' °C</td><td class="hicon hum kitchen"><i class="fa fa-tint"></i></td><td class="hum kitchen">' . $weather['kitchen_humidity'] . '%</td></tr>';
+ $res .= '<tr><td class="hicon livingroom"><i class="fa fa-cocktail"></i></td><td class="livingroom">' . $weather['livingroom_temp'] . ' °C</td><td class="hicon hum livingroom"><i class="fa fa-tint"></i></td><td class="hum livingroom">' . $weather['livingroom_humidity'] . '%</td>';
+ $res .= '<td class="sep"></td><td class="hicon office"><i class="fa fa-plane"></i></td><td class="office">' . $weather['office_temp'] . ' °C</td><td class="hicon hum office"><i class="fa fa-tint"></i></td><td class="hum office">' . $weather['office_humidity'] . '%</td></tr>';
+ $res .= '<tr><td class="hicon wc"><i class="fa fa-toilet"></i></td><td class="wc">' . $weather['wc_temp'] . ' °C</td><td class="hicon hum wc"><i class="fa fa-tint"></i></td><td class="hum wc">' . $weather['wc_humidity'] . '%</td>';
+ $res .= '<td class="sep"></td><td class="hicon bedroom"><i class="fa fa-bed"></i></td><td class="bedroom">' . $weather['bedroom_temp'] . ' °C</td><td class="hicon hum bedroom"><i class="fa fa-tint"></i></td><td class="hum bedroom">' . $weather['bedroom_humidity'] . '%</td>';
+ $res .= '<tr><td class="hicon bathroom"><i class="fa fa-bath"></i></td><td class="bathroom">' . $weather['bathroom_temp'] . ' °C</td><td class="hicon hum bathroom"><i class="fa fa-tint"></i></td><td class="hum bathroom">' . $weather['bathroom_humidity'] . '%</td>';
+ $res .= '<td class="sep"></td><td class="hicon cellar"><i class="fa fa-bat"></i></td><td class="cellar">' . $weather['cellar_temp'] . ' °C</td><td class="hicon hum cellar"><i class="fa fa-tint"></i></td><td class="hum cellar">' . $weather['cellar_humidity'] . '%</td></tr>';
+ $res .= '</table>';
+ $res .= '</div>';
+ $res .= '<div class="forecasts">';
+ foreach ($weather['forecasts'] as $forecast) {
+ $res .= '<div class="forecast">';
+ $res .= '<div class="weekday">' . $forecast['day'] . '</div>';
+ $res .= '<div class="night">' . accuweatherIcon($forecast['nightIcon']) . '</div>';
+ $res .= '<div class="day">' . accuweatherIcon($forecast['dayIcon']) . '</div>';
+ $res .= '<div class="temp-min">' . $forecast['min'] . '°C</div>';
+ $res .= '<div class="temp-max">' . $forecast['max'] . '°C</div>';
+ $res .= '</div>';
+ }
+ $res .= '</div>';
+
+ $res .= '<div class="curves">';
+ $res .= _curve($weather, 'sun');
+ $res .= _curve($weather, 'moon');
+ $res .= '</div>';
+ $res .= '</div>';
+
+ return $res;
}
-function _curve($weather, $curve) {
- $time = time();
-
- if ($curve == 'sun') {
- $set = $weather['sunset'];
- $rise = $weather['sunrise'];
- $icon = '/images/weather/sun.svg';
- $radius = 75;
- $pointXOffset = 44;
- $pointYOffset = 33;
- } else {
- $set = $weather['moonset'];
- $rise = $weather['moonrise'];
- $icon = '/images/weather/moon/' . (round(($weather['moonage'] / 28) * 12) % 12) . '.svg';
- $radius = 50;
- $pointXOffset = 33;
- $pointYOffset = 21;
- }
-
- $diameter = $radius * 2;
-
- $duration = 360 * (($set - $rise) / (3600 * 24));
- $riseAngle = (180 - $duration) / 2;
- $setAngle = $riseAngle + $duration;
-
- //die('d '.$sunduration.';r '.$sunriseAngle.';s '.$sunsetAngle);
-
- $sunrisePos = getPosOnCircle($riseAngle, $radius, $pointXOffset, $pointYOffset);
- $sunsetPos = getPosOnCircle($setAngle, $radius, $pointXOffset, $pointYOffset);
- $sunangle = $riseAngle + (($time - $rise) / (3600 * 24)) * 360;
-
- $res = '<div class="curve curve-' . $curve . '">';
- $res .= '<div class="astre" style="transform: rotate(' . $sunangle . 'deg)"><img src="' . $icon . '" width="20" height="20" style="transform: rotate(' . (-$sunangle) . 'deg)" /></div>';
- if ($curve === 'sun') {
- $res .= '<div class="orbit earth" style="background-image:url(\'/images/earth.png?j=' . filemtime(ROOT . '/images/earth.png') . '\'"></div>';
- } else {
- $res .= '<div class="orbit"></div>';
- }
- $res .= '<div class="horizon" style="top:' . ($sunrisePos['y'] + 3) . 'px;"></div>';
- $res .= '<div class="point rise" style="top:' . $sunrisePos['y'] . 'px;left:' . $sunrisePos['x'] . 'px;"><span>' . date('H:i', $rise) . '</span></div>';
- $res .= '<div class="point set" style="top:' . $sunsetPos['y'] . 'px;left:' . $sunsetPos['x'] . 'px;"><span>' . date('H:i', $set) . '</span></div>';
- $res .= '</div>';
-
- return $res;
+function _curve($weather, $curve)
+{
+ $time = time();
+
+ if ($curve == 'sun') {
+ $set = $weather['sunset'];
+ $rise = $weather['sunrise'];
+ $icon = '/images/weather/sun.svg';
+ $radius = 75;
+ $pointXOffset = 44;
+ $pointYOffset = 33;
+ } else {
+ $set = $weather['moonset'];
+ $rise = $weather['moonrise'];
+ $icon = '/images/weather/moon/' . (round(($weather['moonage'] / 28) * 12) % 12) . '.svg';
+ $radius = 50;
+ $pointXOffset = 33;
+ $pointYOffset = 21;
+ }
+
+ $diameter = $radius * 2;
+
+ $duration = 360 * (($set - $rise) / (3600 * 24));
+ $riseAngle = (180 - $duration) / 2;
+ $setAngle = $riseAngle + $duration;
+
+ //die('d '.$sunduration.';r '.$sunriseAngle.';s '.$sunsetAngle);
+
+ $sunrisePos = getPosOnCircle($riseAngle, $radius, $pointXOffset, $pointYOffset);
+ $sunsetPos = getPosOnCircle($setAngle, $radius, $pointXOffset, $pointYOffset);
+ $sunangle = $riseAngle + (($time - $rise) / (3600 * 24)) * 360;
+
+ $res = '<div class="curve curve-' . $curve . '">';
+ $res .= '<div class="astre" style="transform: rotate(' . $sunangle . 'deg)"><img src="' . $icon . '" width="20" height="20" style="transform: rotate(' . (-$sunangle) . 'deg)" /></div>';
+ if ($curve === 'sun') {
+ $res .= '<div class="orbit earth" style="background-image:url(\'/images/earth.png?j=' . filemtime(ROOT . '/images/earth.png') . '\'"></div>';
+ } else {
+ $res .= '<div class="orbit"></div>';
+ }
+ $res .= '<div class="horizon" style="top:' . ($sunrisePos['y'] + 3) . 'px;"></div>';
+ $res .= '<div class="point rise" style="top:' . $sunrisePos['y'] . 'px;left:' . $sunrisePos['x'] . 'px;"><span>' . date('H:i', $rise) . '</span></div>';
+ $res .= '<div class="point set" style="top:' . $sunsetPos['y'] . 'px;left:' . $sunsetPos['x'] . 'px;"><span>' . date('H:i', $set) . '</span></div>';
+ $res .= '</div>';
+
+ return $res;
}
-function getPosOnCircle($angle, $radius, $x, $y) {
- $angle -= 180;
- $cos = $radius / 2 + (cos(deg2rad($angle)) * $radius);
- $sin = $radius / 2 + (sin(deg2rad($angle)) * $radius);
+function getPosOnCircle($angle, $radius, $x, $y)
+{
+ $angle -= 180;
+ $cos = $radius / 2 + (cos(deg2rad($angle)) * $radius);
+ $sin = $radius / 2 + (sin(deg2rad($angle)) * $radius);
- return ['x' => $x + $cos, 'y' => $y + $sin];
+ return ['x' => $x + $cos, 'y' => $y + $sin];
}
-function accuweatherIcon($icon) {
- return '<img src="/images/weather/' . $icon . '.svg" />';
- // return '<img src="https://www.accuweather.com/images/weathericons/' . $icon . '.svg" />';
+function accuweatherIcon($icon)
+{
+ return '<img src="/images/weather/' . $icon . '.svg" />';
+ // return '<img src="https://www.accuweather.com/images/weathericons/' . $icon . '.svg" />';
}
-function isDay() {
- return getPeriodOfDay()['day'];
+function isDay()
+{
+ return getPeriodOfDay()['day'];
}
-function getPeriodOfDay() {
- $time = new DateTime('now', new DateTimeZone('Europe/Paris'));
- $timestamp = $time->getTimestamp();
- $offset = $time->getOffset() / 3600;
+function getPeriodOfDay()
+{
+ $time = new DateTime('now', new DateTimeZone('Europe/Paris'));
+ $timestamp = $time->getTimestamp();
+ $offset = $time->getOffset() / 3600;
- $hours = intval(date('H'));
+ $hours = intval(date('H'));
- $sunrise = date_sunrise($timestamp, SUNFUNCS_RET_TIMESTAMP, LATITUDE, LONGITUDE, 90, $offset);
- $sunset = date_sunset($timestamp, SUNFUNCS_RET_TIMESTAMP, LATITUDE, LONGITUDE, 90, $offset);
+ $sunrise = date_sunrise($timestamp, SUNFUNCS_RET_TIMESTAMP, LATITUDE, LONGITUDE, 90, $offset);
+ $sunset = date_sunset($timestamp, SUNFUNCS_RET_TIMESTAMP, LATITUDE, LONGITUDE, 90, $offset);
- if ($timestamp > $sunset && $sunrise < $sunset) {
- $sunrise += 3600 * 24;
- }
+ if ($timestamp > $sunset && $sunrise < $sunset) {
+ $sunrise += 3600 * 24;
+ }
- $start_twilight = $sunset - 3600;
- $end_twilight = $sunset + 3600;
+ $start_twilight = $sunset - 3600;
+ $end_twilight = $sunset + 3600;
- $start_dawn = $sunrise - 3600;
- $end_dawn = $sunrise + 3600;
+ $start_dawn = $sunrise - 3600;
+ $end_dawn = $sunrise + 3600;
- $day = !($timestamp < $sunrise || $timestamp >= $sunset);
+ $day = !($timestamp < $sunrise || $timestamp >= $sunset);
- if ($timestamp >= $start_twilight && $timestamp < $end_twilight) {
- $period = 'twilight';
- } else if ($timestamp >= $start_dawn && $timestamp < $end_dawn) {
- $period = 'dawn';
- } else if ($day) {
+ if ($timestamp >= $start_twilight && $timestamp < $end_twilight) {
+ $period = 'twilight';
+ } else if ($timestamp >= $start_dawn && $timestamp < $end_dawn) {
+ $period = 'dawn';
+ } else if ($day) {
- } else {
- $period = 'night';
- }
+ } else {
+ $period = 'night';
+ }
- if ($day) {
- $midday = ($sunset + $sunrise) / 2;
- } else {
+ if ($day) {
+ $midday = ($sunset + $sunrise) / 2;
+ } else {
- }
+ }
+
+ return ['day' => $day, 'period' => $period];
+}
- return ['day' => $day, 'period' => $period];
-}
\ No newline at end of file