ESPHome condition : comparer un preset_mode à une valeur

Bonjour,

Dans le but de permettre le pilotage de mon chauffage sur un ESP32 + écran ili9341 j’ai créé l’interface mais j’ai un souci pour le changement de couleur de l’icon.

Mon text_sensor:

text_sensor:
 
  - platform: homeassistant
    id: preset_mode_sejour
    entity_id: climate.sejour
    attribute: preset_mode

Le touchscreen:

  - platform: touchscreen
    id: touch_key3d
    name: Zone 3d
    x_min: 162
    x_max: 239
    y_min: 0
    y_max: 69
    page_id: page4
    on_press:
    - logger.log: "Bruno"
    - logger.log:
        format: "Situation chauffage  %s and consigne %.1f"
        args: [ 'id(preset_mode_sejour).state.c_str()', 'id(target_temperature_sejour).state' ]
    on_state: 
      if: 
        condition: 
          binary_sensor.is_on: touch_key3d
        then: 
        - homeassistant.service:
            service: climate.set_preset_mode
            data: 
              entity_id: climate.sejour
              preset_mode: eco

Résultat du logger lors de l’appui sur la zone « Eco » alors que je suis sur le preset « home »:

[20:22:40][I][calib:707]: x=200, y=41, x_raw=3205, y_raw=3406
[20:22:40][D][binary_sensor:036]: 'Zone 3d': Sending state ON
[20:22:40][D][main:1348]: Bruno
[20:22:40][D][main:1351]: Situation chauffage  home and consigne 18.0
[20:22:40][D][homeassistant.sensor:022]: 'climate.sejour::temperature': Got attribute state 17.00
[20:22:40][D][sensor:094]: 'target_temperature_sejour': Sending state 17.00000  with 1 decimals of accuracy
[20:22:40][D][homeassistant.text_sensor:015]: 'climate.sejour::preset_mode': Got attribute state 'eco'
[20:22:41][D][text_sensor:064]: 'preset_mode_sejour': Sending state 'eco'
[20:22:41][D][binary_sensor:036]: 'Zone 3d': Sending state OFF

Le display:

      - id: page4
        lambda: |-
          auto red = Color(255, 0, 0);
          auto green = Color(0, 255, 0);
          auto blue = Color(0, 0, 255);
          auto yellow = Color(255, 255, 0);
          auto white = Color(255, 255, 255);
          it.rectangle(0,  0, it.get_width(), it.get_height());
 
          it.rectangle(164, 4, 72, 72, yellow);
          it.print(172, 5, id(my_font12), my_white, "Eco");
          if (id(preset_mode_sejour).state.c_str() == "eco") {
            it.print(170, 14, id(material30), my_orange, "\U000F032A");
          } else{
            it.print(170, 14, id(material30), my_white, "\U000F032A");
          }

Le problème c’est que cette ligne " if (id(preset_mode_sejour).state.c_str() == « eco ») {" ne fonctionne pas, je n’ai pas d’erreur mais pas de changement de couleur de l’icon alors que pour un interrupteur ça fonctionne bien:

          it.rectangle(84, 4, 72, 72, yellow);
          it.print(102, 5, id(my_font12), my_white, "INT");
          if (id(intchauffage).state) {
            it.print(90, 14, id(material30), my_orange, "\U000F0521");
          } else{
            it.print(90, 14, id(material30), my_blue, "\U000F0A19");
          }

Une petite idée ?
Problème de synchro des informations ?

Conf : HAOS à jour

Merci d’avance
Bob

Bonjour,
ca sert a quoi le .c_str() pour id(preset_mode_sejour).state.c_str() ?

j’ai comme toi un peu:

          if (id(door_frigo).state == false) {
            it.printf(200, 112, id(icon_font), Color(0, 255, 0), TextAlign::LEFT, "\U000F081B");
          } else {
            it.printf(200, 112, id(icon_font), Color(255, 0, 0), TextAlign::LEFT, "\U000F081C");
          }
          if (id(power).state >= 1) {
            it.printf(260, 115, id(icon_font_po), Color(255, 0, 0), TextAlign::LEFT, "\U000F0241");
          } else {
            it.printf(260, 115, id(icon_font_po), Color(0, 255, 0), TextAlign::LEFT, "\U000F0243");
          }

Hors sujet, j’utilise OpenHASP c’est bien plus pratique pour ce genre de chose.

Bonsoir @WarC0zes

id(preset_mode_sejour).state.c_str() parce que preset_mode_sejour est un string, pas un ON ou OFF, je vais essayer sans demain :wink:

OpenHASP, j’ai vu passer des sujets là dessus, il faut MQTT ?

Merci pour ta réponse :wink:
Je vais pouvoir rapidement poster sur mes écrans tactiles :slight_smile:

Bob

Ok, beh j’utilise une entité météo france et j’ai pas mis c’est fonction .c_str() et ca fonctionne bien:

          if (id(weather_j0).state == "clear-night") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F0594");
          } else if (id(weather_j0).state == "cloudy") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F0590");
          } else if (id(weather_j0).state == "fog") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F0591");
          } else if (id(weather_j0).state == "hail") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F0592");
          } else if (id(weather_j0).state == "lightning") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F0593");
          } else if (id(weather_j0).state == "lightning-rainy") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F067E");
          } else if (id(weather_j0).state == "partlycloudy") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F0595");
          } else if (id(weather_j0).state == "partlycloudy") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F0595");
          } else if (id(weather_j0).state == "pouring") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F0596");
          } else if (id(weather_j0).state == "rainy") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F0597");
          } else if (id(weather_j0).state == "snowy") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F0598");
          } else if (id(weather_j0).state == "snowy-rainy") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F067F");
          } else if (id(weather_j0).state == "sunny") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F0599");
          } else if (id(weather_j0).state == "windy") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F059D");
          } else if (id(weather_j0).state == "windy-variant") {
            it.printf(4, 25, id(icon_meteo), Color(255, 255, 255), TextAlign::LEFT, "\U000F059E");
          } else {
            it.printf(4, 25, id(icon_font_po), Color(255, 255, 255), TextAlign::LEFT, "\U000F0241");
          }

Oui, c’est par MQTT.

Bonjour,
Merci @WarC0zes, au départ je n’avais pas ajouté .c_str() mais j’ai du m’embrouiller quelque part, sans .c_str() ça fonctionne ce matin, une bonne nuit c’est bon parfois :wink:

Bonne journée
Bob

1 « J'aime »