From 18ac3f6f36a2c7031df1e5290fc0c59bac4b5eb4 Mon Sep 17 00:00:00 2001 From: vincent Date: Thu, 14 Apr 2022 01:34:05 +0200 Subject: [PATCH] . --- .idea/workspace.xml | 24 +++++----- config/coffee.php | 4 ++ scripts/cron/cron.php | 28 +++++++----- scripts/domoticz_device_event.php | 26 +++++------ scripts/lib/ecomode.php | 27 ++++++----- scripts/lib/lib.php | 3 +- scripts/lib/scenes.php | 75 ++++++++++++++++++------------- scripts/lib/velib.php | 4 +- 8 files changed, 112 insertions(+), 79 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 317c68b..d6a18af 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,10 +3,12 @@ + + - + - + diff --git a/config/coffee.php b/config/coffee.php index 6229f74..31feaef 100644 --- a/config/coffee.php +++ b/config/coffee.php @@ -4,6 +4,10 @@ $shortcuts['coffee'] = [ ['type' => 'separator', 'label' => 'Machine à café'], ['type' => 'light', 'scene' => 'cuisine/coffee/on', 'label' => 'Allumer'], ['type' => 'light', 'scene' => 'cuisine/coffee/off', 'label' => 'éteindre'], + ['type' => 'separator', 'label' => 'Hotte'], + ['type' => 'light', 'scene' => 'cuisine/hotte/on', 'label' => 'Allumer'], + ['type' => 'light', 'scene' => 'cuisine/hotte/off', 'label' => 'éteindre'], + // ['type' => 'separator', 'label' => 'Cafés'], // ['type' => 'ifttt', 'event' => 'coffee_vincent', 'label' => 'Vincent'], // ['type' => 'ifttt', 'event' => 'coffee_jerome', 'label' => 'Jérôme'], diff --git a/scripts/cron/cron.php b/scripts/cron/cron.php index 6fb5205..a517b7d 100644 --- a/scripts/cron/cron.php +++ b/scripts/cron/cron.php @@ -123,19 +123,20 @@ function _logSection($t) function cronRooms($cronmin) { _logSection('Rooms'); - if (getState('bureauAutoMode') == '1') { - _logSection('Bureau'); - updateBureauAuto(); - } - if (getState('chambreAutoMode') == '1') { - _logSection('Chambre'); - updateChambreAuto(); - } - if (getState('courAutoMode') == '1') { - _logSection('Cour'); - updateCourAuto(); - } + + _logSection('Bureau'); + updateBureauAuto(); + + _logSection('Chambre'); + updateChambreAuto(); + _logSection('Cour'); + updateCourAuto(); + + _logSection('Salon'); + updateSalonAuto(); + + _logSection('Cuisine'); updateCuisine(); _logSection('Planetarium'); checkPlanetarium(); @@ -192,6 +193,9 @@ function cronPing($cronmin) setState('vincenthere', ping('192.168.13.20', 5) ? '1' : '0'); setState('hasnetwork', ping('1.1.1.1', 3, 443) ? '1' : '0'); foreach ($devices as $name => $device) { + if (!isset($device['host'])) { + continue; + } $result = ping($device['host'], 3, 22) ? '1' : '0'; setState('device_' . $name . '_awake', $result); echo 'device_' . $name . '_awake : ' . getState('device_' . $name . '_awake') . "\n"; diff --git a/scripts/domoticz_device_event.php b/scripts/domoticz_device_event.php index 8745543..3777b59 100644 --- a/scripts/domoticz_device_event.php +++ b/scripts/domoticz_device_event.php @@ -24,18 +24,18 @@ if (gloria()) { if ($_GET['device'] == 480) { - chambreToggle(); + chambreToggle(true); } else if (in_array($_GET['device'], $cubesalon)) { // Cube switch ($_GET['state']) { case 'Shake': - execScene('home/alert'); + execScene('home/alert',true); break; case 'Flip_90': - execScene('salon/cinema'); + execScene('salon/cinema',true); break; case 'Flip_180': - execScene('salon/auto'); + execScene('salon/auto',true); break; case 'Free_Fall': off('salon'); @@ -62,11 +62,11 @@ if ($_GET['device'] == 480) { $forceConfig = 'wc'; switch ($_GET['state']) { case 'Double_Click': - execScene('wc/spa'); + execScene('wc/spa',true); setState('wc', 1); break; case 'Long_Click': - execScene('home/alert'); + execScene('home/alert',true); break; case 'Click': default: @@ -77,16 +77,16 @@ if ($_GET['device'] == 480) { // Cube bureau switch ($_GET['state']) { case 'Shake': - execScene('home/alert'); + execScene('home/alert',true); break; case 'Flip_90': - execScene('bureau/rideaux/toggle'); + execScene('bureau/rideaux/toggle',true); break; case 'Flip_180': - execScene('bureau/auto'); + execScene('bureau/auto',true); break; case 'Free_Fall': - execScene('bureau/off'); + execScene('bureau/off',true); off('bureau'); break; case 'Move': @@ -119,13 +119,13 @@ if ($_GET['device'] == 480) { // Cube SDB switch ($_GET['state']) { case 'Shake': - execScene('home/alert'); + execScene('home/alert',true); break; case 'Flip_90': - execScene('sdb/off'); + execScene('sdb/off',true); break; case 'Flip_180': - execScene('sdb/on'); + execScene('sdb/on',true); break; case 'Free_Fall': off('sdb'); diff --git a/scripts/lib/ecomode.php b/scripts/lib/ecomode.php index 5f9227e..2f124b7 100644 --- a/scripts/lib/ecomode.php +++ b/scripts/lib/ecomode.php @@ -34,30 +34,32 @@ function getNightMode() { $device = config('DEVICE'); if ($device === 'sdb') { - $h = date('G'); - if ($h > 6 && $h < 21) { + $h = date('H'); + if ($h >= 6 && $h <= 8) { return false; } - } - if ($device === 'salon') { + if (getState('chambreOff')) { + return true; + } + } else if ($device === 'salon') { if (getState('salon') !== 'off') { return false; } - } - if ($device === 'bureau' || $device === 'bureausun') { + } else if ($device === 'bureau' || $device === 'bureausun') { + if (getState('bureauOff') == '1') { + return true; + } if (getDomoticzDeviceStatus(391) === 'Closed') { return true; } if (getState('bureau_gradient') !== 'off') { return false; } - } - if ($device === 'wc') { + } else if ($device === 'wc') { if (getState('bureau_gradient') !== 'off') { return false; } - } - if ($device === 'entree' || $device === 'cuisine') { + } else if ($device === 'entree' || $device === 'cuisine') { $lights = [15, 18, 1, 58, 59, 57, 56, 55, 37]; $hueLights = getHueInstance()->getLights(); foreach ($lights as $l) { @@ -66,7 +68,12 @@ function getNightMode() return false; } } + } else if ($device === 'chambre' || $device === 'litjerome' || $device === 'litvincent') { + if (getState('chambreOff')) { + return true; + } } + return getState('night') == '1'; } diff --git a/scripts/lib/lib.php b/scripts/lib/lib.php index 6333dad..417e343 100644 --- a/scripts/lib/lib.php +++ b/scripts/lib/lib.php @@ -95,8 +95,7 @@ function getCurrentConfig() } if (!isset($_COOKIE['homeconfig'])) { - - if (isset($ips[$_SERVER['REMOTE_ADDR']])) { + if (isset($_SERVER['REMOTE_ADDR']) && isset($ips[$_SERVER['REMOTE_ADDR']])) { $c = $ips[$_SERVER['REMOTE_ADDR']]; } else { $c = 'salon'; diff --git a/scripts/lib/scenes.php b/scripts/lib/scenes.php index 113a4ad..0477645 100644 --- a/scripts/lib/scenes.php +++ b/scripts/lib/scenes.php @@ -111,7 +111,6 @@ $scenes = [ 'chambre/boreal' => [ ['type' => 'nightmode', 'mode' => '0'], - ['type' => 'state', 'key' => 'chambre', 'value' => 1], ['type' => 'hue', 'group' => $chambre, 'scene' => 'mwAGvt2n70oXCqA'], ['type' => 'domoticz', 'scene' => 4, 'command' => true, 'priority' => true], //['type' => 'insteon', 'command' => '0?1131=I=0=0'], @@ -119,7 +118,6 @@ $scenes = [ ], 'chambre/savane' => [ ['type' => 'nightmode', 'mode' => '0'], - ['type' => 'state', 'key' => 'chambre', 'value' => 1], ['type' => 'hue', 'group' => $chambre, 'scene' => 'ABqCuE-ob-sw2vQ'], ['type' => 'domoticz', 'scene' => 5, 'command' => true, 'priority' => true], //['type' => 'insteon', 'command' => '0?1131=I=0=0'], @@ -127,7 +125,6 @@ $scenes = [ ], 'chambre/focus' => [ ['type' => 'nightmode', 'mode' => '0'], - ['type' => 'state', 'key' => 'chambre', 'value' => 1], ['type' => 'hue', 'group' => $chambre, 'scene' => 'Ne6uJnnoPO9yRhl'], ['type' => 'domoticz', 'scene' => 6, 'command' => true, 'priority' => true], //['type' => 'insteon', 'command' => '0?1131=I=0=0'], @@ -136,7 +133,6 @@ $scenes = [ ], 'chambre/chillout' => [ ['type' => 'nightmode', 'mode' => '0'], - ['type' => 'state', 'key' => 'chambre', 'value' => 1], ['type' => 'hue', 'group' => $chambre, 'scene' => '03gdSwPyZ9sbZVg'], ['type' => 'domoticz', 'scene' => 7, 'command' => true, 'priority' => true], //['type' => 'insteon', 'command' => '0?1131=I=0=0'], @@ -149,7 +145,6 @@ $scenes = [ ], 'chambre/reading' => [ ['type' => 'nightmode', 'mode' => '0'], - ['type' => 'state', 'key' => 'chambre', 'value' => 1], ['type' => 'hue', 'group' => $chambre, 'scene' => 'BNiNQjxiWNbKRaH'], ['type' => 'domoticz', 'scene' => 8, 'command' => true, 'priority' => true], // ['type' => 'insteon', 'command' => '0?1131=I=0=0'], @@ -158,7 +153,6 @@ $scenes = [ ], 'chambre/tonic' => [ ['type' => 'nightmode', 'mode' => '0'], - ['type' => 'state', 'key' => 'chambre', 'value' => 1], ['type' => 'hue', 'group' => $chambre, 'scene' => 'Tlcft9sPK492cJA'], ['type' => 'domoticz', 'scene' => 9, 'command' => true, 'priority' => true], // ['type' => 'insteon', 'command' => '0?1131=I=0=0'], @@ -173,7 +167,6 @@ $scenes = [ ], 'chambre/party' => [ ['type' => 'nightmode', 'mode' => '0'], - ['type' => 'state', 'key' => 'chambre', 'value' => 1], ['type' => 'hue', 'group' => $chambre, 'scene' => 'qvQXHDodBPa0cZf'], ['type' => 'domoticz', 'scene' => 12, 'command' => true, 'priority' => true], //['type' => 'insteon', 'command' => '0?1119=I=0=0'], @@ -182,7 +175,6 @@ $scenes = [ ], 'chambre/flowers' => [ ['type' => 'nightmode', 'mode' => '0'], - ['type' => 'state', 'key' => 'chambre', 'value' => 1], ['type' => 'hue', 'group' => $chambre, 'scene' => 'VtGPKtpQ7DF-RCd'], ['type' => 'domoticz', 'scene' => 13, 'command' => true, 'priority' => true], //['type' => 'insteon', 'command' => '0?1131=I=0=0'], @@ -191,7 +183,6 @@ $scenes = [ ], 'chambre/tropical' => [ ['type' => 'nightmode', 'mode' => '0'], - ['type' => 'state', 'key' => 'chambre', 'value' => 1], ['type' => 'hue', 'group' => $chambre, 'scene' => 'Mqq8VMsmPQtzEQ0'], ['type' => 'domoticz', 'scene' => 14, 'command' => true, 'priority' => true], // ['type' => 'insteon', 'command' => '0?1131=I=0=0'], @@ -200,7 +191,6 @@ $scenes = [ ], 'chambre/beach' => [ ['type' => 'nightmode', 'mode' => '0'], - ['type' => 'state', 'key' => 'chambre', 'value' => 1], ['type' => 'hue', 'group' => $chambre, 'scene' => 'HfMaPG92lEOUDB0'], ['type' => 'domoticz', 'scene' => 15, 'command' => true, 'priority' => true], //['type' => 'insteon', 'command' => '0?1131=I=0=0'], @@ -212,7 +202,6 @@ $scenes = [ ['type' => 'domoticz', 'scene' => 16, 'command' => true, 'priority' => true], ], 'chambre/summernight' => [ - ['type' => 'state', 'key' => 'chambre', 'value' => 1], ['type' => 'scene', 'scene' => 'chambre/nightlights'], //['type' => 'insteon', 'command' => '0?1131=I=0=0'], ['type' => 'function', 'function' => 'bedbrightness', 'args' => [255]], @@ -220,7 +209,6 @@ $scenes = [ ], 'chambre/lounge' => [ ['type' => 'nightmode', 'mode' => '0'], - ['type' => 'state', 'key' => 'chambre', 'value' => 1], ['type' => 'hue', 'group' => $chambre, 'scene' => 'XGuSVQ3RCd7JUBC'], ['type' => 'domoticz', 'scene' => 17, 'command' => true, 'priority' => true], // ['type' => 'insteon', 'command' => '0?1131=I=0=0'], @@ -229,7 +217,6 @@ $scenes = [ ], 'chambre/full' => [ ['type' => 'nightmode', 'mode' => '0'], - ['type' => 'state', 'key' => 'chambre', 'value' => 1], ['type' => 'hue', 'group' => $chambre, 'scene' => 'ZkiQbNQDXJz9-OC'], ['type' => 'domoticz', 'scene' => 18, 'command' => true, 'priority' => true], // ['type' => 'insteon', 'command' => '0?1132=I=0=0'], @@ -248,7 +235,6 @@ $scenes = [ // ['type' => 'insteon', 'command' => '0?1332=I=0=0'], ['type' => 'domoticz', 'scene' => 19, 'command' => false, 'priority' => true], ], - 'chambre/cheminee' => [ ['type' => 'domoticz', 'scene' => 43, 'command' => true, 'priority' => true], ], @@ -580,7 +566,6 @@ $scenes = [ ['type' => 'scene', 'scene' => 'bureau/base/on'], ['type' => 'scene', 'scene' => 'bureau/screens/on'], ['type' => 'domoticz', 'scene' => 39, 'command' => true, 'priority' => true], - ], 'bureau/beach' => [ ['type' => 'hue', 'group' => $bureau, 'scene' => '0mPAKOl-Kw8Fwb1'], @@ -908,9 +893,14 @@ function execScene($name, $fromUserAction = false, $transitionTime = null) $e = explode('/', $name); - if ($fromUserAction && $e[1] !== 'auto' && count($e) == 2) { - call_user_func($e[0] . 'Auto', false); + $autoRooms = ['bureau', 'chambre', 'salon', 'cour']; + + if (in_array($e[0], $autoRooms)) { setState($e[0] . 'Off', $e[1] === 'off' ? '1' : '0'); + if ($fromUserAction && $e[1] !== 'auto' && count($e) == 2) { + call_user_func($e[0] . 'Auto', false); + + } } $killurl = WEB_ROOT . 'scripts/light.php?[r]=2'; @@ -937,7 +927,7 @@ function execScene($name, $fromUserAction = false, $transitionTime = null) if ($action['type'] == 'hue') { hueCommand($action, $transitionTime); - } else if ($action['type'] == 'delay' || $action['type'] == 'scene') { + } else if ($action['type'] == 'delay' || $action['type'] == 'scene') { if (!isset($action['delay'])) { $action['delay'] = 0; } @@ -977,12 +967,12 @@ function execScene($name, $fromUserAction = false, $transitionTime = null) } } -function chambreToggle() +function chambreToggle($fromUserAction = false) { - if (getState('chambre') == 1) { - execScene('chambre/off'); + if (getState('chambreOff') == 0) { + execScene('chambre/off', $fromUserAction); } else { - execScene('chambre/full'); + execScene('chambre/full', $fromUserAction); } } @@ -1000,7 +990,7 @@ function wcMusic($volume) function wcToggle() { if (getState('wc') == 1) { - execScene('wc/off'); + execScene('wc/off', true); } else { wcOn(); } @@ -1018,7 +1008,6 @@ function sdbToggle() function wcOn($vmc = true) { - $hour = getHour(); if (getNightMode()) { $period = 'night'; @@ -1031,7 +1020,7 @@ function wcOn($vmc = true) } else { $period = 'evening'; } - execScene('wc/' . $period); + execScene('wc/' . $period, true); setState('wc', 1); if ($vmc && $period != 'night') { wcVMCOn(); @@ -1155,7 +1144,6 @@ function bedbrightness($brightness) function salonAuto($on = true) { if ($on) { - setState('salonAutoMode', '1'); updateSalonAuto(); } else if (getState('salonAutoMode') === '1') { @@ -1165,10 +1153,6 @@ function salonAuto($on = true) function chambreAuto($on = true, $transitionTime = null) { - if (getState('chambreOff') == '1') { - execScene('chambre/off'); - return; - } if ($on) { ecoMode(0); setState('chambreAutoMode', '1'); @@ -1204,6 +1188,9 @@ function updateSalonAuto() execScene('salon/off'); return; } + if (getState('salonAutoMode') != '1') { + return; + } $hours = intval(date('H')); if ($hours <= 9) { $scene = 'tamise'; @@ -1221,6 +1208,9 @@ function updateChambreAuto($transitionTime = null) execScene('chambre/off'); return; } + if (getState('chambreAutoMode') != '1') { + return; + } $hours = intval(date('H')); if ($hours <= 4) { $scene = 'party'; @@ -1246,6 +1236,9 @@ function updateBureauAuto() execScene('bureau/off'); return; } + if (getState('bureauAutoMode') != '1') { + return; + } $hours = intval(date('H')); if ($hours <= 4) { $scene = 'outrun'; @@ -1281,6 +1274,9 @@ function updateCourAuto() execScene('cour/off'); return; } + if (getState('courAutoMode') != '1') { + return; + } if (isDay()) { $scene = 'daylight'; } else { @@ -1388,4 +1384,23 @@ function alert() domoticzSwitch($domoticzDevice, $domoticzState); } +} + +function autoRooms() +{ + if (getState('bureauAutoMode') == '1') { + updateBureauAuto(); + } + if (getState('chambreAutoMode') == '1') { + updateChambreAuto(); + } + if (getState('courAutoMode') == '1') { + updateCourAuto(); + } + if (getState('salonAutoMode') == '1') { + updateSalonAuto(); + } + updateCuisine(); + checkPlanetarium(); + checkWCVMC(); } \ No newline at end of file diff --git a/scripts/lib/velib.php b/scripts/lib/velib.php index 66bf8bf..ecf66ba 100644 --- a/scripts/lib/velib.php +++ b/scripts/lib/velib.php @@ -1,7 +1,9 @@ 9101, 'Bleue' => 9113, 'Folies bergères' => 9011, 9009, 'Le Pelletier' => 9014]; $res = array(); -- 2.39.5