PARTAGE prévisions nombres d'heures de soleil sur 7 jours en PHP

Parfait.
Merci beaucoup.

1 « J'aime »

non en fonction de l’heure,il est 13:05
image

// ────────────────────────────────────────────────
// 2. Tableau détaillé aujourd'hui (three-hourly-view)
// ────────────────────────────────────────────────
if ($detailJour){
  $today_content = "<p style='color:#f66;font-weight:bold;margin:0;padding:0;'>Tableau horaire introuvable</p>";

  $three_hourly = $xpath->query("//table[contains(@class,'picto') and contains(@class,'three-hourly-view')]");

  if ($three_hourly->length > 0) {
      $tbl = $three_hourly->item(0);

      $time_cells  = $xpath->query(".//tr[contains(@class,'times')]//td", $tbl);
      $icon_cells  = $xpath->query(".//tr[contains(@class,'icons')]//img", $tbl);
      $temp_cells  = $xpath->query(".//tr[contains(@class,'temperatures')]//td//div[contains(@class,'cell')]", $tbl);
      $feel_cells  = $xpath->query(".//tr[contains(@class,'windchills')]//td//div[contains(@class,'cell')]", $tbl);
      $wind_cells  = $xpath->query(".//tr[contains(@class,'windspeeds')]//td//div[contains(@class,'cell')]", $tbl);
      $dir_cells   = $xpath->query(".//tr[contains(@class,'winddirs')]//td//div[contains(@class,'winddir')]", $tbl);
      $pluie_cells = $xpath->query(".//tr[contains(@class,'precipprobs')]//td//span[contains(@class,'precip-prob')]", $tbl);
      $pluie_mm    = $xpath->query(".//tr[contains(@class,'precips')]//td//div[contains(@class,'cell')]//span", $tbl);

      $today_content = '<div style="margin:0;padding:0;max-width:100%;overflow-x:auto;">'
                     . '<table style="width:100%;max-width:100%;border-collapse:collapse;font-size:12px;text-align:center;margin:0;padding:0;border-spacing:0;">'
                     . '<thead><tr style="background:#2c2c2c;color:#eee;">'
                     . '<th style="padding:4px 3px;font-size:11px;text-align=center;">Heure</th>'
                     . '<th style="padding:4px 3px;font-size:11px;text-align=center;">Icône</th>'
                     . '<th style="padding:4px 3px;font-size:11px;text-align=center;">Temp</th>'
                     . '<th style="padding:4px 3px;font-size:11px;text-align=center;">Ressenti</th>'
                     . '<th style="padding:4px 6px;font-size:9px;text-align=center;">Vent(km/h)</th>'
                     . '<th style="padding:4px 3px;font-size:11px;text-align=center;">Pluie</th>'
                     . '<th style="padding:4px 3px;font-size:11px;text-align=center;">(mm)</th>'
                     . '</tr></thead><tbody>';

      $slots = min(8, $time_cells->length);

      for ($i = 0; $i < $slots; $i++) {
          $h_node = $xpath->query(".//time", $time_cells->item($i))->item(0);
          $h = $h_node ? trim($h_node->textContent) : '?';

          // Transformation du format horaire
if ($h === '0300') {
    $h = '0-3h';
} elseif ($h === '0600') {
    $h = '3-6h';
} elseif ($h === '0900') {
    $h = '6-9h';
} elseif ($h === '1200') {
    $h = '9-12h';
} elseif ($h === '1500') {
    $h = '12-15h';
} elseif ($h === '1800') {
    $h = '15-18h';
} elseif ($h === '2100') {
    $h = '18-21h';
} elseif ($h === '2400') {
    $h = '21-24h';
}

// Ajout de ">> " devant le créneau horaire en cours
$heureActuelle = intval(date('H')); // heure actuelle (0-23)
$h_prefix = ''; // pas de >> par défaut

if ($h === '0-3h'   && $heureActuelle >= 0  && $heureActuelle < 3)  $h_prefix = '➡ ';
if ($h === '3-6h'   && $heureActuelle >= 3  && $heureActuelle < 6)  $h_prefix = '➡ ';
if ($h === '6-9h'   && $heureActuelle >= 6  && $heureActuelle < 9)  $h_prefix = '➡ ';
if ($h === '9-12h'  && $heureActuelle >= 9  && $heureActuelle < 12) $h_prefix = '➡ ';
if ($h === '12-15h' && $heureActuelle >= 12 && $heureActuelle < 15) $h_prefix = '➡ ';
if ($h === '15-18h' && $heureActuelle >= 15 && $heureActuelle < 18) $h_prefix = '➡ ';
if ($h === '18-21h' && $heureActuelle >= 18 && $heureActuelle < 21) $h_prefix = '➡ ';
if ($h === '21-24h' && $heureActuelle >= 21 && $heureActuelle < 24) $h_prefix = '➡ ';

// Mise en évidence du créneau horaire en cours (vert)
if ($h_prefix !== '') {
    $h = "<span style='color:#3CFF3C;font-weight:bold;'>{$h_prefix}{$h}</span>";
} else {
    $h = $h;
}


          $icon = $icon_cells->item($i) ?? null;
          $icon_html = $icon 
              ? '<img src="' . htmlspecialchars($icon->getAttribute('src')) . '" alt="' . htmlspecialchars($icon->getAttribute('alt') ?? '') . '" style="max-width:28px;height:auto;vertical-align:middle;">' 
              : '-';

          $temp     = trim($temp_cells->item($i)->textContent ?? '-');
          $ressenti = trim($feel_cells->item($i)->textContent ?? '-');
          $vent     = trim($wind_cells->item($i)->textContent ?? '-');

          $dir_node = $dir_cells->item($i);
          $dir      = $dir_node ? trim($dir_node->textContent) : '-';

          $pluie    = trim($pluie_cells->item($i)->textContent ?? '0%');
          $pluie_extract_mm  = trim($pluie_mm->item($i)->textContent ?? '0 mm');

          $vent_display = ($vent !== '-' && $dir !== '-') 
              ? $vent . ' ' . wind_arrow($dir) 
              : ($vent !== '-' ? $vent : $dir);

          $moyvent = '-';
          if(preg_match('/(\d+)\s*-\s*(\d+)/', $vent, $matches)) {
              $moyVent = ($matches[1] + $matches[2]) / 2;
          }

          $vent_color = ($moyVent !== '-') ? vent_color($moyVent) : 'rgb(var(--txt-color))';

          $temp_color = ($temp !== '-') ? temp_color($temp) : 'rgb(var(--txt-color))';

          $temp_color_ressenti = ($ressenti !== '-') ? temp_color($ressenti) : 'rgb(var(--txt-color))';

          $pluie_color = pluie_percent($pluie);
          $pluie_mm_color = pluie_bg($pluie_extract_mm);

          $today_content .= '<tr style="border-bottom:1px solid #444;height:32px;margin:0;padding:0;">'
                         .  '<td style="padding:4px 3px;margin:0;">' . $h . '</td>'
                         . '<td style="padding:4px 3px;margin:0;">' . $icon_html . '</td>'
                         . '<td style="padding:4px 3px;margin:0;color:' . $temp_color . '">' . htmlspecialchars($temp) . '</td>'
                         . '<td style="padding:4px 3px;margin:0;color:' . $temp_color_ressenti . '">' . htmlspecialchars($ressenti) . '</td>'
                         . '<td style="padding:4px 3px;margin:0;color:' . $vent_color . '">' . $vent_display . '</td>'
                         . '<td style="padding:4px 3px;margin:0;color:' . $pluie_color . '">' . htmlspecialchars($pluie) . '</td>'
                         . '<td style="padding:4px 3px;margin:0;color:' . $pluie_mm_color . '">' . htmlspecialchars($pluie_extract_mm) . '</td>'
                         . '</tr>';
      }

      $today_content .= '</tbody></table></div>';
      $scenario->setLog("Tableau today complet reconstruit ($slots créneaux)");
  } else {
      $scenario->setLog("Aucun tableau three-hourly-view trouvé");
  }
}

