From: Vincent Vanwaelscappel Date: Tue, 4 Jul 2023 09:25:45 +0000 (+0200) Subject: . X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=b159552a724acf987ce8d1957f8dc94fbeb24b7f;p=tortuga-home.git . --- diff --git a/.docker/config/httpd/httpd.conf b/.docker/config/httpd/httpd.conf index 36ef7e9..9956ab2 100644 --- a/.docker/config/httpd/httpd.conf +++ b/.docker/config/httpd/httpd.conf @@ -297,7 +297,7 @@ RemoteIPInternalProxy nginx-proxy - Require ip 127.0.0.0/8 192.168.13.0/24 172.0.0.0/8 + Require ip 127.0.0.0/8 192.168.0.0/16 172.0.0.0/8 diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml index 2427b23..8edb0f6 100644 --- a/.idea/dataSources.local.xml +++ b/.idea/dataSources.local.xml @@ -1,6 +1,6 @@ - + " diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3f18f3d..7cce9f2 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,12 +5,19 @@ + + + + - - + + + + + - { - "keyToString": { - "RunOnceActivity.OpenProjectViewOnStart": "true", - "RunOnceActivity.ShowReadmeOnStart": "true", - "WebServerToolWindowFactoryState": "true", - "WebServerToolWindowPanel.toolwindow.highlight.mappings": "true", - "WebServerToolWindowPanel.toolwindow.highlight.symlinks": "true", - "WebServerToolWindowPanel.toolwindow.show.date": "false", - "WebServerToolWindowPanel.toolwindow.show.permissions": "false", - "WebServerToolWindowPanel.toolwindow.show.size": "false", - "deletionFromPopupRequiresConfirmation": "false", - "git-widget-placeholder": "master", - "ignore.virus.scanning.warn.message": "true", - "last_opened_file_path": "D:/Works/tortuga-home/node_modules", - "node.js.detected.package.eslint": "true", - "node.js.detected.package.tslint": "true", - "node.js.selected.package.eslint": "(autodetect)", - "node.js.selected.package.tslint": "(autodetect)", - "nodejs_package_manager_path": "npm", - "project.structure.last.edited": "Project", - "project.structure.proportion": "0.0", - "project.structure.side.proportion": "0.2", - "ruby.rails.projectView.checked": "true", - "settings.editor.selected.configurable": "editor.preferences.fonts.default", - "vue.rearranger.settings.migration": "true" + +}]]> + - @@ -1213,14 +1220,12 @@ - - - - 1641578230504 - 1641726946298 @@ -1558,7 +1563,14 @@ - @@ -1593,7 +1605,7 @@ file://$PROJECT_DIR$/scripts/lib/lib.php - 97 + 98 diff --git a/config/dnsmasq.conf b/config/dnsmasq.conf index 68721dd..bc9815a 100644 --- a/config/dnsmasq.conf +++ b/config/dnsmasq.conf @@ -17,4 +17,6 @@ address=/potainersalon.home.tortuga.enhydra.fr/192.168.13.66 address=/transmission.home.tortuga.enhydra.fr/192.168.13.7 address=/paperless.home.tortuga.enhydra.fr/192.168.13.7 address=/piwigo.home.tortuga.enhydra.fr/192.168.13.7 -address=/dockerbackup.home.tortuga.enhydra.fr/192.168.13.70 \ No newline at end of file +address=/dockerbackup.home.tortuga.enhydra.fr/192.168.13.70 +address=/zigbee2mqtt.home.tortuga.enhydra.fr/192.168.13.70 +address=/homeassistant.home.tortuga.enhydra.fr/192.168.13.8 \ No newline at end of file diff --git a/scripts/cron/cron.php b/scripts/cron/cron.php index 129243d..4c2b322 100644 --- a/scripts/cron/cron.php +++ b/scripts/cron/cron.php @@ -294,12 +294,6 @@ function cronHarmony($cronmin) } else if ($currentActivity == 'poweroff' || $currentActivity == 'off') { setPlaying('mycanal', 'bureau'); } - -// if ($currentActivity === 'poweroff' || $currentActivity === 'off' || $currentActivity === 'musique') { -// harmonyDeviceCommand('sony-projecteur', 'power-off'); -// } else { -// harmonyDeviceCommand('sony-projecteur', 'power-on'); -// } } function cronHeartbeat($cronmin, $devices = false) diff --git a/scripts/domoticz_device_event.php b/scripts/domoticz_device_event.php index c7af342..df53b15 100644 --- a/scripts/domoticz_device_event.php +++ b/scripts/domoticz_device_event.php @@ -3,171 +3,128 @@ define('TIMELIMIT', 1); $_GET['im'] = '5'; -$wcswitch = 6448; +$wcswitch = [6448, 6894, 6895]; $cubesalon = [6844, 6846, 6848]; $bar = 6890; $device = (int)$_GET['device']; if (in_array($device, $cubesalon)) { - $forceConfig = 'salon'; + $forceConfig = 'salon'; } elseif ($device == $wcswitch) { - $forceConfig = 'wc'; + $forceConfig = 'wc'; } elseif ($device == 4600) { - $forceConfig = 'bureau'; + $forceConfig = 'bureau'; } elseif ($device == 4711) { - $forceConfig = 'sdb'; + $forceConfig = 'sdb'; } else if ($device == $bar) { - $forceConfig = 'salon'; -} else if ($device == 6894) { - $forceConfig = 'cour'; -} else if ($device == 6895) { - $forceConfig = 'cour'; + $forceConfig = 'salon'; } +//} else if ($device == 6894) { +// $forceConfig = 'cour'; +//} else if ($device == 6895) { +// $forceConfig = 'cour'; +//} require_once "import.php"; -if ($device === 6894) { - domoticzCmd(6898, 'Toggle'); -} elseif ($device == 6895) { - domoticzCmd(6899, 'Toggle'); -} elseif ($device == $bar) { - execScene('salon/bar/' . mb_strtolower($_GET['state'])); +//if ($device === 6894) { +// domoticzCmd(6898, 'Toggle'); +//} elseif ($device == 6895) { +// domoticzCmd(6899, 'Toggle'); +//} else + if ($device == $bar) { + execScene('salon/bar/' . mb_strtolower($_GET['state'])); } elseif ($device == 480) { - chambreToggle(true); + chambreToggle(true); } else if (in_array($device, $cubesalon)) { - // Cube - if (gloria()) { - die('0'); - } - switch ($_GET['state']) { - case 'Shake': - execScene('home/alert', true); - break; - case 'Flip_90': - execScene('salon/cinema', true); - break; - case 'Flip_180': - execScene('salon/auto', true); - break; - case 'Free_Fall': - off('salon'); - break; - case 'Move': - _remoteCmd('pause', 'salon'); - break; - case 'Clock_Wise': - volume(config('VOLUME_STEP'), '+'); - break; - case 'Anti_Clock_Wise': - volume(config('VOLUME_STEP'), '-'); - break; - case 'Tap': - squeezePlayByName('FIP', $squeezeboxPlayers['Salon']); - break; - case 'Alert': - default: - break; - } + // Cube + if (gloria()) { + die('0'); + } + switch ($_GET['state']) { + case 'Shake': + execScene('home/alert', true); + break; + case 'Flip_90': + execScene('salon/cinema', true); + break; + case 'Flip_180': + execScene('salon/auto', true); + break; + case 'Free_Fall': + off('salon'); + break; + case 'Move': + _remoteCmd('pause', 'salon'); + break; + case 'Clock_Wise': + volume(config('VOLUME_STEP'), '+'); + break; + case 'Anti_Clock_Wise': + volume(config('VOLUME_STEP'), '-'); + break; + case 'Tap': + squeezePlayByName('FIP', $squeezeboxPlayers['Salon']); + break; + case 'Alert': + default: + break; + } } else if ($device == 1451) { - domoticzSwitch(1450); -} else if ($device == $wcswitch) { - $forceConfig = 'wc'; - switch ($_GET['state']) { - case 'Double_Click': - execScene('wc/spa', true); - setState('wc', 1); - break; - case 'Long_Click': - if (isJerome(false) && isVincent()) { - execScene('home/alert', true); - } else { - wcToggle(); - } - break; - case 'Click': - default: - wcToggle(); - break; - } -} else if ($device == 4600) { - if (gloria()) { - die('0'); - } - // Cube bureau - switch ($_GET['state']) { - case 'Shake': - execScene('home/alert', true); - break; - case 'Flip_90': - execScene('bureau/rideaux/toggle', true); - break; - case 'Flip_180': - execScene('bureau/auto', true); - break; - case 'Free_Fall': - execScene('bureau/off', true); - off('bureau'); - break; - case 'Move': - if (getCurrentHarmonyActivity() === 'tv') { - _remoteCmd('pause', 'bureau'); - } else { - stopPlayersIn('bureau'); - stopHarmony(); - } - break; - case 'Clock_Wise': - volume(config('VOLUME_STEP'), '+',); - break; - case 'Anti_Clock_Wise': - volume(config('VOLUME_STEP'), '-'); - break; - case 'Tap': - harmonyActivity('musique'); - $lastTap = getState('bureau_squeeze_tap', 0); - $musics = ['FIP', 'Samba']; - $i = ($lastTap + 1) % count($musics); - setState('bureau_squeeze_tap', $i); - squeezePlayByName($musics[$i], 'Bureau'); - break; - case 'Alert': - default: - break; - } + domoticzSwitch(1450); +} else if (in_array($device, $wcswitch)) { + $forceConfig = 'wc'; + switch ($_GET['state']) { + case 'Double_Click': + execScene('wc/spa', true); + setState('wc', 1); + break; + case 'Long_Click': + if (isJerome(false) && isVincent()) { + execScene('home/alert', true); + } else { + wcToggle(); + } + break; + case 'Click': + default: + wcToggle(); + break; + } } else if ($device == 4711) { - if (gloria()) { - die('0'); - } - // Cube SDB - switch ($_GET['state']) { - case 'Shake': - execScene('home/alert', true); - break; - case 'Flip_90': - execScene('sdb/off', true); - break; - case 'Flip_180': - execScene('sdb/on', true); - break; - case 'Free_Fall': - off('sdb'); - break; - case 'Move': - //_remoteCmd('pause', 'salon'); - break; - case 'Clock_Wise': - volume(config('VOLUME_STEP'), '+'); - break; - case 'Anti_Clock_Wise': - volume(config('VOLUME_STEP'), '-'); - break; - case 'Tap': - squeezePlayByName('FIP', $squeezeboxPlayers['Salle de bains']); - break; - case 'Alert': - default: - break; - } + if (gloria()) { + die('0'); + } + // Cube SDB + switch ($_GET['state']) { + case 'Shake': + execScene('home/alert', true); + break; + case 'Flip_90': + execScene('sdb/off', true); + break; + case 'Flip_180': + execScene('sdb/on', true); + break; + case 'Free_Fall': + off('sdb'); + break; + case 'Move': + //_remoteCmd('pause', 'salon'); + break; + case 'Clock_Wise': + volume(config('VOLUME_STEP'), '+'); + break; + case 'Anti_Clock_Wise': + volume(config('VOLUME_STEP'), '-'); + break; + case 'Tap': + squeezePlayByName('FIP', $squeezeboxPlayers['Salle de bains']); + break; + case 'Alert': + default: + break; + } } echo '1'; \ No newline at end of file diff --git a/scripts/homeassistant.php b/scripts/homeassistant.php new file mode 100644 index 0000000..1902707 --- /dev/null +++ b/scripts/homeassistant.php @@ -0,0 +1,7 @@ +setMethod($method); - $harmonyClient->setUri($uri); - $harmonyClient->setOptions(['timeout' => 60]); - try { - $response = $harmonyClient->send(); - $res = json_decode($response->getBody(), true); - if (!$res) { - return $response->getBody(); - } - return $res; - } catch (Exception $e) { - return $e->getMessage(); - } -} - -function harmonyActivity($activity) -{ - if ($activity == 'poweroff' || $activity == 'off') { - setPlaying('mycanal', 'bureau'); - } - $wait = 0; - $current = getCurrentHarmonyActivity(); - if ($current == 'off' || $current == 'poweroff' || !$current) { - if ($activity == 'tv') { - $wait = 10; - } - } - if ($activity !== 'off' && $activity !== 'poweroff') { - ecoMode('0'); - } - if ($activity === 'tv') { - shieldWakeup('bureau'); - } - $res = harmonyRequest('activities/' . $activity, 'POST'); - $map = ['musique' => 2200, 'tv' => 2199, 'off' => 2198]; - domoticzSwitch($map[$activity], true, 'light', false); - if ($wait > 0) { - sleep($wait); - } - if ($activity == 'tv') { - runAtEnd('sleep(15);harmonyDeviceCommand(\'sony-projecteur\', \'power-on\');'); - } - return $res; +$harmonymap = ['musique' => 'Musique', 'tv' => 'TV', 'switch' => 'Switch', 'poweroff' => 'Power Off']; +function harmonyActivity($activity) { + global $harmonymap; + if($activity=='off'){ + $activity='poweroff'; + } + if ($activity == 'poweroff' ) { + setPlaying('mycanal', 'bureau'); + } + $wait = 0; + $current = getCurrentHarmonyActivity(); + if ($current == 'poweroff' || !$current) { + if ($activity == 'tv') { + $wait = 10; + } + } + if ($activity !== 'poweroff') { + ecoMode('0'); + } + if ($activity === 'tv') { + shieldWakeup('bureau'); + } + + + haAction("select.bureau_activities", $harmonymap[$activity]); + if ($wait > 0) { + sleep($wait); + } + if ($activity == 'tv') { + runAtEnd('sleep(15);harmonyDeviceCommand(\'sony-projecteur\', \'power-on\');'); + } } -function getCurrentHarmonyActivity() -{ - $status = harmonyRequest('status'); - if (is_string($status)) { - return false; - } - return $status['current_activity']['slug']; +function getCurrentHarmonyActivity() { + global $harmonymap; + $a = haGetState('select.bureau_activities'); + if (in_array($a, $harmonymap)) { + return array_search($a, $harmonymap); + } + return false; } -function stopHarmony() -{ - $res = harmonyRequest('off', 'PUT'); - domoticzSwitch(2198, true, 'light', false); - return $res; +function stopHarmony() { + harmonyActivity('off'); } -function harmonyDeviceCommand($device, $command) -{ - return harmonyRequest('devices/' . $device . '/commands/' . $command, 'POST'); +function harmonyDeviceCommand($device, $command) { + haEvent(); + return harmonyRequest('devices/' . $device . '/commands/' . $command, 'POST'); } \ No newline at end of file diff --git a/scripts/lib/homeassistant.php b/scripts/lib/homeassistant.php new file mode 100644 index 0000000..0833bb4 --- /dev/null +++ b/scripts/lib/homeassistant.php @@ -0,0 +1,61 @@ + [ + "method" => "GET", + "header" => + "Content-Type: application/json\r\n" . + "Authorization: Bearer " . HA_KEY . "\r\n" + ] + ]; + $ctx = stream_context_create($opts); + $data = @file_get_contents(HA_URL . 'api/states/' . $id, false, $ctx); + if (!$data) + return false; + $data = json_decode($data); + if (!$data) + return false; + if (!isset($data->state)) + return false; + return $data->state; +} + +function haAction($id, $action='turn_on', $domain = null) { + $opts = [ + "http" => [ + "method" => "POST", + 'content' => json_encode(['entity_id' => $id]), + "header" => + "Content-Type: application/json\r\n" . + "Authorization: Bearer " . HA_KEY . "\r\n" + ] + ]; + + if (null === $domain) { + $e = explode('.', $id); + $domain = $e[0]; + } + + $ctx = stream_context_create($opts); + $data = @file_get_contents(HA_URL . 'api/services/' . $domain . '/' . $action, false, $ctx); + if (!$data) + return false; + $data = json_decode($data); + if (!$data) + return false; + if (!isset($data->state)) + return false; + return [$data->state, $data->last_updated]; +} diff --git a/scripts/lib/lib.php b/scripts/lib/lib.php index 4089440..df9237d 100644 --- a/scripts/lib/lib.php +++ b/scripts/lib/lib.php @@ -10,6 +10,7 @@ require_once ROOT . '/vendor/autoload.php'; require_once ROOT . '/scripts/lib/profile.php'; require_once ROOT . "/config/global.php"; require_once ROOT . '/config/rooms.php'; +require_once ROOT . '/scripts/lib/homeassistant.php'; require_once ROOT . '/scripts/lib/redis.php'; require_once ROOT . '/scripts/lib/state.php'; require_once ROOT . '/scripts/lib/hue.php'; @@ -465,19 +466,10 @@ function volume($volume, $increase = '', $device = null) { case 'squeezebox': return squeezeVolume($volume, $increase, config('SQUEEZEBOX_PLAYER')); case 'harmony': - $lastHarmonyVolume = min(time(), getState('last_harmony_volume', 0)); - $limit = time() - 2; - if ($lastHarmonyVolume > $limit) { - return; - } - setState('last_harmony_volume', time()); - - $volume = min(5, max(1, $volume)); - if ($increase == '-') { - return harmonyRequest('commands/volume-down?repeat=' . $volume, 'POST'); + return haAction('script.bureau_volume_down'); } else { - return harmonyRequest('commands/volume-up?repeat=' . $volume, 'POST'); + return haAction('script.bureau_volume_up'); } case 'vlc': return VLCCmd(['command' => 'volume', 'val' => $increase . '20'], $device); diff --git a/scripts/lib/scenes.php b/scripts/lib/scenes.php index 703ca36..7f6280a 100644 --- a/scripts/lib/scenes.php +++ b/scripts/lib/scenes.php @@ -21,7 +21,6 @@ $home = 15; $alert = 16; $chambrefan = 6952; -$amplisdb = 6956; $bar = 6985; $scenes = [ @@ -340,13 +339,13 @@ $scenes = [ ['type' => 'function', 'function' => 'salonAuto', 'args' => [true]], ], 'salon/bar/on' => [ - ['type' => 'domoticz', 'device' => $bar, 'command' => true, 'priority' => true], + ['type' => 'ha', 'device' => HA_BAR, 'command' => 'turn_on', 'priority' => true], ], 'salon/bar/off' => [ - ['type' => 'domoticz', 'device' => $bar, 'command' => false, 'priority' => true], + ['type' => 'ha', 'device' => HA_BAR, 'command' => 'turn_off', 'priority' => true], ], 'salon/bar/toggle' => [ - ['type' => 'domoticz', 'device' => $bar, 'command' => 'Toggle', 'priority' => true], + ['type' => 'ha', 'device' => HA_BAR, 'command' => 'toggle', 'priority' => true], ], 'salon/day' => [ ['type' => 'domoticz', 'scene' => 45, 'command' => true, 'priority' => true], @@ -768,13 +767,15 @@ $scenes = [ ['type' => 'function', 'function' => 'wcVMCOn'], ], 'wc/vmc/off' => [ - ['type' => 'domoticz', 'device' => '6449', 'command' => false, 'priority' => true], + ['type' => 'ha', 'device' => HA_WC_VMC, 'command' => 'turn_off', 'priority' => true], ], 'sdb/ampli/on' => [ - ['type' => 'domoticz', 'device' => $amplisdb, 'command' => true, 'priority' => true], + ['type' => 'ha', 'device' => HA_SDB_AMPLI, 'command' => 'turn_on', 'priority' => true], + //['type' => 'domoticz', 'device' => $amplisdb, 'command' => true, 'priority' => true], ], 'sdb/ampli/off' => [ - ['type' => 'domoticz', 'device' => $amplisdb, 'command' => false, 'priority' => true], + ['type' => 'ha', 'device' => HA_SDB_AMPLI, 'command' => 'turn_off', 'priority' => true], + //['type' => 'domoticz', 'device' => $amplisdb, 'command' => false, 'priority' => true], ], 'sdb/hotwater/auto' => [ ['type' => 'function', 'function' => 'hotwaterAutoMode', 'args' => ['1']], @@ -825,10 +826,10 @@ $scenes = [ ['type' => 'domoticz', 'device' => '1439', 'command' => false], ], 'cuisine/hotte/on' => [ - ['type' => 'domoticz', 'scene' => 52, 'command' => true], + ['type' => 'ha', 'device' => HA_HOTTE, 'command' => 'turn_on'], ], 'cuisine/hotte/off' => [ - ['type' => 'domoticz', 'scene' => 52, 'command' => false], + ['type' => 'ha', 'device' => HA_HOTTE, 'command' => 'turn_off'], ], 'cuisine/base/on' => [ ['type' => 'hue', 'group' => $cuisine, 'scene' => 'UDlNCnVQjTHZJFF'], @@ -892,14 +893,14 @@ $scenes = [ ['type' => 'domoticz', 'device' => '6898', 'command' => false], ], 'ecomode/basic' => [ - ['type' => 'domoticz', 'device' => '1', 'switchtype' => 'scene', 'command' => false], + ['type' => 'ha', 'device' => HA_ECO_BASIC, 'command' => 'turn_off'], ], 'ecomode/super' => [ ['type' => 'scene', 'scene' => 'ecomode/basic'], - ['type' => 'domoticz', 'device' => '2', 'switchtype' => 'scene', 'command' => false], + ['type' => 'ha', 'device' => HA_ECO_SUPER, 'command' => 'turn_off'], ], 'ecomode/notsuper' => [ - ['type' => 'domoticz', 'device' => '2', 'switchtype' => 'scene', 'command' => true], + ['type' => 'ha', 'device' => HA_ECO_SUPER, 'command' => 'turn_on'], ], 'ecomode/on' => [ ['type' => 'scene', 'scene' => 'ecomode/basic'], @@ -907,7 +908,7 @@ $scenes = [ ], 'ecomode/off' => [ ['type' => 'scene', 'scene' => 'ecomode/notsuper'], - ['type' => 'domoticz', 'device' => '1', 'switchtype' => 'scene', 'command' => true, 'priority' => false], + ['type' => 'ha', 'device' => HA_ECO_BASIC, 'command' => 'turn_on'], ], ]; @@ -1007,6 +1008,8 @@ function execScene($name, $fromUserAction = false, $transitionTime = null) { $action['switchtype'] = 'scene'; } domoticzSwitch($action['device'], $action['command'], isset($action['switchtype']) ? $action['switchtype'] : 'light', $action['priority'] ?? false); + } else if ($action['type'] === 'ha') { + haAction($action['device'], $action['command']); } else if ($action['type'] == 'ir') { irsend($action['room'], $action['device'], $action['command']); } else if ($action['type'] == 'ifttt') { @@ -1328,7 +1331,8 @@ function updateCourAuto() { function wcVMCOn() { setState('lastVMCOn', time()); // Start VMC - domoticzSwitch(6449, true, 'light', true); + haAction(HA_WC_VMC, 'turn_on'); + //domoticzSwitch(6449, true, 'light', true); } function wcVMCOff($timeout = 'auto') { diff --git a/scripts/lib/weatherstation.php b/scripts/lib/weatherstation.php index 0a241b3..c31d09c 100644 --- a/scripts/lib/weatherstation.php +++ b/scripts/lib/weatherstation.php @@ -1,263 +1,256 @@ '; - $res .= '
'; - $res .= '
'; - $res .= '
'; - $res .= '
' . accuweatherIcon($weather['icon']) . '
'; - $res .= '
'; - $res .= '
' . accuweatherIcon($weather['nightIcon']) . '
'; - $res .= '
' . accuweatherIcon($weather['dayIcon']) . '
'; - $res .= '
'; - $res .= '
'; - $res .= '
' . $weather['min'] . '°C
'; - $res .= '
' . $weather['outdoor_temp'] . '°C ' . $weather['temp'] . '°C
'; - $res .= '
' . $weather['max'] . '°C
'; - $res .= '
'; - $res .= '
'; - $res .= ' ' . $weather['precipitations24'] . ' mm | ' . $pressure . ' hPa | ' . $weather['outdoor_humidity'] . '%'; - $res .= '
'; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= ''; - $res .= '
' . $weather['backyard_temp'] . ' °C' . $weather['backyard_humidity'] . '%' . $weather['kitchen_temp'] . ' °C' . $weather['kitchen_humidity'] . '%
' . $weather['livingroom_temp'] . ' °C' . $weather['livingroom_humidity'] . '%' . $weather['office_temp'] . ' °C' . $weather['office_humidity'] . '%
' . $weather['wc_temp'] . ' °C' . $weather['wc_humidity'] . '%' . $weather['bedroom_temp'] . ' °C' . $weather['bedroom_humidity'] . '%
' . $weather['bathroom_temp'] . ' °C' . $weather['bathroom_humidity'] . '%' . $weather['cellar_temp'] . ' °C' . $weather['cellar_humidity'] . '%
'; - $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 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 = '
'; + $res .= '
'; + $res .= '
'; + $res .= '
'; + $res .= '
' . accuweatherIcon($weather['icon']) . '
'; + $res .= '
'; + $res .= '
' . accuweatherIcon($weather['nightIcon']) . '
'; + $res .= '
' . accuweatherIcon($weather['dayIcon']) . '
'; + $res .= '
'; + $res .= '
'; + $res .= '
' . $weather['min'] . '°C
'; + $res .= '
' . $weather['outdoor_temp'] . '°C ' . $weather['temp'] . '°C
'; + $res .= '
' . $weather['max'] . '°C
'; + $res .= '
'; + $res .= '
'; + $res .= ' ' . $weather['precipitations24'] . ' mm | ' . $pressure . ' hPa | ' . $weather['outdoor_humidity'] . '%'; + $res .= '
'; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= '
' . $weather['backyard_temp'] . ' °C' . $weather['backyard_humidity'] . '%' . $weather['kitchen_temp'] . ' °C' . $weather['kitchen_humidity'] . '%
' . $weather['livingroom_temp'] . ' °C' . $weather['livingroom_humidity'] . '%' . $weather['office_temp'] . ' °C' . $weather['office_humidity'] . '%
' . $weather['wc_temp'] . ' °C' . $weather['wc_humidity'] . '%' . $weather['bedroom_temp'] . ' °C' . $weather['bedroom_humidity'] . '%
' . $weather['bathroom_temp'] . ' °C' . $weather['bathroom_humidity'] . '%' . $weather['cellar_temp'] . ' °C' . $weather['cellar_humidity'] . '%
'; + $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 .= '
'; - if ($curve === 'sun') { - $res .= '
'; - } else { - $res .= '
'; - } - $res .= '
'; - $res .= '
' . date('H:i', $rise) . '
'; - $res .= '
' . date('H:i', $set) . '
'; - $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 .= '
'; + if ($curve === 'sun') { + $res .= '
'; + } else { + $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); +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 ''; - // return ''; +function accuweatherIcon($icon) { + return ''; + // return ''; } -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