From: Vincent Vanwaelscappel Date: Wed, 4 Jun 2025 15:40:45 +0000 (+0200) Subject: . X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=291a0f3c799c4ff87bd426dabe0a3d54159f4541;p=tortuga-home.git . --- diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 67ea113..b36e2be 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,12 +5,9 @@ - - - - - + + + - @@ -1349,7 +1347,9 @@ - + + + 1641726946298 @@ -1694,7 +1694,7 @@ - diff --git a/images/cocodrilo.svg b/images/cocodrilo.svg new file mode 100644 index 0000000..0f065fb --- /dev/null +++ b/images/cocodrilo.svg @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/scripts/lib/homeassistant.php b/scripts/lib/homeassistant.php index 83c79c8..16ac759 100644 --- a/scripts/lib/homeassistant.php +++ b/scripts/lib/homeassistant.php @@ -2,96 +2,117 @@ const HA_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJiMjJlOWU2YzQ5ZTM0OTk5YTc3YTFjYzE3MDdiNTViNyIsImlhdCI6MTY4ODMxNTk0NywiZXhwIjoyMDAzNjc1OTQ3fQ.HS-KUXxaFE2esRydhqTfzCS7sc7eaZPVv0BE6NNGWas'; const HA_URL = 'http://192.168.13.8:8123/'; +const HA_COCODRILO_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI0NjNhOWVhNzIyYzY0ZGRlODhkODY3ZDdhZDc2N2NmOSIsImlhdCI6MTc0OTA0MDkxNCwiZXhwIjoyMDY0NDAwOTE0fQ.0cwLyGhpd0XK4NaO2cK0686SNRor7jAQqdEDb9vos6Q'; +const HA_COCODRILO_URL = 'http://cocodrilo.enhydra.fr:18832/'; + const HA_WC_VMC = 'switch.0x847127fffe280f20'; const HA_SDB_AMPLI = 'switch.0xa4c138168147c1b6'; 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_GROW_LAMPS='switch.0x00124b0025e24358'; +const HA_GROW_LAMPS = 'switch.0x00124b0025e24358'; const HA_PLANETARIUM = 'switch.0xa4c138788071821e'; -const HA_OFFICE_CURTAIN='input_boolean.rideaux_bureau'; -const HA_OFFICE_SCREEN='cover.office_screen'; +const HA_OFFICE_CURTAIN = 'input_boolean.rideaux_bureau'; +const HA_OFFICE_SCREEN = 'cover.office_screen'; const HA_OFFICE_MAIN_SCREEN = 'switch.0xa4c138787633f01d'; const HA_OFFICE_PLANE_SCREENS = 'switch.0xa4c138ba535d2cc5'; -const HA_COFFEE='switch.machine_a_cafe_power'; +const HA_COFFEE = 'switch.machine_a_cafe_power'; + +const HA_SALON_PROJ_SENSOR = 'binary_sensor.0x00158d00094363cc_contact'; -const HA_SALON_PROJ_SENSOR='binary_sensor.0x00158d00094363cc_contact'; +function haGetState($id, $attribute = null, $instance = 'tortuga') +{ //ID to read - for example sensor.foo -function haGetState($id, $attribute = null) { //ID to read - for example sensor.foo + if ($instance === 'tortuga') { + $url = HA_URL; + $key = HA_KEY; + } else { + $url = HA_COCODRILO_URL; + $key = HA_COCODRILO_KEY; + } - $opts = [ - "http" => [ - "method" => "GET", - "header" => - "Content-Type: application/json\r\n" . - "Authorization: Bearer " . HA_KEY . "\r\n" - ] - ]; + $opts = [ + "http" => [ + "method" => "GET", + "header" => + "Content-Type: application/json\r\n" . + "Authorization: Bearer " . $key . "\r\n" + ] + ]; - $ids = !is_array($id) ? explode(',', $id) : $id; - $d = []; + $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); - } + foreach ($ids as $id) { + $ctx = stream_context_create($opts); + $data = @file_get_contents($url . 'api/states/' . $id, false, $ctx); + if (!$data) { + continue; + } + $d[$id] = json_decode($data); + } - usort($d, function ($a, $b) { - return strcmp($a->last_updated, $b->last_updated) * -1; - }); + usort($d, function ($a, $b) { + return strcmp($a->last_updated, $b->last_updated) * -1; + }); - $data = array_shift($d); + $data = array_shift($d); - if (null === $attribute) { - if (!$data) - return false; - if (!isset($data->state)) - return false; - return $data->state; - } - return ($data->attributes->$attribute) ?? false; + if (null === $attribute) { + if (!$data) + return false; + if (!isset($data->state)) + return false; + return $data->state; + } + return ($data->attributes->$attribute) ?? false; } -function haAction($id, $action = null, $domain = null, $data = []) { - if (null === $action) { - $action = 'turn_on'; - } - $data['entity_id'] = $id; - $opts = [ - "http" => [ - "method" => "POST", - 'content' => json_encode($data), - "header" => - "Content-Type: application/json\r\n" . - "Authorization: Bearer " . HA_KEY . "\r\n" - ] - ]; - - if (null === $domain) { - $e = explode('.', $id); - $domain = $e[0]; - } - - $ctx = stream_context_create($opts); - $data = file_get_contents(HA_URL . 'api/services/' . $domain . '/' . $action, false, $ctx); - if (!$data) - return false; - $data = json_decode($data); - if (!$data) - return false; - if (!isset($data->state)) - return false; - return [$data->state, $data->last_updated]; +function haAction($id, $action = null, $domain = null, $data = [], $instance = 'tortuga') +{ + if ($instance === 'tortuga') { + $url = HA_URL; + $key = HA_KEY; + } else { + $url = HA_COCODRILO_URL; + $key = HA_COCODRILO_KEY; + } + + if (null === $action) { + $action = 'turn_on'; + } + $data['entity_id'] = $id; + $opts = [ + "http" => [ + "method" => "POST", + 'content' => json_encode($data), + "header" => + "Content-Type: application/json\r\n" . + "Authorization: Bearer " . $key . "\r\n" + ] + ]; + + if (null === $domain) { + $e = explode('.', $id); + $domain = $e[0]; + } + + $ctx = stream_context_create($opts); + $data = file_get_contents($url . 'api/services/' . $domain . '/' . $action, false, $ctx); + if (!$data) + return false; + $data = json_decode($data); + if (!$data) + return false; + if (!isset($data->state)) + return false; + return [$data->state, $data->last_updated]; } diff --git a/scripts/lib/weatherstation.php b/scripts/lib/weatherstation.php index 40adcea..c4d9a7b 100644 --- a/scripts/lib/weatherstation.php +++ b/scripts/lib/weatherstation.php @@ -16,25 +16,26 @@ 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', '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.indoor_outdoor_meter_1719'), 1); - $res['backyard_humidity'] = toNumber(haGetState('sensor.indoor_outdoor_meter_1719_humidite'), true); - $res['backyard_pressure'] = toNumber(haGetState('sensor.0x00158d0004658cc2_pressure'), true); - $res['bathroom_temp'] = toNumber(haGetState('sensor.0x00158d0004658cc2_temperature'), 1); - $res['bathroom_humidity'] = toNumber(haGetState('sensor.0x00158d0004658cc2_humidity'), true); - $res['bedroom_temp'] = toNumber(haGetState('sensor.0x54ef4410003596e5_temperature'), 1); - $res['bedroom_humidity'] = toNumber(haGetState('sensor.0x54ef4410003596e5_humidity'), true); - $res['bedroom_airquality'] = toNumber(haGetState('sensor.0x54ef4410003596e5_voc'), true); - $res['livingroom_temp'] = toNumber(haGetState('sensor.temperature_salon_temperature'), 1); - $res['livingroom_humidity'] = toNumber(haGetState('sensor.temperature_salon_humidity'), true); - $res['kitchen_temp'] = toNumber(haGetState('sensor.0x00158d000418441f_temperature'), 1); - $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', 'sensor.thx1_w230150x_tempc']), 1); - $res['office_humidity'] = toNumber(haGetState(['sensor.meter_c7c3_humidite', 'sensor.thx1_w230150x_hum']), true); + $res['outdoor_temp'] = toNumber(haGetState('sensor.sb_balcon_temperature'), true); + $res['outdoor_humidity'] = toNumber(haGetState('sensor.sb_balcon_humidite'), true); + $res['backyard_temp'] = toNumber(haGetState('sensor.sb_cour_temperature'), 1); + $res['backyard_humidity'] = toNumber(haGetState('sensor.sb_cour_humidite'), true); + $res['bathroom_temp'] = toNumber(haGetState('sensor.sb_sdb_temperature'), 1); + $res['bathroom_humidity'] = toNumber(haGetState('sensor.sb_sdb_humidite'), true); + $res['bedroom_temp'] = toNumber(haGetState('sensor.sb_chambre_temperature'), 1); + $res['bedroom_humidity'] = toNumber(haGetState('sensor.sb_chambre_humidite'), true); + //$res['bedroom_airquality'] = toNumber(haGetState('sensor.0x54ef4410003596e5_voc'), true); + $res['livingroom_temp'] = toNumber(haGetState('sensor.sb_salon_temperature'), 1); + $res['livingroom_humidity'] = toNumber(haGetState('sensor.sb_salon_humidite'), true); + $res['kitchen_temp'] = toNumber(haGetState('sensor.sb_cuisine_temperature'), 1); + $res['kitchen_humidity'] = toNumber(haGetState('sensor.sb_cuisine_humidite'), true); + $res['wc_temp'] = toNumber(haGetState('sensor.sb_wc_temperature'), 1); + $res['wc_humidity'] = toNumber(haGetState('sensor.sb_wc_humidite'), true); + $res['office_temp'] = toNumber(haGetState('sensor.sb_bureau_temperature'), 1); + $res['office_humidity'] = toNumber(haGetState('sensor.sb_bureau_humidite'), true); + $res['cocodrilo_min'] = toNumber(haGetState('sensor.temperature_interieure_minimale', null, 'cocodrilo')); + $res['cocodrilo_max'] = toNumber(haGetState('sensor.temperature_interieure_maximale', null, 'cocodrilo')); + $res['cocodrilo_humidity'] = toNumber(haGetState('sensor.humidite_interieure', null, 'cocodrilo'),true); $res['cellar_humidity'] = 0; $res['cellar_temp'] = 0; $res['pressure'] = round($weather['Pressure']['Metric']['Value']); @@ -101,7 +102,6 @@ function weatherStationScreenSaver() $weather = json_decode(file_get_contents(ROOT . '/cache/weather.json'), true); $pressureTendency = $weather['pressureTendency'] == 'F' ? 'down' : 'up'; - $pressure = $weather['outdoor_pressure'] == '--' ? $weather['backyard_pressure'] : $weather['outdoor_pressure']; $res = '
'; $res .= '
'; @@ -118,7 +118,7 @@ function weatherStationScreenSaver() $res .= '
' . $weather['max'] . '°C
'; $res .= '
'; $res .= '
'; - $res .= ' ' . $weather['precipitations24'] . ' mm | ' . $pressure . ' hPa | ' . $weather['outdoor_humidity'] . '%'; + $res .= ' ' . $weather['precipitations24'] . ' mm | ' . $weather['pressure'] . ' hPa | ' . $weather['outdoor_humidity'] . '%'; $res .= '
'; $res .= ''; $res .= ''; @@ -128,7 +128,9 @@ function weatherStationScreenSaver() $res .= ''; $res .= ''; $res .= ''; - $res .= ''; + $res .= ''; $res .= '
' . $weather['backyard_temp'] . ' °C' . $weather['backyard_humidity'] . '%
' . $weather['wc_temp'] . ' °C' . $weather['wc_humidity'] . '%' . $weather['bedroom_temp'] . ' °C' . $weather['bedroom_humidity'] . '%
' . $weather['bathroom_temp'] . ' °C' . $weather['bathroom_humidity'] . '%' . $weather['cellar_temp'] . ' °C' . $weather['cellar_humidity'] . '%
+ +' . $weather['cocodrilo_min'] . ' / ' . $weather['cocodrilo_max'] . ' °C' . $weather['cocodrilo_humidity'] . '%
'; $res .= '
'; $res .= '
';