From: vincent Date: Sun, 13 Feb 2022 14:56:08 +0000 (+0100) Subject: . X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=2bcd8d06a18e3449ce9568944ee3f7152c57be71;p=tortuga-home.git . --- diff --git a/.idea/workspace.xml b/.idea/workspace.xml index fbd6b70..0f0e4f3 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,12 +2,12 @@ + - - - + + diff --git a/scripts/cron/cron.php b/scripts/cron/cron.php index 586860d..6fb5205 100644 --- a/scripts/cron/cron.php +++ b/scripts/cron/cron.php @@ -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) diff --git a/scripts/lib/domoticz.php b/scripts/lib/domoticz.php index 111975c..fecf98c 100644 --- a/scripts/lib/domoticz.php +++ b/scripts/lib/domoticz.php @@ -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) { diff --git a/scripts/lib/flowerpower.php b/scripts/lib/flowerpower.php index 2d671c3..b096732 100644 --- a/scripts/lib/flowerpower.php +++ b/scripts/lib/flowerpower.php @@ -1,7 +1,9 @@ 1467, 0 => 1468]; diff --git a/scripts/lib/weatherstation.php b/scripts/lib/weatherstation.php index b8ebd8e..cf70ae9 100644 --- a/scripts/lib/weatherstation.php +++ b/scripts/lib/weatherstation.php @@ -1,4 +1,101 @@