I started working with displays in ESPHome recently and I’m trying to display temperature and humidity and something struck me. It turns out that the degree symbol (°) is not valid YAML syntax and generates this error:
INFO Reading configuration /config/esphome/eatery.yaml...
ERROR Error while reading config: Invalid YAML syntax. Please see YAML syntax reference or use an online YAML syntax validator:
Error reading file /config/esphome/eatery.yaml: 'utf-8' codec can't decode byte 0xb0 in position 2691: invalid start byte
This shows up when I have a degree symbol for displaying the temperature in degree’s Fahrenheit:
display:
- platform: ssd1306_i2c
model: "SH1106 128x64"
address: 0x3C
id: my_display
pages:
- id: blank_page
lambda: |-
it.print(0, 0, id(my_small_font), "");
- id: content_page
lambda: |-
it.line(0, 0, 127, 0);
it.line(0, 0, 0, 63);
it.line(127, 0, 127, 63);
it.line(0, 63, 127, 63);
it.printf(0, 10, id(my_small_font), "The Eatery! %.0f°F %.0f%%", id(${name}_temperature).state, id(${name}_humidity).state);
it.printf(5, 25, id(my_big_font), "Jade: %.0f%%", id(jade_plant_moisture).state);
it.printf(5, 50, id(my_big_font), "Ugly: %.0f%%", id(ugly_plant_moisture).state);
I’ve tried all of these degree symbols and none of them work.
alt-0176 – °
alt-167 – º
alt-248 – °
However, something very interesting is that when I validate an ESPHome yaml file with a display and a font it generates a list of “supported characters” and the last character in the list is a degree symbol!!
....
font:
- file: comic.ttf
id: my_big_font
size: 22
glyphs:
- ' '
- '!'
- '"'
- '%'
- (
- )
- +
- ','
- '-'
- .
- '0'
- '1'
- '2'
- '3'
- '4'
- '5'
- '6'
- '7'
- '8'
- '9'
- ':'
- A
- B
- C
- D
- E
- F
- G
- H
- I
- J
- K
- L
- M
- N
- O
- P
- Q
- R
- S
- T
- U
- V
- W
- X
- Y
- Z
- _
- a
- b
- c
- d
- e
- f
- g
- h
- i
- j
- k
- l
- m
- n
- o
- p
- q
- r
- s
- t
- u
- v
- w
- x
- y
- z
- °
- file: comic.ttf
id: my_small_font
size: 10
glyphs:
- ' '
- '!'
- '"'
- '%'
- (
- )
- +
- ','
- '-'
- .
- '0'
- '1'
- '2'
- '3'
- '4'
- '5'
- '6'
- '7'
- '8'
- '9'
- ':'
- A
- B
- C
- D
- E
- F
- G
- H
- I
- J
- K
- L
- M
- N
- O
- P
- Q
- R
- S
- T
- U
- V
- W
- X
- Y
- Z
- _
- a
- b
- c
- d
- e
- f
- g
- h
- i
- j
- k
- l
- m
- n
- o
- p
- q
- r
- s
- t
- u
- v
- w
- x
- y
- z
- °
display:
- platform: ssd1306_i2c
model: SH1106_128X64
address: 0x3C
id: my_display
pages:
- id: blank_page
lambda: !lambda |-
it.print(0, 0, id(my_small_font), "");
- id: content_page
lambda: !lambda |-
it.line(0, 0, 127, 0);
it.line(0, 0, 0, 63);
it.line(127, 0, 127, 63);
it.line(0, 63, 127, 63);
it.printf(0, 10, id(my_small_font), "The Eatery! %.0f'F %.0f%%", id(eatery_temperature).state, id(eatery_humidity).state);
it.printf(5, 25, id(my_big_font), "Jade: %.0f%%", id(jade_plant_moisture).state);
it.printf(5, 50, id(my_big_font), "Ugly: %.0f%%", id(ugly_plant_moisture).state);
brightness: 1.0
update_interval: 1s
Is there an ESPHome-safe way to use special symbols like that; similar to how HTML has &
and other characters that would mess up the interpreter? I’d really like to use the degree symbol, I recently got a weather station setup and it tells me wind direction, I’d like to define it in degrees of direction but it chokes on that symbol too.
Thanks,
-Greg