[ESPHome] Fouten in code voor Display Component

Pagina: 1
Acties:

Vraag


Acties:
  • 0 Henk 'm!

  • hubertgruber
  • Registratie: December 2016
  • Laatst online: 21:16
Na lang te hebben geprutst wordt het wellicht tijd om toch een beetje hulp in te roepen. Met onderstaande .yaml bestand in ESPHome wil ik twee displays, te weten een SSD1306 en een MAX7219 . Daarop wil ik de waardes van de gekoppelde sensoren laten zien, met de volgende code:

YAML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# Modified from code for BMP-280
#
esphome:
  name: esp_ironing_room_monitor_oled
  platform: ESP32
  board: nodemcu-32s
# Turn off screens (OLED + LED) on boot
  on_boot:
    priority: -10
    then:
      - switch.turn_off: LED_switch
      - display.page.show: page0

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "esp ir rm oled Fallback"
    password: !secret backup_password

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: !secret backup_password_2

ota:
  password: !secret backup_password_2

# Sync time with Home Assistant.
time:
  - platform: homeassistant
    id: homeassistant_time

# #Touch sensor
# binary_sensor:
#   - platform: gpio
#     pin: 16
#     name: "Touch sensor"
#     id: touch_sensor
#     internal: true
#     on_press:
#       then:
#         - script.execute: motion_script

# Motion detector
binary_sensor:
 - platform: gpio
   pin: 16
   name: "Ironing room pir"
   device_class: motion
   id: ironing_room_pir
  # # In case of too many false positives: enable this and switch time delay to minimum and jumper to High
    # filters:
    # - delayed_on_off: 360ms
    #  - delayed_on: 3000ms
#Automation for switching on screen on motion detect
#See also https://esphome.io/components/binary_sensor/index.html#on-press
   on_press:
     then:
       - script.execute: motion_script

#Script for the above automation, to incorporate 'restart' mode
script:
  - id: motion_script
    mode: single
    then:
      - display.page.show: page1 
      - switch.turn_on: LED_switch
      - delay: 60s
      - display.page.show: page0
      - switch.turn_off: LED_switch

#For MH-Z19
uart:
  rx_pin: 19
  tx_pin: 18
  baud_rate: 9600
#For MH-Z19B
sensor:
  - platform: mhz19
    co2:
      name: "Ironing room CO2 Value"
      id: co2
      filters:
        - sliding_window_moving_average:
            window_size: 10
            send_every: 10
    temperature:
      name: "Ironing room Temperature backup"
    update_interval: 60s
    automatic_baseline_calibration: false
    id: mhz19_abc
#For BMP-280
  - platform: bmp280
    temperature:
      name: "Ironing room Temperature"
      oversampling: 16x
      id: temperature
    pressure:
      name: "Ironing room Pressure"
      oversampling: 16x
      id: pressure
#    humidity:
#      name: "Ironing room Humidity"
#      oversampling: 16x
    address: 0x76
    i2c_id: bus_b
    update_interval: 60s
    iir_filter: 16x
#    filters:
#      offset: -0.2
#For MH-Z19
switch:
  - platform: template
    name: "MH-Z19 ABC"
    optimistic: true
    on_turn_on:
      mhz19.abc_enable: mhz19_abc
    on_turn_off:
      mhz19.abc_disable: mhz19_abc
  # For virtual internal switch for turning on/off LED display, with help of automation
  - platform: template
    name: "LED switch"
    internal: true
    id: LED_switch

#For i2c buses
i2c:
  #OLED
  - id: bus_a
    sda: 21
    scl: 22
    scan: True
    #frequency: 400khz
  # #BMP280
  - id: bus_b
    sda: 25
    scl: 26
    scan: True

#For SPI (for Digit LED display)
spi:
  clk_pin: 5
  mosi_pin: 17
#  miso_pin: NOT FOR LED DISPLAY

#For OLED display
font:
  - file: 'fonts/slkscr.ttf'
    id: font1
    size: 8

  - file: 'fonts/BebasNeue-Regular.ttf'
    id: font2
    size: 48

  - file: 'fonts/arial.ttf'
    id: font3
    size: 14

  - file: 'fonts/pixelmix.ttf'
    id: font4
    size: 6