je regarderai ta nouvelle invention ce soir :+1:
merci

Ah c’est pas bête ça, bien vu

J’étudierai ça quand j’aurai plus de temps

super boulot et en plus rien a faire juste un copie colle de ton code

et tout est paramétrable

tout simplement parfais

1 « J'aime »

suite à l’idée de @pj66 (merci :wink: ), j’ai rajouté en plus la double bordure pour que ce soit encore plus visible:

Le fichier:
index.txt (35,4 Ko)

1 « J'aime »

Ce @Noyax37 ; il nous fait un festival …
:clap:
merci

2 « J'aime »

Bonjour, comment faut il faire pour utiliser les informations du nombre d’heure de soleil dans un scenario

je voudrais par exemple récupérer le nombre d’heure de soleil pour plus ou moins charger ma batterie durant la nuit pour le lendemain

actuellement j’utilise déjà solcast pour cette prévision mais je voudrais pouvoir coupler avec valeur

merci

1 « J'aime »

C’est pour ça que j’ai créé une commande « Données Météo JSON » dans l’équipement afin que tu puisses récupérer ce que tu veux

Ça ressemble à ça :

[ { "jour_court": "ven.", "jour_long": "Aujourd'hui", "donnees": { "Vent": "22", "Direction": "SW", "Tmax": "14 °C", "Tmin": "8 °C", "Pluie": "2-5 mm", "Soleil": "0 h" } }, { "jour_court": "sam.", "jour_long": "Demain", "donnees": { "Vent": "20", "Direction": "SW", "Tmax": "12 °C", "Tmin": "7 °C", "Pluie": "0-2 mm", "Soleil": "4 h" } }, { "jour_court": "dim.", "jour_long": "1\/3", "donnees": { "Vent": "14", "Direction": "S", "Tmax": "13 °C", "Tmin": "4 °C", "Pluie": "-", "Soleil": "3 h" } }, { "jour_court": "lun.", "jour_long": "2\/3", "donnees": { "Vent": "15", "Direction": "SE", "Tmax": "18 °C", "Tmin": "4 °C", "Pluie": "-", "Soleil": "8 h" } }, { "jour_court": "mar.", "jour_long": "3\/3", "donnees": { "Vent": "9", "Direction": "SE", "Tmax": "18 °C", "Tmin": "6 °C", "Pluie": "-", "Soleil": "0 h" } }, { "jour_court": "mer.", "jour_long": "4\/3", "donnees": { "Vent": "11", "Direction": "E", "Tmax": "18 °C", "Tmin": "8 °C", "Pluie": "-", "Soleil": "11 h" } }, { "jour_court": "jeu.", "jour_long": "5\/3", "donnees": { "Vent": "12", "Direction": "E", "Tmax": "20 °C", "Tmin": "8 °C", "Pluie": "-", "Soleil": "3 h" } } ]

