]> _ Git - tortuga-home.git/commitdiff
.
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 14 Jul 2023 10:13:55 +0000 (12:13 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 14 Jul 2023 10:13:55 +0000 (12:13 +0200)
.idea/workspace.xml
scripts/lib/homeassistant.php
scripts/lib/weatherstation.php

index 526a0f34bb022b5bbaf59b93a0fa57ce54eb7648..7b9044935e7c742ea296e5422e28efcd50aae36a 100644 (file)
@@ -6,7 +6,8 @@
   <component name="ChangeListManager">
     <list default="true" id="352ce63a-b52a-41a2-979b-becda7920939" name="Default" comment=".">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/scripts/homeassistant_device_event.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/homeassistant_device_event.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/homeassistant.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/homeassistant.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="1689026578748" duration="2434000" />
       <workItem from="1689274022940" duration="239000" />
       <workItem from="1689274317966" duration="657000" />
-      <workItem from="1689326392784" duration="1671000" />
+      <workItem from="1689326392784" duration="3064000" />
     </task>
     <task id="LOCAL-00502" summary=".">
       <created>1641726946298</created>
       <option name="project" value="LOCAL" />
       <updated>1687259667913</updated>
     </task>
-    <option name="localTasksCounter" value="573" />
+    <option name="localTasksCounter" value="574" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
index 898f3434a64240d84d2bdac9978938ed42e58c7d..a0a1c38eb913d9fc534bf53f4874f58b06305044 100644 (file)
@@ -8,7 +8,7 @@ const HA_ECO_BASIC = 'switch.ecomode_basic';
 const HA_ECO_SUPER = 'switch.ecomode_super';
 const HA_HOTTE = 'switch.hotte';
 const HA_BAR = 'switch.bar';
-const HA_PLANETARIUM='switch.0xa4c138788071821e';
+const HA_PLANETARIUM = 'switch.0xa4c138788071821e';
 
 function haGetState($id, $attribute = null) { //ID to read - for example sensor.foo
 
@@ -21,12 +21,25 @@ function haGetState($id, $attribute = null) { //ID to read - for example sensor.
                                "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;
+
+       $ids = !is_array($id) ? explode(',', $id) : $id;
+       $d = [];
+
+       foreach ($ids as $id) {
+               $ctx = stream_context_create($opts);
+               $data = @file_get_contents(HA_URL . 'api/states/' . $id, false, $ctx);
+               if (!$data) {
+                       continue;
+               }
+               $d[$id] = json_decode($data);
        }
-       $data = json_decode($data);
+
+       usort($d, function ($a, $b) {
+               return strcmp($a->last_updated, $b->last_updated) * -1;
+       });
+
+
+       $data = array_shift($d);
 
        if (null === $attribute) {
                if (!$data)
index cb00e53fe13042b1530c57553361f73b63a33490..11255a579d397a32e5687a855280530e4c2978c6 100644 (file)
@@ -15,8 +15,8 @@ function getWeather() {
        $weather = json_decode(file_get_contents($cache), true);
        $weather = $weather[0];
        $res['temp'] = round(($weather['Temperature']['Metric']['Value']/* + getState('airtemperature')*/));
-       $res['outdoor_temp'] = toNumber(haGetState('sensor.indoor_outdoor_meter_ddf7_temperature'), 1);
-       $res['outdoor_humidity'] = toNumber(haGetState('sensor.indoor_outdoor_meter_ddf7_humidty'), true);
+       $res['outdoor_temp'] = toNumber(haGetState(['sensor.indoor_outdoor_meter_ddf7_temperature', 'sensor.w340001x_tempc']), 1);
+       $res['outdoor_humidity'] = toNumber(haGetState(['sensor.indoor_outdoor_meter_ddf7_humidity', 'sensor.w340001x_hum']), true);
        $res['outdoor_pressure'] = toNumber(haGetState('sensor.0x00158d000464c885_pressure'), true);
        $res['backyard_temp'] = toNumber(haGetState('sensor.0x00158d000464c885_temperature'), 1);
        $res['backyard_humidity'] = toNumber(haGetState('sensor.0x00158d000464c885_humidity'), true);
@@ -32,8 +32,8 @@ function getWeather() {
        $res['kitchen_humidity'] = toNumber(haGetState('sensor.0x00158d000418441f_humidity'), true);
        $res['wc_temp'] = toNumber(haGetState('sensor.0x00158d00046574da_temperature'), 1);
        $res['wc_humidity'] = toNumber(haGetState('sensor.0x00158d00046574da_humidity'), true);
-       $res['office_temp'] = toNumber(haGetState('sensor.meter_c7c3_temperature'), 1);
-       $res['office_humidity'] = toNumber(haGetState('sensor.meter_c7c3_humidite'), 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;