display:
# For OLED display
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    i2c_id: bus_a
    id: oled_display
    #rotation: 180°
    brightness: 80%
    #external_vcc: false
    update_interval: 10s
    pages:
      - id: page1
        lambda: |-
          // See https://esphome.io/components/display/index.html#display-engine
          // And https://esphome.io/components/display/index.html#formatted-text
          //it.print(0, 0, id(font), "Hello World!");
          // Print title in top center.
          it.printf(64, 0, id(font1), TextAlign::TOP_CENTER, "Kamer monitor");

          // Print temperature big left
          if (id(temperature).has_state()) {
            it.printf(0, 60, id(font2), TextAlign::BASELINE_LEFT, "%.1f°C", id(temperature).state);
          }
          // Print CO2
          if (id(co2).has_state()) {
            it.printf(127, 23, id(font3), TextAlign::TOP_RIGHT , "%.0fPPM", id(co2).state);
          }
          // Print time
          it.strftime(127, 60, id(font3), TextAlign::BASELINE_RIGHT , "%H:%M", id(homeassistant_time).now);
      - id: page0
        lambda: |-
          // Turn the whole display off
          it.fill(COLOR_OFF);
# For digit LED display
  - platform: max7219digit
    id: digit_led_display
    cs_pin: 12
    num_chips: 4
    intensity: 6
    scroll_enable: true
    scroll_mode: stop
    scroll_delay: 1s
    scroll_dwell: 1s
    lambda: |-
      if (id(LED_switch).state) {
        it.turn_on_off(true);
        it.strftime(0, 0, id(font4), "%H:%M", id(homeassistant_time).now());
        it.print(0,0), id(font4), "Temperature: %1f°C, CO2: %0.f", id(temperature).state, id(co2).state);
      } else {
        it.turn_on_off(false);
      }



# 16 - touch sensor data
# 18 - mhz19 RX pin
# 19 - mhz19 TX pin
# 21 - OLED SDA
# 22 - OLED SCL
# 25 - BMP280 SDA
# 26 - BMP280 SCL

# 5 - LED CLK
# 17 - LED MOSI/DIN
# 12 - LED CS


# OLED: 3.3V or 5V
# MHz19b: 5V
# LED: 3.3V or 5V
# BMP280: 3.3V
# Touch sensor: 3.3V or 5V

# ESP32:
# 1 x 3.3v
# 1 x 5.5v
# 3 x GROUND

# Dedicated grounds: mhz19b & OLED


Voorzover ik kan zien klopt het .yaml gedeelte van de code, maar zijn het de C++ regels voor de Display Component van ESPHome waar ik de mist in ga. Ik krijg bij het compileren in ESPHome namelijk de volgende foutmeldingen:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Compiling /data/esp_ironing_room_monitor_oled/.pioenvs/esp_ironing_room_monitor_oled/src/main.cpp.o
/config/esphome/esp_ironing_room_monitor_oled.yaml: In lambda function:
/config/esphome/esp_ironing_room_monitor_oled.yaml:200:95: error: invalid use of non-static member function
           it.strftime(127, 60, id(font3), TextAlign::BASELINE_RIGHT , "%H:%M", id(homeassistant_time).now);
                                                                                               ^
/config/esphome/esp_ironing_room_monitor_oled.yaml: In lambda function:
/config/esphome/esp_ironing_room_monitor_oled.yaml:219:21: error: no matching function for call to 'esphome::max7219digit::MAX7219Component::print(int, int)'
         it.print(0,0), id(font4), "Temperature: %1f°C, CO2: %0.f", id(temperature).state, id(co2).state);
                     ^
In file included from src/esphome.h:18:0,
                 from src/main.cpp:3:
src/esphome/components/display/display_buffer.h:140:8: note: candidate: void esphome::display::DisplayBuffer::print(int, int, esphome::display::Font*, esphome::Color, esphome::display::TextAlign, const char*)
   void print(int x, int y, Font *font, Color color, TextAlign align, const char *text);
        ^
