From: Vincent Vanwaelscappel Date: Wed, 24 Apr 2024 07:32:13 +0000 (+0200) Subject: . X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=2da25fe6ad00da7ddba94f383407810f11b8d578;p=tortuga-home.git . --- diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3bdac88..99c8e25 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,9 +6,18 @@ - - + + + + + + + + + + + diff --git a/config/coffee.php b/config/coffee.php index 31feaef..bd3545d 100644 --- a/config/coffee.php +++ b/config/coffee.php @@ -7,10 +7,4 @@ $shortcuts['coffee'] = [ ['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'], -// ['type' => 'ifttt', 'event' => 'coffee_expresso', 'label' => 'Expresso'], -// ['type' => 'ifttt', 'event' => 'coffee_americano', 'label' => 'Americano'], ]; \ No newline at end of file diff --git a/config/global.php b/config/global.php index 7c348bd..020c0b6 100644 --- a/config/global.php +++ b/config/global.php @@ -10,11 +10,6 @@ define("SQUEEZEBOX_SPOTIFY_PASSWORD", '?Z8}#HK+SZrQ'); define('HUE_BRIDGE', '192.168.13.85'); define('HUE_USER', 'zZigF7nPQq9nTZ3GTB1zkntn98trOJVFHWAwFiqQ'); -define('HOMECONNECT_CLIENT_ID', '97C087A66769555561D14306F34336C5D05AD97B56ED813E6BD44ECCFA980CE5'); -define('HOMECONNECT_CLIENT_SECRET', '540F102E39E86F7F92C3A534C31017264A47458589E9E66D27427F35DD4F7BFC'); -define('HOMECONNECT_USERNAME', 'vincent@enhydra.fr'); -define('HOMECONNECT_PASSWORD', 'YcR%vNmYnu%e$3dx2idM'); - define('LATITUDE', 48.8758392); define('LONGITUDE', 2.3422104); diff --git a/js/home.js b/js/home.js index 8607a6a..bf7d354 100644 --- a/js/home.js +++ b/js/home.js @@ -150,11 +150,6 @@ $(function () { return true; }); - $(document).on(clickevent, '.ifttt', function () { - $.get('scripts/ifttt.php?event=' + $(this).data('event')); - return false; - }); - $(document).on(clicktouchevent, '[data-menu]', function () { $("#iframeHolder").hide(); window.location.hash = "#/section/" + $(this).data('menu'); diff --git a/scripts/cron/cron.php b/scripts/cron/cron.php index 0430033..f39138c 100644 --- a/scripts/cron/cron.php +++ b/scripts/cron/cron.php @@ -253,7 +253,6 @@ function cronHarmony($cronmin) { function cronHeartbeat($cronmin, $devices = false) { _logSection('Heartbeat'); setState('cron_heartbeat', time()); - domoticzCmd(null); squeezeRequest(null); hueCommand(null); diff --git a/scripts/domoticz_status.php b/scripts/domoticz_status.php deleted file mode 100644 index 8e59944..0000000 --- a/scripts/domoticz_status.php +++ /dev/null @@ -1,5 +0,0 @@ - 'command', 'passcode' => '']; - $params = array_merge($default, $params); - - unset($params['delay']); - - $ip = 'domoticz.home.tortuga.enhydra.fr'; - return httpRequest('http://' . $ip . ':8084/json.htm', 'GET', $params); -} - -function domoticzGroup($group, $command) -{ - foreach ($group as $device => $delays) { - $delay = $command ? $delays[0] : $delays[1]; - domoticzSwitch($device, $command, 'light', false, $delay); - } -} - -function domoticzSwitch($device, $cmd, $type = 'light', $priority = false, $delay = 0) -{ - if ($cmd === 'Toogle' || $cmd === 'toogle' || $cmd === 'Toggle' || $cmd === 'toggle') { - $cmd = 'Toggle'; - } - if (is_bool($cmd)) { - $cmd = $cmd ? 'On' : 'Off'; - } - return domoticzCmd(['idx' => $device, 'switchcmd' => $cmd, 'param' => 'switch' . $type, 'level' => '0', 'delay' => $delay], $priority); -} - -function domoticzSetLevel($device, $level, $priority = false) -{ - return domoticzCmd(['idx' => $device, 'switchcmd' => 'Set Level', 'param' => 'switchlight', 'level' => max(0, min(100, $level))], $priority); -} - -function domoticzGetLevel($device) -{ - return getDomoticzDeviceStatus($device, true, 'LevelInt'); -} - -function domoticzCmd($command, $priority = false) -{ - - $redis = connectRedis(); - $queue_name = 'domoticz_queue'; - - $queue = $redis->igbget($queue_name); - if (!is_array($queue)) { - $queue = []; - } - if (null !== $command) { - if ($priority) { - array_unshift($queue, $command); - } else { - array_push($queue, $command); - } - } - $redis->igbset($queue_name, $queue); - $redis->publish('domoticz_event', 'handle_queue'); - return true; -} - -function getDomoticzDeviceStatus($device, $force = false, $key = 'Data') -{ - //echo ':)'; - $res = runDomoticzCommand(['type' => 'devices', 'rid' => $device]); - $res = json_decode($res->getBody(), true); - if (null === $res || !isset($res['result']) || !count($res['result'])) { - echo 'Error getting status of device ' . $device . "\n" . print_r($res, true); - return null; - } - - try { - - $update = new DateTime($res['result'][0]['LastUpdate']); - $now = new DateTime(); - if (!$force && $update->diff($now)->days > 0) { - return false; - } - } catch (Exception $e) { - } - return $res['result'][0][$key]; -} diff --git a/scripts/lib/flowerpower.php b/scripts/lib/flowerpower.php deleted file mode 100644 index ce59013..0000000 --- a/scripts/lib/flowerpower.php +++ /dev/null @@ -1,22 +0,0 @@ - 1467, 0 => 1468]; - foreach ($map as $k => $v) { - $newValue = $fp[$k]; - if ($v === 1467) { - $newValue = (float)$newValue; - $currentValue = toNumber(getDomoticzDeviceStatus(1467, true), false); - if (abs($currentValue - $newValue) > 30 || $newValue == 0 || $newValue > 60 || $newValue < -50) { - echo 'Out of bounds'; - return; - } - } - domoticzCmd(['param' => 'udevice', 'idx' => $v, 'nvalue' => 0, 'svalue' => $newValue]); - } -} \ No newline at end of file diff --git a/scripts/lib/ifttt.php b/scripts/lib/ifttt.php deleted file mode 100644 index 9117f9f..0000000 --- a/scripts/lib/ifttt.php +++ /dev/null @@ -1,5 +0,0 @@ - 'scene', 'scene' => 'cuisine/coffee/on'], ], 'chambre/deshumidificateur/on' => [ - //['type' => 'domoticz', 'device' => $chambrefan, 'command' => true], ], 'chambre/deshumidificateur/off' => [ - //['type' => 'domoticz', 'device' => $chambrefan, 'command' => false], + ], 'chambre/fan/on' => [ - ['type' => 'domoticz', 'device' => $chambrefan, 'command' => true], + ], 'chambre/fan/off' => [ - ['type' => 'domoticz', 'device' => $chambrefan, 'command' => false], + ], 'chambre/fan/toggle' => [ - ['type' => 'domoticz', 'device' => $chambrefan, 'command' => 'Toggle'], ], 'chambre/auto' => [ ['type' => 'nightmode', 'mode' => '0'], @@ -266,7 +264,6 @@ $scenes = [ ['type' => 'function', 'function' => 'alert',], ], 'home/doalert' => [ - ['type' => 'domoticz', 'device' => '4207', 'command' => true, 'priority' => true], ['type' => 'hue', 'group' => $alert, 'scene' => ['alert' => 'lselect']], ['type' => 'hue', 'group' => $alert, 'delay' => 3, 'scene' => ['alert' => 'none']], ['type' => 'phonetask', 'phone' => 'vincent', 'task' => 'Tortuga Alerte'], @@ -331,7 +328,6 @@ $scenes = [ ], 'salon/day' => [ ['type' => 'ha', 'device' => 'scene.salon_on'], - ['type' => 'domoticz', 'scene' => 45, 'command' => true, 'priority' => true], ['type' => 'hue', 'group' => $salon, 'scene' => '9ay5VtNcjvUZIFF', 'repeat' => 2], ['type' => 'state', 'key' => 'salon', 'value' => 'on'], ['type' => 'scene', 'scene' => 'cuisine/on', 'delay' => 1], @@ -349,7 +345,6 @@ $scenes = [ 'salon/off' => [ ['type' => 'function', 'function' => 'salonAuto', 'args' => [false]], ['type' => 'ha', 'device' => 'scene.salon_off'], - ['type' => 'domoticz', 'scene' => 45, 'command' => false, 'priority' => true], ['type' => 'hue', 'group' => $salon, 'scene' => array('on' => false)], ['type' => 'state', 'key' => 'salon', 'value' => 'off'], //['type' => 'insteon', 'command' => '0?133=I=0=0'], @@ -368,10 +363,8 @@ $scenes = [ ['type' => 'scene', 'scene' => 'salon/bar/off'], ['type' => 'function', 'function' => 'salonAuto', 'args' => [false]], ['type' => 'ha', 'device' => 'scene.salon_cineclub'], - ['type' => 'domoticz', 'scene' => 46, 'command' => true, 'priority' => true], ['type' => 'hue', 'group' => $salon, 'scene' => 'xpCjXtV3u7O1kYu', 'repeat' => 2], ['type' => 'scene', 'scene' => 'salon/cinemabase'], - ['type' => 'domoticz', 'scene' => 46, 'command' => true, 'priority' => true], ['type' => 'state', 'key' => 'salon', 'value' => 'cinema'], ['type' => 'scene', 'scene' => 'cuisine/tamise', 'repeat' => 2], ], @@ -379,27 +372,22 @@ $scenes = [ ['type' => 'scene', 'scene' => 'salon/bar/off'], ['type' => 'function', 'function' => 'salonAuto', 'args' => [false]], ['type' => 'ha', 'device' => 'scene.salon_cinema'], - ['type' => 'domoticz', 'scene' => 47, 'command' => true, 'priority' => true], ['type' => 'hue', 'group' => $salon, 'scene' => 'AsU9eOyGsjEyz35', 'repeat' => 2], ['type' => 'scene', 'scene' => 'salon/cinemabase'], ['type' => 'state', 'key' => 'salon', 'value' => 'cinema'], - ['type' => 'domoticz', 'scene' => 47, 'command' => true, 'priority' => true], ['type' => 'scene', 'scene' => 'cuisine/tamise', 'repeat' => 2], ], 'salon/tamise' => [ ['type' => 'ecomode', 'mode' => '0'], ['type' => 'ha', 'device' => 'scene.salon_tamise'], - ['type' => 'domoticz', 'scene' => 48, 'command' => true, 'priority' => true], ['type' => 'hue', 'group' => $salon, 'scene' => 'RbjnIcLtcDuHbfU', 'repeat' => 2], ['type' => 'state', 'key' => 'salon', 'value' => 'tamise'], - // ['type' => 'insteon', 'command' => '0?1130=I=0=0'], ['type' => 'function', 'function' => 'chemineeOn', 'args' => ['salon', 'fire', 0.8]], ['type' => 'scene', 'scene' => 'cuisine/on', 'repeat' => 2], ['type' => 'scene', 'scene' => 'salon/bar/on'], ], 'salon/theatre' => [ ['type' => 'ecomode', 'mode' => '0'], - ['type' => 'domoticz', 'scene' => 53, 'command' => true, 'priority' => true], ['type' => 'hue', 'group' => $salon, 'scene' => 'xWNIeznSzek8dKS', 'repeat' => 2], ['type' => 'state', 'key' => 'salon', 'value' => 'theatre'], // ['type' => 'insteon', 'command' => '0?1130=I=0=0'], @@ -409,7 +397,6 @@ $scenes = [ 'salon/lecturenocture' => [ ['type' => 'function', 'function' => 'salonAuto', 'args' => [false]], ['type' => 'ha', 'device' => 'scene.salon_lecturenocturne'], - ['type' => 'domoticz', 'scene' => 49, 'command' => true, 'priority' => true], ['type' => 'hue', 'group' => $salon, 'scene' => 'HZiYyM6hMUMkmiY'], ['type' => 'state', 'key' => 'salon', 'value' => 'tamise'], // ['type' => 'insteon', 'command' => '0?1113=I=0=0'], @@ -430,13 +417,12 @@ $scenes = [ ], 'salon/fan/on' => [ - ['type' => 'domoticz', 'device' => '478', 'command' => true], + ], 'salon/fan/off' => [ - ['type' => 'domoticz', 'device' => '478', 'command' => false], + ], 'salon/fan/toggle' => [ - ['type' => 'domoticz', 'device' => '478', 'command' => 'Toggle', 'priority' => true], ], 'bureau/pc/wakeup' => [ ['type' => 'function', 'function' => 'wakeupPC', 'args' => ['avion']], @@ -454,10 +440,10 @@ $scenes = [ ['type' => 'function', 'function' => 'pcScreensProfile', 'args' => ['Tortuga', 'avion']] ], 'bureau/fan/on' => [ - ['type' => 'domoticz', 'device' => '3529', 'command' => true, 'priority' => true], + ], 'bureau/fan/off' => [ - ['type' => 'domoticz', 'device' => '3529', 'command' => true, 'priority' => true], + ], 'bureau/fan/toggle' => [ ['type' => 'ha', 'device' => 'script.klarstein_fan_toggle'], @@ -782,13 +768,12 @@ $scenes = [ ], 'sdb/off' => [ ['type' => 'state', 'key' => 'sdb', 'value' => 0], - ['type' => 'domoticz', 'scene' => 20, 'command' => false, 'priority' => true], ['type' => 'function', 'function' => 'stopSqueezeboxPlayer', 'args' => [$squeezeboxPlayers['Salle de bains'], false]], ], 'sdb/on' => [ ['type' => 'state', 'key' => 'sdb', 'value' => 1], ['type' => 'state', 'key' => 'sdb', 'value' => 1], - ['type' => 'domoticz', 'scene' => 20, 'command' => true, 'priority' => true], + ], 'sdb/morning' => [ ['type' => 'state', 'key' => 'sdb', 'value' => 1], @@ -797,11 +782,11 @@ $scenes = [ ], 'sdb/nuit' => [ ['type' => 'state', 'key' => 'sdb', 'value' => 1], - ['type' => 'domoticz', 'scene' => 21, 'command' => true, 'priority' => true], + ], 'sdb/spa' => [ ['type' => 'state', 'key' => 'sdb', 'value' => 1], - ['type' => 'domoticz', 'scene' => 22, 'command' => true, 'priority' => true], + ['type' => 'function', 'function' => 'squeezePlayByName', 'args' => ['Nature sounds', $squeezeboxPlayers['Salle de bains'], 65]], ], 'cuisine/hotte/on' => [ @@ -960,12 +945,6 @@ function execScene($name, $fromUserAction = false, $transitionTime = null) phoneTask($action['task'], $action['phone'], true); } else if ($action['type'] == 'ecomode') { ecoMode($action['mode'], $fromUserAction); - } else if ($action['type'] == 'domoticz') { - if (isset($action['scene'])) { - $action['device'] = $action['scene']; - $action['switchtype'] = 'scene'; - } - domoticzSwitch($action['device'], $action['command'], isset($action['switchtype']) ? $action['switchtype'] : 'light', $action['priority'] ?? false); } else if ($action['type'] === 'ha') { if (isset($action['action']) && !isset($action['command'])) { $action['command'] = $action['action']; @@ -974,8 +953,6 @@ function execScene($name, $fromUserAction = false, $transitionTime = null) haAction($action['device'], $action['command'] ?? null); } else if ($action['type'] == 'ir') { irsend($action['room'], $action['device'], $action['command']); - } else if ($action['type'] == 'ifttt') { - ifttt($action['event']); } else if ($action['type'] == 'nightmode') { nightmode($action['mode']); } @@ -1169,7 +1146,6 @@ function wcVMCOn() setState('lastVMCOn', time()); // Start VMC haAction(HA_WC_VMC); - //domoticzSwitch(6449, true, 'light', true); } function wcVMCOff($timeout = 'auto') @@ -1230,18 +1206,6 @@ function alert() execScene('home/doalert'); $rep = 1 * 2; - $domoticzDevices = [4016, 4017, 4033, 4201, 4202, 4203, 4204, 4205, 4614, 4622]; - $domoticzStates = []; - - foreach ($domoticzDevices as $domoticzDevice) { - $domoticzStates[$domoticzDevice] = getDomoticzDeviceStatus($domoticzDevice); - } - - for ($i = 0; $i < $rep; $i++) { - foreach ($domoticzDevices as $device) { - domoticzSwitch($device, 'Toggle', 'light', true); - } - } $hue = getHueInstance(); $group = $hue->getGroups()[18]; @@ -1265,8 +1229,4 @@ function alert() hueCommand(['light' => $lightId, 'scene' => ['on' => $state]]); } - foreach ($domoticzStates as $domoticzDevice => $domoticzState) { - domoticzSwitch($domoticzDevice, $domoticzState); - } - } diff --git a/scripts/lib/weatherstation.php b/scripts/lib/weatherstation.php index 4488b71..40adcea 100644 --- a/scripts/lib/weatherstation.php +++ b/scripts/lib/weatherstation.php @@ -35,8 +35,6 @@ function getWeather() $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']); diff --git a/tools/flowerpower.js b/tools/flowerpower.js deleted file mode 100644 index 7d194e7..0000000 --- a/tools/flowerpower.js +++ /dev/null @@ -1,154 +0,0 @@ -const fs = require('fs'); -const {Console} = require('console'); -const async = require('async'); -const FlowerPower = require('flower-power'); -const querystring = require('querystring'); -const http = require('http'); - - -var res = {}; -var id; - -var output = fs.createWriteStream('./stdout.log'); -//var logconsole = new Console(output, output); -var logconsole = console; - -logconsole.log('Begin discover'); -FlowerPower.discover(function (flowerPower) { - logconsole.log('Discovered one'); - async.series([ - function (callback) { - flowerPower.on('disconnect', function () { - logconsole.log('disconnected!'); - sendtoserver(JSON.stringify(res)); - }); - - logconsole.log('connectAndSetup'); - flowerPower.connectAndSetup(callback); - }, - function (callback) { - logconsole.log('readSystemId'); - flowerPower.readSystemId(function (error, systemId) { - id = systemId; - res[id] = {}; - callback(); - }); - }, - - function (callback) { - logconsole.log('readBatteryLevel'); - flowerPower.readBatteryLevel(function (error, batteryLevel) { - res[id].batteryLevel = batteryLevel; - callback(); - }); - }, - function (callback) { - logconsole.log('readSoilMoisture'); - flowerPower.readSoilMoisture(function (error, soilMoisture) { - res[id].soilMoisture = soilMoisture; - callback(); - }); - }, - function (callback) { - logconsole.log('readCalibratedSoilMoisture'); - flowerPower.readCalibratedSoilMoisture(function (error, soilMoisture) { - res[id].calibratedSoilMoisture = soilMoisture; - callback(); - }); - }, - function (callback) { - logconsole.log('readAirTemperature'); - flowerPower.readAirTemperature(function (error, temperature) { - res[id].AirTemperature = temperature; - callback(); - }); - }, - function (callback) { - logconsole.log('readCalibratedAirTemperature'); - flowerPower.readCalibratedAirTemperature(function (error, temperature) { - res[id].calibratedAirTemperature = temperature; - callback(); - }); - }, - function (callback) { - logconsole.log('readSoilTemperature'); - flowerPower.readSoilTemperature(function (error, soilTemperature) { - res[id].soilTemperature = soilTemperature; - callback(); - }); - }, - function (callback) { - logconsole.log('readSunlight'); - flowerPower.readSunlight(function (error, sunlight) { - res[id].sunlight = sunlight; - callback(); - }); - }, - function (callback) { - logconsole.log('readCalibratedSunlight'); - flowerPower.readCalibratedSunlight(function (error, sunlight) { - res[id].calibratedSunlight = sunlight; - callback(); - }); - }, - function (callback) { - logconsole.log('readCalibratedEa'); - flowerPower.readCalibratedEa(function (error, ea) { - res[id].ea = ea; - callback(); - }); - }, - function (callback) { - logconsole.log('readCalibratedEcb'); - flowerPower.readCalibratedEcb(function (error, ecb) { - res[id].ecb = ecb; - callback(); - }); - }, - function (callback) { - logconsole.log('readCalibratedEcPorous'); - flowerPower.readCalibratedEcPorous(function (error, ecPorous) { - res[id].ecPorous = ecPorous; - callback(); - }); - }, - - function (callback) { - logconsole.log('disconnect'); - flowerPower.disconnect(callback); - } - ]); -}); - -function sendtoserver(data) { - // Build the post string from an object - var post_data = querystring.stringify({ - 'data' :data - }); - - // An object of options to indicate where to post to - var post_options = { - host: 'home.tortuga.enhydra.fr', - port: '443', - path: '/scripts/flowerpower.php', - method: 'POST', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Content-Length': Buffer.byteLength(post_data) - } - }; - - // Set up the request - var post_req = http.request(post_options, function(res) { - res.setEncoding('utf8'); - res.on('data', function (chunk) { - console.log('Response: ' + chunk); - process.exit(0); - }); - }); - - // post the data - post_req.write(post_data); - post_req.end(); -} -