From: Vincent Date: Mon, 18 Nov 2019 08:36:35 +0000 (+0100) Subject: . X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=f59fe7df9e1d22877e88b2750c2b2ad3290c523e;p=tortuga-home.git . --- diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4502c7f..15b9b0e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,12 @@ + - + + + + diff --git a/config/global.php b/config/global.php index 6142c32..c70b328 100644 --- a/config/global.php +++ b/config/global.php @@ -10,6 +10,9 @@ define("SQUEEZEBOX_SPOTIFY_PASSWORD", '?Z8}#HK+SZrQ'); define('HUE_BRIDGE', '192.168.13.85'); define('HUE_USER', 'zZigF7nPQq9nTZ3GTB1zkntn98trOJVFHWAwFiqQ'); +define('LATITUDE', 48.8758392); +define('LONGITUDE', 2.3422104); + $squeezeboxPlayers = array( 'Salle de bains' => 'b8:27:eb:ab:b4:50', 'Salon' => 'dc:a6:32:02:47:c1', @@ -28,19 +31,19 @@ $phones = array('vincent' => array( ); $devices = [ - 'cerveau' => ['id'=>'cerveau','host' => '192.168.13.60', 'user' => 'pi', 'password' => 'atacama'], - 'litvincent' => ['id'=>'litvincent','host' => '192.168.13.61', 'user' => 'pi', 'password' => 'atacama'], - 'litjerome' => ['id'=>'litjerome','host' => '192.168.13.62', 'user' => 'pi', 'password' => 'atacama'], - 'sdb' => ['id'=>'sdb','host' => '192.168.13.63', 'user' => 'pi', 'password' => 'atacama'], - 'entree' => ['id'=>'entree','host' => '192.168.13.64', 'user' => 'pi', 'password' => 'atacama'], - 'jarvis' => ['id'=>'jarvis','host' => '192.168.13.60', 'user' => 'jarvis', 'password' => 'atacama'], - 'minitel1' => ['id'=>'minitel1','host' => '192.168.13.65', 'user' => 'pi', 'password' => 'atacama'], - 'salon' => ['id'=>'salon','host' => '192.168.13.66', 'user' => 'pi', 'password' => 'atacama'], - 'bureau' => ['id'=>'bureau','host' => '192.168.13.67', 'user' => 'pi', 'password' => 'atacama'], - 'cuisine' => ['id'=>'cuisine','host' => '192.168.13.68', 'user' => 'pi', 'password' => 'atacama'], - 'bureausun' => ['id'=>'bureausun','host' => '192.168.13.70', 'user' => 'pi', 'password' => 'atacama'], - 'lit' => ['id'=>'lit','host' => '192.168.13.71', 'user' => 'pi', 'password' => 'atacama'], - 'avion' => ['id'=>'avion','host' => '192.168.13.5', 'user' => 'Tortuga', 'password' => 's77vpo*wu', 'mac' => 'E0:D5:5E:68:67:B9'], + 'cerveau' => ['id' => 'cerveau', 'host' => '192.168.13.60', 'user' => 'pi', 'password' => 'atacama'], + 'litvincent' => ['id' => 'litvincent', 'host' => '192.168.13.61', 'user' => 'pi', 'password' => 'atacama'], + 'litjerome' => ['id' => 'litjerome', 'host' => '192.168.13.62', 'user' => 'pi', 'password' => 'atacama'], + 'sdb' => ['id' => 'sdb', 'host' => '192.168.13.63', 'user' => 'pi', 'password' => 'atacama'], + 'entree' => ['id' => 'entree', 'host' => '192.168.13.64', 'user' => 'pi', 'password' => 'atacama'], + 'jarvis' => ['id' => 'jarvis', 'host' => '192.168.13.60', 'user' => 'jarvis', 'password' => 'atacama'], + 'minitel1' => ['id' => 'minitel1', 'host' => '192.168.13.65', 'user' => 'pi', 'password' => 'atacama'], + 'salon' => ['id' => 'salon', 'host' => '192.168.13.66', 'user' => 'pi', 'password' => 'atacama'], + 'bureau' => ['id' => 'bureau', 'host' => '192.168.13.67', 'user' => 'pi', 'password' => 'atacama'], + 'cuisine' => ['id' => 'cuisine', 'host' => '192.168.13.68', 'user' => 'pi', 'password' => 'atacama'], + 'bureausun' => ['id' => 'bureausun', 'host' => '192.168.13.70', 'user' => 'pi', 'password' => 'atacama'], + 'lit' => ['id' => 'lit', 'host' => '192.168.13.71', 'user' => 'pi', 'password' => 'atacama'], + 'avion' => ['id' => 'avion', 'host' => '192.168.13.5', 'user' => 'Tortuga', 'password' => 's77vpo*wu', 'mac' => 'E0:D5:5E:68:67:B9'], ]; // Browse media files on NAS diff --git a/scripts/cron/cron.php b/scripts/cron/cron.php index aa422df..b2ac249 100644 --- a/scripts/cron/cron.php +++ b/scripts/cron/cron.php @@ -11,6 +11,7 @@ function cronOneLoop($cronmin) if ($cronmin % 5 == 0) { cronTraffic($cronmin, false); cronVelib($cronmin); + cronBackyard($cronmin); } if ($cronmin % 10 == 0) { cronWeather($cronmin); @@ -55,7 +56,7 @@ function cronEcoMode($cronmin) function cronTranscode($cronmin) { - httpRequest('https://home.tortuga.enhydra.fr/scripts/transcode.php','get',[],null,10,true); + httpRequest('https://home.tortuga.enhydra.fr/scripts/transcode.php', 'get', [], null, 10, true); } function cronRooms($cronmin) @@ -69,6 +70,15 @@ function cronRooms($cronmin) checkPlanetarium(); } +function cronBackyard($cronmin) +{ + if (isDay()) { + domoticzSwitch(679,true); + } else { + domoticzSwitch(679,false); + } +} + function cronMediaLibrary($cronmin) { global $directories; diff --git a/scripts/day.php b/scripts/day.php new file mode 100644 index 0000000..5f01891 --- /dev/null +++ b/scripts/day.php @@ -0,0 +1,3 @@ + 'insteon', 'command' => '0?1131=I=0=0'], ['type' => 'hue', 'group' => $chambrebedgroup, 'scene' => 'JNieZpDHu5fbMyf'], ['type' => 'scene', 'scene' => 'sdb/nuit'], - ['type' => 'function', 'function' => 'bedbrightness', 'args' => [$bedlowscreenbrightness]], + ['type' => 'function', 'function' => 'bedbrightness', 'args' => [$bedlowscreenbrightness]], ['type' => 'scene', 'scene' => 'chambre/cheminee'], ['type' => 'scene', 'scene' => 'chambre/planetarium/on'], // Planétarium on - ['type' => 'scene', 'scene' => 'chambre/deshumidificateur/off'], +// ['type' => 'scene', 'scene' => 'chambre/deshumidificateur/off'], ['type' => 'scene', 'scene' => 'chambre/raspberry/off'], ['type' => 'phonetask', 'phone' => 'vincent', 'task' => 'Va Au Lit'], ], @@ -463,11 +463,11 @@ $scenes = [ ['type' => 'function', 'function' => 'stopHarmony'], ['type' => 'function', 'function' => 'stopAllSqueezebox'], ['type' => 'function', 'function' => 'offAllOMX'], - ['type' => 'scene', 'scene' => 'chambre/deshumidificateur/on'], +// ['type' => 'scene', 'scene' => 'chambre/deshumidificateur/on'], ['type' => 'phonetask', 'phone' => 'vincent', 'task' => 'Stop All Sounds'], ['type' => 'scene', 'scene' => 'chambre/planetarium/off'], ['type' => 'ifttt', 'event' => 'coffee_off'], - ['type' => 'ifttt', 'event' => 'oven_off'], + //['type' => 'ifttt', 'event' => 'oven_off'], ], 'home/welcome' => [ ['type' => 'ecomode', 'mode' => '0'], @@ -521,12 +521,12 @@ $scenes = [ ], 'sdb/off' => [ ['type' => 'state', 'key' => 'sdb', 'value' => 0], - ['type' => 'hue', 'group' => $sdb, 'scene' => ['on' => false, 'brightness' => 0, 'effect' => 'none']], - ['type' => 'function', 'function' => 'stopSqueezeboxPlayer', 'args' => [$squeezeboxPlayers['WC'], false]], + ['type' => 'hue', 'group' => $sdb, 'scene' => ['on' => false]], + ['type' => 'function', 'function' => 'stopSqueezeboxPlayer', 'args' => [$squeezeboxPlayers['Salle de bains'], false]], ], 'sdb/on' => [ ['type' => 'state', 'key' => 'sdb', 'value' => 1], - ['type' => 'hue', 'group' => $sdb, 'scene' => ['effect' => 'none']], + // ['type' => 'hue', 'group' => $sdb, 'scene' => ['effect' => 'none']], ['type' => 'hue', 'group' => $sdb, 'scene' => '0L4cGh7y29uBBez'], ], 'sdb/morning' => [ @@ -536,7 +536,7 @@ $scenes = [ ], 'sdb/nuit' => [ ['type' => 'state', 'key' => 'sdb', 'value' => 1], - ['type' => 'hue', 'group' => $sdb, 'scene' => ['effect' => 'none']], + //['type' => 'hue', 'group' => $sdb, 'scene' => ['effect' => 'none']], ['type' => 'hue', 'group' => $sdb, 'scene' => 'ZTZBNRk6VZMlYvB'], ], 'sdb/spa' => [ @@ -562,7 +562,7 @@ $scenes = [ ['type' => 'domoticz', 'device' => '1', 'switchtype' => 'scene', 'command' => false], ], 'ecomode/notsuper' => [ - ['type' => 'domoticz', 'device' => '1', 'switchtype' => 'scene', 'command' => true, 'priority' => false], + ['type' => 'domoticz', 'device' => '1', 'switchtype' => 'scene', 'command' => true], ], 'ecomode/on' => [ ['type' => 'scene', 'scene' => 'ecomode/basic'], diff --git a/scripts/lib/weatherstation.php b/scripts/lib/weatherstation.php index bde83c8..40525fe 100644 --- a/scripts/lib/weatherstation.php +++ b/scripts/lib/weatherstation.php @@ -1,100 +1,117 @@ '; - $res .= '
'; - $res .= '
'; - $res .= '
' . accuweatherIcon($weather['icon']) . '
'; - $res .= '
'; - $res .= '
' . accuweatherIcon($weather['nightIcon']) . '
'; - $res .= '
' . accuweatherIcon($weather['dayIcon']) . '
'; - $res .= '
'; - $res .= '
'; - $res .= '
' . $weather['min'] . '°C
'; - $res .= '
' . $weather['temp'] . '°C
'; - $res .= '
' . $weather['max'] . '°C
'; - $res .= '
'; - $res .= '
' . $weather['precipitations24'] . ' mm | ' . $weather['pressure'] . ' hPa
'; - $res .= '
'; - $res .= '
'; - foreach ($weather['forecasts'] as $forecast) { - $res .= '
'; - $res .= '
' . $forecast['day'] . '
'; - $res .= '
' . accuweatherIcon($forecast['nightIcon']) . '
'; - $res .= '
' . accuweatherIcon($forecast['dayIcon']) . '
'; - $res .= '
' . $forecast['min'] . '°C
'; - $res .= '
' . $forecast['max'] . '°C
'; - $res .= '
'; - } - $res .= '
'; - - $res .= '
'; - $res .= _curve($weather, 'sun'); - $res .= _curve($weather, 'moon'); - $res .= '
'; - - - $res .= ''; - return $res; + $weather = json_decode(file_get_contents(ROOT . '/cache/weather.json'), true); + + $pressureTendency = $weather['pressureTendency'] == 'F' ? 'down' : 'up'; + + $res = '
'; + $res .= '
'; + $res .= '
'; + $res .= '
' . accuweatherIcon($weather['icon']) . '
'; + $res .= '
'; + $res .= '
' . accuweatherIcon($weather['nightIcon']) . '
'; + $res .= '
' . accuweatherIcon($weather['dayIcon']) . '
'; + $res .= '
'; + $res .= '
'; + $res .= '
' . $weather['min'] . '°C
'; + $res .= '
' . $weather['temp'] . '°C
'; + $res .= '
' . $weather['max'] . '°C
'; + $res .= '
'; + $res .= '
' . $weather['precipitations24'] . ' mm | ' . $weather['pressure'] . ' hPa
'; + $res .= '
'; + $res .= '
'; + foreach ($weather['forecasts'] as $forecast) { + $res .= '
'; + $res .= '
' . $forecast['day'] . '
'; + $res .= '
' . accuweatherIcon($forecast['nightIcon']) . '
'; + $res .= '
' . accuweatherIcon($forecast['dayIcon']) . '
'; + $res .= '
' . $forecast['min'] . '°C
'; + $res .= '
' . $forecast['max'] . '°C
'; + $res .= '
'; + } + $res .= '
'; + + $res .= '
'; + $res .= _curve($weather, 'sun'); + $res .= _curve($weather, 'moon'); + $res .= '
'; + + + $res .= '
'; + 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 = '
'; - $res .= '
'; - $res .= '
'; - $res .= '
'; - $res .= '
' . date('H:i', $rise) . '
'; - $res .= '
' . date('H:i', $set) . '
'; - $res .= '
'; - - return $res; + $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 = '
'; + $res .= '
'; + $res .= '
'; + $res .= '
'; + $res .= '
' . date('H:i', $rise) . '
'; + $res .= '
' . date('H:i', $set) . '
'; + $res .= '
'; + + return $res; } function getPosOnCircle($angle, $radius, $x, $y) { - $angle -= 180; - $cos = $radius / 2 + (cos(deg2rad($angle)) * $radius); - $sin = $radius / 2 + (sin(deg2rad($angle)) * $radius); + $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 ''; + return ''; +} + +function isDay() +{ + $time = time(); + + $sunrise = date_sunrise($time, SUNFUNCS_RET_TIMESTAMP, LATITUDE, LONGITUDE); + $sunset = date_sunset($time, SUNFUNCS_RET_TIMESTAMP, LATITUDE, LONGITUDE); + + if ($time > $sunset && $sunrise < $sunset) { + $sunrise += 3600 * 24; + } + + if ($time < $sunrise || $time > $sunset) { + return false; + } + return true; } \ No newline at end of file