src/esphome/components/display/display_buffer.h:140:8: note:   candidate expects 6 arguments, 2 provided
src/esphome/components/display/display_buffer.h:150:8: note: candidate: void esphome::display::DisplayBuffer::print(int, int, esphome::display::Font*, esphome::Color, const char*)
   void print(int x, int y, Font *font, Color color, const char *text);
        ^
src/esphome/components/display/display_buffer.h:150:8: note:   candidate expects 5 arguments, 2 provided
src/esphome/components/display/display_buffer.h:160:8: note: candidate: void esphome::display::DisplayBuffer::print(int, int, esphome::display::Font*, esphome::display::TextAlign, const char*)
   void print(int x, int y, Font *font, TextAlign align, const char *text);
        ^
src/esphome/components/display/display_buffer.h:160:8: note:   candidate expects 5 arguments, 2 provided
src/esphome/components/display/display_buffer.h:169:8: note: candidate: void esphome::display::DisplayBuffer::print(int, int, esphome::display::Font*, const char*)
   void print(int x, int y, Font *font, const char *text);
        ^
src/esphome/components/display/display_buffer.h:169:8: note:   candidate expects 4 arguments, 2 provided
*** [/data/esp_ironing_room_monitor_oled/.pioenvs/esp_ironing_room_monitor_oled/src/main.cpp.o]
    Error 1 ========================= [FAILED] Took 21.88 seconds
    =========================


Zouden jullie mij misschien in de juiste richting kunnen duwen voor waar ik moet kijken voor verbetering? Naar mijn weten kloppen de indentaties, maar ik weet het niet meer zeker. Het lastige is dat de ingebouwde ' code checker' van ESPHome niet aanslaat op fouten in de Display Component, dus pas na een halve minuut compileren kan ik zien of een aanpassing heeft gewerkt. Alvast hartelijk dank!

Beste antwoord (via hubertgruber op 31-07-2021 12:35)


  • farlane
  • Registratie: Maart 2000
  • Laatst online: 22:31
id(homeassistant_time).now
Die now lijkt een functie te zijn, dus dat zou dan
id(homeassistant_time).now()
Moeten worden.

Bij
it.print(0,0), id(font4), "Temperature: %1f°C, CO2: %0.f", id(temperature).state, id(co2).state);
Sluit je de functieaanroep naar it.print na de twee coordinaten:
it.print(0,0, id(font4), "Temperature: %1f°C, CO2: %0.f", id(temperature).state, id(co2).state);
Verder heb ik de ballen verstand van ESPHome :P

Somniferous whisperings of scarlet fields. Sleep calling me and in my dreams i wander. My reality is abandoned (I traverse afar). Not a care if I never everwake.

Alle reacties


Acties:
  • Beste antwoord
  • +1 Henk 'm!

  • farlane
  • Registratie: Maart 2000
  • Laatst online: 22:31
id(homeassistant_time).now
Die now lijkt een functie te zijn, dus dat zou dan
id(homeassistant_time).now()
Moeten worden.

Bij
it.print(0,0), id(font4), "Temperature: %1f°C, CO2: %0.f", id(temperature).state, id(co2).state);
Sluit je de functieaanroep naar it.print na de twee coordinaten:
it.print(0,0, id(font4), "Temperature: %1f°C, CO2: %0.f", id(temperature).state, id(co2).state);
Verder heb ik de ballen verstand van ESPHome :P

Somniferous whisperings of scarlet fields. Sleep calling me and in my dreams i wander. My reality is abandoned (I traverse afar). Not a care if I never everwake.


Acties:
  • 0 Henk 'm!

  • hubertgruber
  • Registratie: December 2016
  • Laatst online: 21:16
Hartelijk dank!! Dat was de oplossing! Nu nog even uitvogelen waarom de MAX7219 niets weergeeft ook al wordt hij toch gedetecteerd, maar nu zijn er tenminste geen fouten in de code meer!

Acties:
  • +1 Henk 'm!

  • SA007
  • Registratie: Oktober 2002
  • Laatst online: 23:43

SA007

Moderator Tweaking
Ook al is het opgelost, dit past beter in Domotica.