'model' is a required option for [display.st7789v]?

Hi all and HNY.

A while back I built a little ESP32 based CO2 sensor from a project I found on the Web but after upgrading ESPHome to use BT Proxies it tells me that the node needs updating but when I try it comes up with the error on the title of the post?

Now I’m not a coder and it is currently working now so I’m frightened anything I do to try to fix it will actually break it so I would be grateful if someone could help me out here please?

Could someone remind me how to post code here and confirm if doing so would be ok please?

Best than would be to consult the documentation about the component that throws the error - in yur case the st7789 :point_down:

model (Required, string): The display model to use.

So indeed you need to define a model in your esphome yaml. :point_up:

Sure, this post explains everything in detail :point_down:

Thanks very much for that orange-assistant.

The problem for me is I think I have some level of code-blindness, I really (and I’ve tried many times over the years) can’t seem to get to grips with it and at 66 I think it’s way past hoping it will happen now. ;-(

So I look at the code and maybe I’ve got ADHD, discalcula or some dyslexia but it rarely makes any sense. ;-(

I can generally follow a good walkthrough and can still do simple electronics design and my soldering is still pretty good, but coding it really is just like an alien language. ;-(

So unless the manual / instructions had exact and working examples of exactly what I need to do, the chances are it would never compile because of something obvious to many but completely transparent to me.

So I love the whole HA / ESP32 thing and I can sometimes get lucky and find some code that I can just tweak to suit my needs but unless I can, I’m beholden to those for whom it’s second nature and in the hope that I can repay them or others via something I can actually do. :wink:

Anyroadup, in the hope that this works and someone wouldn’t mind sorting it for me, this is my current code:

esphome:
  name: co2-sensor-2
  platform: ESP32
  board: "featheresp32"  

# Enable Home Assistant API
api:

ota:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
  #  use_address: 192.168.0.207
  
  manual_ip:
   static_ip: 192.168.0.198
   gateway: 192.168.0.100
   subnet: 255.255.255.0      
  

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Co2-Sensor-2 Fallback Hotspot"
    password: "munged"

captive_portal:

logger:

# CO2 sensor
uart:
  rx_pin: 27
  tx_pin: 26
  baud_rate: 9600

# Dipslay driver: ST7789
spi:
  clk_pin: GPIO18
  mosi_pin: GPIO19

font:
  - file: "Oswald-Light.ttf"
    id: font_70
    size: 70
    glyphs: 0123456789 # Only used for CO2 level

  - file: "Oswald-Light.ttf"
    id: font_30
    size: 30

color:
  - id: color_black
    red: 0%
    green: 0%
    blue: 0%
    white: 0%
  - id: color_green
    red: 0%
    green: 100%
    blue: 0%
  - id: color_yellow
    red: 100%
    green: 100%
    blue: 0%
  - id: color_orange
    red: 100%
    green: 55%
    blue: 0%
  - id: color_red
    red: 100%
    green: 0%
    blue: 0%
  - id: color_white
    red: 100%
    green: 100%
    blue: 100%

display:
  - platform: st7789v
    id: my_display
    backlight_pin: GPIO4
    cs_pin: GPIO5
    dc_pin: GPIO16
    reset_pin: GPIO23
    brightness: 100%
    rotation: 90
    pages:
      # Page 1: Current CO2 levels
      #    0    - 1000 -> Green
      #    1000 - 1600 -> Yellow
      #    1600 - 2000 -> Orange
      #    >2000       -> Red
      - id: page1
        lambda: |-
          if(!id(co2_sensor_2).has_state() ){
            it.print(
              it.get_width()/2,
              it.get_height()/2,
              id(font_70),
              color_white,
              TextAlign::CENTER,
              "Starting..."
            );
            return;
          }
         
          auto bg_color = id(color_black);
          auto text_color = id(color_green);
          auto co2 = id(co2_sensor_2).state;
          if(co2 > 1000) text_color = id(color_yellow);
          if(co2 > 1600) text_color = id(color_orange);
          if(co2 > 2000){
            text_color = id(color_white);
            bg_color = id(color_red);
          }
          it.filled_rectangle(0, 0, it.get_width(), it.get_height(), bg_color);
          it.printf(
            it.get_width()/2, 
            it.get_height()/2, 
            id(font_70), 
            text_color, 
            TextAlign::CENTER, 
            "%.0f",
            co2
          );
      # Page 2: WiFi information
      - id: page2
        lambda: |-
          it.print(
            0, 0,
            id(font_30),
            id(color_white),
            "WiFi details"
          );
          it.printf(
            0, 30,
            id(font_30),
            id(color_white),
            "%s",
            id(wifi_ssid).state.c_str()
          );
          it.printf(
            0, 60,
            id(font_30),
            id(color_white),
            "%s",
            id(wifi_ip_addr).state.c_str()
          );
switch:
  - platform: gpio
    pin: GPIO4
    id: backlight
    internal: true

sensor:
  - platform: mhz19
    co2:
      name: "CO2 Sensor 2"
      id: "co2_sensor_2"
    temperature:
      name: "CO2 sensor 2 temperature"
      internal: true
    update_interval: 60s
    automatic_baseline_calibration: false
    
  - platform: wifi_signal
    name: "CO2 sensor 2 WiFi"
    update_interval: 60s   

text_sensor:
  - platform: wifi_info
    ip_address:
      internal: true
      id: wifi_ip_addr
    ssid:
      internal: true
      id: wifi_ssid

binary_sensor:
  # Button to cycle through pages on the display
  - platform: gpio
    pin:
      number: GPIO35
      inverted: true
    id: button_1
    on_click:
      then:
        - display.page.show_next: my_display
        - component.update: my_display

  # Button to toggle the backlight (for use at night)
  - platform: gpio
    pin:
      number: GPIO0
      inverted: true
    id: button_2
    on_click:
      then:
        - switch.toggle: backlight
        
button:
  - platform: restart
    name: "CO2 sensor 2 restart"       

This is the error message I get when I try to update (or verify).

INFO Reading configuration /config/esphome/co2-sensor-2.yaml...
WARNING GPIO0 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
Failed config

display.st7789v: [source /config/esphome/co2-sensor-2.yaml:81]
  
  'model' is a required option for [display.st7789v].
  platform: st7789v
  id: my_display
  backlight_pin: GPIO4
  cs_pin: GPIO5
  dc_pin: GPIO16
  reset_pin: GPIO23
  
  [brightness] is an invalid option for [display.st7789v]. Please check the indentation.
  brightness: 100%
  rotation: 90
  pages: 
    - id: page1
      lambda: |-
        if(!id(co2_sensor_2).has_state() ){
          it.print(
            it.get_width()/2,
            it.get_height()/2,
            id(font_70),
            color_white,
            TextAlign::CENTER,
            "Starting..."
          );
          return;
        }
        
        auto bg_color = id(color_black);
        auto text_color = id(color_green);
        auto co2 = id(co2_sensor_2).state;
        if(co2 > 1000) text_color = id(color_yellow);
        if(co2 > 1600) text_color = id(color_orange);
        if(co2 > 2000){
          text_color = id(color_white);
          bg_color = id(color_red);
        }
        it.filled_rectangle(0, 0, it.get_width(), it.get_height(), bg_color);
        it.printf(
          it.get_width()/2, 
          it.get_height()/2, 
          id(font_70), 
          text_color, 
          TextAlign::CENTER, 
          "%.0f",
          co2
        );
    - id: page2
      lambda: |-
        it.print(
          0, 0,
          id(font_30),
          id(color_white),
          "WiFi details"
        );
        it.printf(
          0, 30,
          id(font_30),
          id(color_white),
          "%s",
          id(wifi_ssid).state.c_str()
        );
        it.printf(
          0, 60,
          id(font_30),
          id(color_white),
          "%s",
          id(wifi_ip_addr).state.c_str()
        );

Well, that was a bit of luck!

I got the display example page and my current code side by side and gave it a go …

I first commented out the ‘Brightness’ on the grounds it said it was either not wanted or not aligned properly. That cleared one error. :wink:

I then added (I thought I was going to have to replace something and so have to deal with all the alignment sensitive stuff) the model line from the example, saved and it verified and upgraded ok! :wink:

Thanks for that, I got away with it this time and now I can get back to trying to get BT Proxies to work via my ESP32 cards … :wink:

1 Like

Create you sorted it out faster I could answer :stuck_out_tongue:

If any one else stumbles across this the problem it was the missing model: under the st7789v platform :point_down:

It was also the ‘Brightness’ field that wasn’t wanted in there apparently?

display:
  - platform: st7789v
    model: TTGO TDisplay 135x240  # added bit
    id: my_display
    backlight_pin: GPIO4
    cs_pin: GPIO5
    dc_pin: GPIO16
    reset_pin: GPIO23
 #   brightness: 100%

I have no idea if the rest of it is considered acceptable coding but I’m grateful to the original coder as I wouldn’t have a clue how to do all that! :wink:

To me it’s all like a game of chess (something else I’ve never got into) but where the instructions are in a foreign language and the rules keep changing! ;-(

Luckily though, I’ve learned not to take on a new HA addon unless I’ve checked someone has already posted a known working solution. Standing on the shoulders of giants etc.

I have a mate who now has a HA system because I was willing to help him and that’s my chance of being able to share what I’ve learned. I can also design and print cases for the projects I help him with. :wink: