]> _ Git - tortuga-home.git/commitdiff
.
authorvincent <vincent@enhydra.fr>
Sun, 13 Feb 2022 14:56:08 +0000 (15:56 +0100)
committervincent <vincent@enhydra.fr>
Sun, 13 Feb 2022 14:56:08 +0000 (15:56 +0100)
.idea/workspace.xml
scripts/cron/cron.php
scripts/lib/domoticz.php
scripts/lib/flowerpower.php
scripts/lib/weatherstation.php
scripts/weather.php [new file with mode: 0644]

index fbd6b700cc9d49705c15d0e32d8c6e3bf1a696c3..0f0e4f3f964951994e2e0fab120f7792696a8f0c 100644 (file)
@@ -2,12 +2,12 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="352ce63a-b52a-41a2-979b-becda7920939" name="Default" comment=".">
+      <change afterPath="$PROJECT_DIR$/scripts/weather.php" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/config/rooms.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/rooms.php" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/scripts/cron/cron.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/cron/cron.php" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/scripts/lib/domoticz.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/domoticz.php" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/scripts/lib/lib.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/lib.php" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/scripts/lib/scenes.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/scenes.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/flowerpower.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/flowerpower.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/weatherstation.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/weatherstation.php" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
       <workItem from="1643960682357" duration="593000" />
       <workItem from="1644143547964" duration="594000" />
       <workItem from="1644673539378" duration="1825000" />
-      <workItem from="1644683361342" duration="3044000" />
-    </task>
-    <task id="LOCAL-00467" summary=".">
-      <created>1618342660944</created>
-      <option name="number" value="00467" />
-      <option name="presentableId" value="LOCAL-00467" />
-      <option name="project" value="LOCAL" />
-      <updated>1618342660944</updated>
+      <workItem from="1644683361342" duration="8803000" />
     </task>
     <task id="LOCAL-00468" summary=".">
       <created>1618426951296</created>
       <option name="project" value="LOCAL" />
       <updated>1642950622190</updated>
     </task>
-    <option name="localTasksCounter" value="516" />
+    <task id="LOCAL-00516" summary=".">
+      <created>1644750402613</created>
+      <option name="number" value="00516" />
+      <option name="presentableId" value="LOCAL-00516" />
+      <option name="project" value="LOCAL" />
+      <updated>1644750402613</updated>
+    </task>
+    <option name="localTasksCounter" value="517" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
index 586860dd4afc8fce0d3b929d493ab06d42162f4a..6fb52057c9dd2677cd2625b9ee9b6f49494f3093 100644 (file)
@@ -220,97 +220,7 @@ function cronSqueezeCheckPlayers($cronmin)
 function cronWeather($cronmin)
 {
     _logSection('Weather');
-    $place = 2608449;
-    $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(getDomoticzDeviceStatus(1467), 1);
-    $res['outdoor_humidity'] = toNumber(getDomoticzDeviceStatus(1026), true);
-    $res['outdoor_pressure'] = toNumber(getDomoticzDeviceStatus(1027), true);
-    $res['backyard_temp'] = toNumber(getDomoticzDeviceStatus(1354), 1);
-    $res['backyard_humidity'] = toNumber(getDomoticzDeviceStatus(1357), true);
-    $res['backyard_pressure'] = toNumber(getDomoticzDeviceStatus(1358), true);
-    $res['bathroom_temp'] = toNumber(getDomoticzDeviceStatus(1346), 1);
-    $res['bathroom_humidity'] = toNumber(getDomoticzDeviceStatus(1347), true);
-    $res['bedroom_temp'] = toNumber(getDomoticzDeviceStatus(6851), 1);
-    $res['bedroom_humidity'] = toNumber(getDomoticzDeviceStatus(6852), true);
-    $res['bedroom_airquality'] = toNumber(getDomoticzDeviceStatus(6853), true);
-    $res['livingroom_temp'] = toNumber(getDomoticzDeviceStatus(6453), 1);
-    $res['livingroom_humidity'] = toNumber(getDomoticzDeviceStatus(6454), true);
-    $res['kitchen_temp'] = toNumber(getDomoticzDeviceStatus(1506), 1);
-    $res['kitchen_humidity'] = toNumber(getDomoticzDeviceStatus(1507), true);
-    $res['wc_temp'] = toNumber(getDomoticzDeviceStatus(1501), 1);
-    $res['wc_humidity'] = toNumber(getDomoticzDeviceStatus(1502), true);
-    $res['office_temp'] = toNumber(getDomoticzDeviceStatus(1496), 1);
-    $res['office_humidity'] = toNumber(getDomoticzDeviceStatus(1497), true);
-    $res['cellar_humidity'] = toNumber(getDomoticzDeviceStatus(4818), true);
-    $res['cellar_temp'] = toNumber(getDomoticzDeviceStatus(4817), 1);
-    $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));
+    getWeather();
 }
 
 function cronVelib($cronmin)
