On ne sait jamais cela pourra peut être servir à d’autre.
Ci dessous un code qui fonctionne pour moi :
lambda: |-
char *strCopy = strdup( id(Pluie).state.c_str() );
char delim[] = ",";
char *prochain;
prochain = strtok(strCopy, delim);
int y = 16;
it.printf(64, 0, id(font4), TextAlign::TOP_CENTER, "Next Rain");
bool pluieTrouvee = false;
while ( prochain != NULL ) {
if (strstr(prochain, "Pluie") != NULL) {
it.printf( 5, y, id(font1), " %s", prochain );
y += 14;
pluieTrouvee = true;
}
prochain = strtok(NULL, delim);
}
if (!pluieTrouvee) {
it.printf( 64, 52, id(font6), TextAlign::BASELINE_CENTER, " Pas de pluie" );
}
Sur la base du Text_Sensor
text_sensor:
- platform: homeassistant
name: "NextRain"
entity_id: sensor.la_jarrie_next_rain
id: Pluie
attribute: 1_hour_forecast
filters:
- substitute:
- "' -> "
- "{ -> "
- "} -> "
Il y a certainement moyen de faire plus propre ou autrement mais je n’ai pas trouvé
Bonne soirée
EDIT : modification du code. toujours la même base mais je saturai la mémoire et l’ESP se déconnectait
lambda: |-
std::string strCopy = id(Pluie).state;
std::string delim = ",";
size_t pos = 0;
int y = 16;
int i = 0;
it.printf(64, 0, id(font4), TextAlign::TOP_CENTER, "Next Rain");
bool pluieTrouvee = false;
while ((pos = strCopy.find(delim)) != std::string::npos && i < 20) {
std::string prochain = strCopy.substr(0, pos);
if (prochain.find("Pluie") != std::string::npos) {
i++;
it.printf( 2, y, id(font1), " %s", prochain.c_str() );
y += 16;
pluieTrouvee = true;
delay(100);
}
strCopy.erase(0, pos + delim.length());
delay(100);
}
if (!pluieTrouvee) {
it.printf( 64, 52, id(font6), TextAlign::BASELINE_CENTER, " Pas de pluie" );
}