j’ai bien vue ses infos mais comment j’exploite ses infos
je maitrise pas trop on dirait ce mode de récupération

"[ { "jour_court": "ven.", "jour_long": "Aujourd'hui", "donnees": { "Vent": "33", "Direction": "SW", "Tmax": "13 °C", "Tmin": "8 °C", "Pluie": "5-10 mm", "Soleil": "1 h" } }, { "jour_court": "sam.", "jour_long": "Demain", "donnees": { "Vent": "22", "Direction": "W", "Tmax": "13 °C", "Tmin": "6 °C", "Pluie": "-", "Soleil": "5 h" } }, { "jour_court": "dim.", "jour_long": "1\/3", "donnees": { "Vent": "26", "Direction": "SW", "Tmax": "12 °C", "Tmin": "8 °C", "Pluie": "0-2 mm", "Soleil": "2 h" } }, { "jour_court": "lun.", "jour_long": "2\/3", "donnees": { "Vent": "21", "Direction": "S", "Tmax": "16 °C", "Tmin": "9 °C", "Pluie": "-", "Soleil": "4 h" } }, { "jour_court": "mar.", "jour_long": "3\/3", "donnees": { "Vent": "14", "Direction": "NE", "Tmax": "17 °C", "Tmin": "7 °C", "Pluie": "-", "Soleil": "5 h" } }, { "jour_court": "mer.", "jour_long": "4\/3", "donnees": { "Vent": "15", "Direction": "E", "Tmax": "18 °C", "Tmin": "8 °C", "Pluie": "-", "Soleil": "9 h" } }, { "jour_court": "jeu.", "jour_long": "5\/3", "donnees": { "Vent": "20", "Direction": "SE", "Tmax": "18 °C", "Tmin": "8 °C", "Pluie": "0-2 mm", "Soleil": "6 h" } } ]"
Résultat : "[ { "jour_court": "ven.", "jour_long": "Aujourd'hui", "donnees": { "Vent": "33", "Direction": "SW", "Tmax": "13 °C", "Tmin": "8 °C", "Pluie": "5-10 mm", "Soleil": "1 h" } }, { "jour_court": "sam.", "jour_long": "Demain", "donnees": { "Vent": "22", "Direction": "W", "Tmax": "13 °C", "Tmin": "6 °C", "Pluie": "-", "Soleil": "5 h" } }, { "jour_court": "dim.", "jour_long": "1\/3", "donnees": { "Vent": "26", "Direction": "SW", "Tmax": "12 °C", "Tmin": "8 °C", "Pluie": "0-2 mm", "Soleil": "2 h" } }, { "jour_court": "lun.", "jour_long": "2\/3", "donnees": { "Vent": "21", "Direction": "S", "Tmax": "16 °C", "Tmin": "9 °C", "Pluie": "-", "Soleil": "4 h" } }, { "jour_court": "mar.", "jour_long": "3\/3", "donnees": { "Vent": "14", "Direction": "NE", "Tmax": "17 °C", "Tmin": "7 °C", "Pluie": "-", "Soleil": "5 h" } }, { "jour_court": "mer.", "jour_long": "4\/3", "donnees": { "Vent": "15", "Direction": "E", "Tmax": "18 °C", "Tmin": "8 °C", "Pluie": "-", "Soleil": "9 h" } }, { "jour_court": "jeu.", "jour_long": "5\/3", "donnees": { "Vent": "20", "Direction": "SE", "Tmax": "18 °C", "Tmin": "8 °C", "Pluie": "0-2 mm", "Soleil": "6 h" } } ]"

par exemple comment je recupere la valeur 5 du soleil pour samedi

{ "jour_court": "sam.", "jour_long": "Demain", "donnees": { "Vent": "22", "Direction": "W", "Tmax": "13 °C", "Tmin": "6 °C", "Pluie": "-", "Soleil": "5 h" } }

en gros

si demain soleil compris entre 4 et 6 charge la batterie a 50%

Dans le plugin script tu crées un nouvel équipement, dans cet équipement tu crées une commande avec type script JSON, dans paramètre tu y colles l’URL de la commande JSON de ton équipement météo et dans requête tu y colles 0>donnees>Soleil pour le jour aujourd’hui mais si tu veux demain alors tu mets 1 à la place de 0.

Pour l’URL de ta commande si tu ne sais pas, tu vas dans ton équipement météo et tu vas dans la configuration de ta commande et tu as le lien là :

1 « J'aime »

super merci c’est bon avec ton aide c’est toujours plus facile

1 « J'aime »