index 111975cf96644b7853146bfa7c5d7a9ec3b48ffb..fecf98cc19e3726887095912084715fd69bed4b1 100644 (file)
@@ -64,8 +64,13 @@ 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) {
index 2d671c3e27871b1c0bab092f8c3593db3f9152a4..b096732f349f9189ed4c7b61b614d038924e0e6f 100644 (file)
@@ -1,7 +1,9 @@
 <?php
 function updateFlowerPower()
 {
-    $device = getState('device_salon_awake') ? 'salon' : 'bureausun';
+    $devices = getState('device_salon_awake') ? ['bureausun', 'salon'] : ['bureausun'];
+    shuffle($devices);
+    $device = array_pop($devices);
     $res = sshRunCommand('timeout -k 10 1m /usr/local/bin/flowerpower', $device, true, true);
     $fp = explode("\n", $res['output']);
     $map = [1 => 1467, 0 => 1468];
index b8ebd8eb5eba791a22ba17ee8b2911249a09f1e8..cf70ae92b367fb5e5efc0f9e218bd746f308a983 100644 (file)
@@ -1,4 +1,101 @@
 <?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(getDomoticzDeviceStatus(1467), 1);
+    $res['outdoor_humidity'] = toNumber($weather['RelativeHumidity'], true);
+    $res['outdoor_pressure'] = toNumber(getDomoticzDeviceStatus(1358), true);
+    $res['backyard_temp'] = toNumber(getDomoticzDeviceStatus(1354), 1);
+    $res['backyard_humidity'] = toNumber(getDomoticzDeviceStatus(1357), true);
+    $res['backyard_pressure'] = toNumber(getDomoticzDeviceStatus(1358), true);
+    $res['bathroom_temp'] = toNumber(getDomoticzDeviceStatus(1346), 1);
+    $res['bathroom_humidity'] = toNumber(getDomoticzDeviceStatus(1347), true);
+    $res['bedroom_temp'] = toNumber(getDomoticzDeviceStatus(6851), 1);
+    $res['bedroom_humidity'] = toNumber(getDomoticzDeviceStatus(6852), true);
+    $res['bedroom_airquality'] = toNumber(getDomoticzDeviceStatus(6853), true);
+    $res['livingroom_temp'] = toNumber(getDomoticzDeviceStatus(6453), 1);
+    $res['livingroom_humidity'] = toNumber(getDomoticzDeviceStatus(6454), true);
+    $res['kitchen_temp'] = toNumber(getDomoticzDeviceStatus(1506), 1);
+    $res['kitchen_humidity'] = toNumber(getDomoticzDeviceStatus(1507), true);
+    $res['wc_temp'] = toNumber(getDomoticzDeviceStatus(1501), 1);
+    $res['wc_humidity'] = toNumber(getDomoticzDeviceStatus(1502), true);
+    $res['office_temp'] = toNumber(getDomoticzDeviceStatus(1496), 1);
+    $res['office_humidity'] = toNumber(getDomoticzDeviceStatus(1497), true);
+    $res['cellar_humidity'] = toNumber(getDomoticzDeviceStatus(4818), true);
+    $res['cellar_temp'] = toNumber(getDomoticzDeviceStatus(4817), 1);
+    $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);
diff --git a/scripts/weather.php b/scripts/weather.php
new file mode 100644 (file)
index 0000000..f0180ec
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+include "import.php";
+header('Content-type: text/plain');
+print_r(json_decode(file_get_contents(ROOT . '/cache/accuweather.json')));
+print_r(json_decode(file_get_contents(ROOT . '/cache/accuforecasts.json')));
+print_r(getWeather());