Replace point to comma in ESPHome on ST7798v 320x240 display

Hi,

I’m struggling for days to try to replace point to comma on my display. I get a value as British and American English notation 1.0734 and want to have the European notation with a comma 1,0734.

I would appreciate some help to solve this issue because this is driving me mad :sweat_smile:.

My code:

  platform: esp32
  board: esp32-c3-devkitm-1

  on_boot:
    priority: 200
    then:
      - light.turn_on:
          id: display_backlight
          brightness: 75%

# Enable logging
logger:
  logs:
    component: ERROR

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxxxxxxxxxx"

ota:
  password: "xxxxxxxxxxxxxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true
  manual_ip:
    static_ip: 192.168.178.44
    gateway: 192.168.178.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp32-Mini-Display"
    password: "xxxxxxxxxxxxxx"

captive_portal:

# =========================== #

# Display ST7789V 320 x 240
# Vcc 3V3
# GND GND
# SCL GPIO9
# SDA GPIO6
# RES GPIO5
# DC  GPIO3
# CS  GPIO4
# BLK GPIO7

status_led:

  pin:
    number: GPIO8
    inverted: true

sensor:

  - platform: wifi_signal
    name: "WiFi ESP32 Mini Display"
    update_interval: 60s

  - platform: internal_temperature
    name: "ESP32 Mini Display Temperature"
    unit_of_measurement: °C
    accuracy_decimals: 0
    update_interval: 60s

  - platform: homeassistant
    id: ha_processor
    entity_id: sensor.system_monitor_processor_use
    internal: true

  - platform: homeassistant
    id: ha_memory
    entity_id: sensor.home_assistant_core_memory_percent
    internal: true

  - platform: homeassistant
    id: ha_disk
    entity_id: sensor.system_monitor_disk_usage_percent
    internal: true

  - platform: homeassistant
    id: cpu_temperature
    entity_id: sensor.system_monitor_processortemperatuur
    internal: true

  - platform: homeassistant
    id: lan_temperature
    entity_id: sensor.lan_temperature
    internal: true

  - platform: homeassistant
    id: i_download
    entity_id: sensor.speedtest_download
    internal: true

  - platform: homeassistant
    id: i_upload
    entity_id: sensor.speedtest_upload
    internal: True

  - platform: homeassistant
    id: i_ping
    entity_id: sensor.speedtest_ping
    internal: true

  - platform: homeassistant
    id: euro_price
    entity_id: sensor.euro_price
    internal: true

  - platform: homeassistant
    id: euro_change
    entity_id: sensor.euro_change_24h
    internal: true

time:

  - platform: homeassistant
    id: ha_time

output:

  - platform: ledc
    pin: GPIO7
    id: GPIO7

light:

  - platform: monochromatic
    id: display_backlight
    output: GPIO7
    name: "Display Backlight"

binary_sensor:

  - platform: homeassistant
    id: lan_door
    entity_id: switch.lan_door_switch
    internal: true

  - platform: homeassistant
    id: rpi_fan
    entity_id: switch.rpi_cooling_fan
    internal: true

font:

  - file: 'DejaVuSans-Bold.ttf'
    id: font1
    size: 12
    extras:
      - file: "DejaVuSans-Bold.ttf"
        glyphs: [$,€]

  - file: 'DejaVuSans-Bold.ttf'
    id: font2
    size: 16

color: # RGB

  - id: white
    hex: '808080'

  - id: orange
    hex: ff8c00

  - id: red
    hex: cc0000

  - id: dark_blue
    hex: '000033'

  - id: blue
    hex: 0066cc

  - id: green
    hex: '009900'

spi:

  clk_pin: GPIO9
  mosi_pin: GPIO6

display:

  - platform: st7789v
    id: esp32_st7798v_display
    model: Custom
    width: 240
    height: 320
    offset_height: 0
    offset_width: 0
    rotation: 0
    eightbitcolor: true
    cs_pin: GPIO4
    dc_pin: GPIO3
    reset_pin: GPIO5

    pages:

    - id: page01
      lambda: |-
      
        it.printf(0, 10, id(font1), white, TextAlign::BASELINE_LEFT, "SSD Drive");
        if ((id(ha_disk).state) > 0 and (id(ha_disk).state) <= 60) {
          it.printf(240, 10, id(font1), white, TextAlign::BASELINE_RIGHT, "%.0f %%", id(ha_disk).state);
        }
        if ((id(ha_disk).state) > 60 and (id(ha_disk).state) <= 80) {
          it.printf(240, 10, id(font1), orange, TextAlign::BASELINE_RIGHT, "%.0f %%", id(ha_disk).state);
        }
        if ((id(ha_disk).state) >80 ) {
          it.printf(240, 10, id(font1), red, TextAlign::BASELINE_RIGHT, "%.0f %%", id(ha_disk).state);
        }

        it.printf(0, 25, id(font1), white, TextAlign::BASELINE_LEFT, "CPU Usage");
        if ((id(ha_processor).state) >= 0 and (id(ha_processor).state) < 10) {
          it.printf(240, 25, id(font1), white, TextAlign::BASELINE_RIGHT, "%.0f %%", id(ha_processor).state);
        }
        if ((id(ha_processor).state) >= 10 and (id(ha_processor).state) <= 50) {
          it.printf(240, 25, id(font1), white, TextAlign::BASELINE_RIGHT, "%.0f %%", id(ha_processor).state);
        }
        if ((id(ha_processor).state) > 50 and (id(ha_processor).state) <= 75) {
          it.printf(240, 25, id(font1), orange, TextAlign::BASELINE_RIGHT, "%.0f %%", id(ha_processor).state);
        }
        if ((id(ha_processor).state) > 72 ) {
          it.printf(240, 25, id(font1), red, TextAlign::BASELINE_RIGHT, "%.0f %%", id(ha_processor).state);
        }          

        it.printf(0, 40, id(font1), white, TextAlign::BASELINE_LEFT, "Memory Usage");
        if ((id(ha_memory).state) >= 0 and (id(ha_memory).state) < 10) {
          it.printf(240, 40, id(font1), white, TextAlign::BASELINE_RIGHT, "%.0f %%", id(ha_memory).state);
        }
        if ((id(ha_memory).state) >= 10 and (id(ha_memory).state) <= 50) {
          it.printf(240, 40, id(font1), white, TextAlign::BASELINE_RIGHT, "%.0f %%", id(ha_memory).state);
        }
        if ((id(ha_memory).state) > 50 and (id(ha_memory).state) <= 75) {
          it.printf(240, 40, id(font1), orange, TextAlign::BASELINE_RIGHT, "%.0f %%", id(ha_memory).state);
        }
        if ((id(ha_memory).state) > 72 ) {
          it.printf(240, 40, id(font1), red, TextAlign::BASELINE_RIGHT, "%.0f %%", id(ha_memory).state);
        }   

        it.printf(0, 55, id(font1), white, TextAlign::BASELINE_LEFT, "CPU Temperature");
        if ((id(cpu_temperature).state) > 0 and (id(cpu_temperature).state) <= 60) {
          it.printf(240, 55, id(font1), white, TextAlign::BASELINE_RIGHT, "%.0f °C", id(cpu_temperature).state);
        }
        if ((id(cpu_temperature).state) > 60 and (id(cpu_temperature).state) <= 65) {
          it.printf(240, 55, id(font1), orange, TextAlign::BASELINE_RIGHT, "%.0f °C", id(cpu_temperature).state);
        }
        if ((id(cpu_temperature).state) > 65 ) {
          it.printf(240, 55, id(font1), red, TextAlign::BASELINE_RIGHT, "%.0f °C", id(cpu_temperature).state);
        } 

        it.printf(0, 70, id(font1), white, TextAlign::BASELINE_LEFT, "LAN Temperature");
        if ((id(lan_temperature).state) > 0 and (id(lan_temperature).state) <= 32.5) {
          it.printf(240, 70, id(font1), white, TextAlign::BASELINE_RIGHT, "%.0f °C", id(lan_temperature).state);
        }
        if ((id(lan_temperature).state) > 32.5 and (id(lan_temperature).state) <= 35) {
          it.printf(240, 70, id(font1), orange, TextAlign::BASELINE_RIGHT, "%.0f °C", id(lan_temperature).state);
        }
        if ((id(lan_temperature).state) > 35 ) {
          it.printf(240, 70, id(font1), red, TextAlign::BASELINE_RIGHT, "%.0f °C", id(lan_temperature).state);
        }

        it.printf(0, 100, id(font1), white, TextAlign::BASELINE_LEFT, "RPi FAN");
        if (id(rpi_fan).state) {
          it.printf(240, 100, id(font1), blue, TextAlign::BASELINE_RIGHT, "ON", id(rpi_fan).state);
        } else {
          it.printf(240, 100, id(font1), white, TextAlign::BASELINE_RIGHT, "Off", id(rpi_fan).state);
        }

        it.printf(0, 115, id(font1), white, TextAlign::BASELINE_LEFT, "LAN Door");
        if (id(lan_door).state) {
          it.printf(240, 115, id(font1), blue, TextAlign::BASELINE_RIGHT, "OPEN", id(lan_door).state);
        } else {
          it.printf(240, 115, id(font1), white, TextAlign::BASELINE_RIGHT, "Closed", id(lan_door).state);
        }

        it.printf(0, 145, id(font1), white, TextAlign::BASELINE_LEFT, "Download Speed");
        if ((id(i_download).state) >= 100 ) {
          it.printf(240, 145, id(font1), white, TextAlign::BASELINE_RIGHT, "%.0f Mbps", id(i_download).state);
        }
        if ((id(i_download).state) < 100 and (id(i_download).state) >= 80) {
          it.printf(240, 145, id(font1), orange, TextAlign::BASELINE_RIGHT, "%.0f Mbps", id(i_download).state);
        }
        if ((id(i_download).state) < 80 ) {
          it.printf(240, 145, id(font1), red, TextAlign::BASELINE_RIGHT, "%.0f Mbps", id(i_download).state);
        }

        it.printf(0, 160, id(font1), white, TextAlign::BASELINE_LEFT, "Upload Speed");
        if ((id(i_upload).state) >= 100 ) {
          it.printf(240, 160, id(font1), white, TextAlign::BASELINE_RIGHT, "%.0f Mbps", id(i_upload).state);
        }
        if ((id(i_upload).state) <= 100 and (id(i_upload).state) >= 80) {
          it.printf(240, 160, id(font1), orange, TextAlign::BASELINE_RIGHT, "%.0f Mbps", id(i_upload).state);
        }
        if ((id(i_upload).state) < 80 ) {
          it.printf(240, 160, id(font1), red, TextAlign::BASELINE_RIGHT, "%.0f Mbps", id(i_upload).state);
        }

        it.printf(0, 175, id(font1), white, TextAlign::BASELINE_LEFT, "Ping Time");
        if ((id(i_ping).state) > 0 and (id(i_ping).state) <= 30 ) {
          it.printf(240, 175, id(font1), white, TextAlign::BASELINE_RIGHT, "%.0f ms", id(i_ping).state);
        }
        if ((id(i_ping).state) > 30 and (id(i_ping).state) <= 60) {
          it.printf(240, 175, id(font1), orange, TextAlign::BASELINE_RIGHT, "%.0f ms", id(i_ping).state);
        }
        if ((id(i_ping).state) > 60 ) {
          it.printf(240, 175, id(font1), red, TextAlign::BASELINE_RIGHT, "%.0f ms", id(i_ping).state);
        }

        it.printf(0, 205, id(font1), white, TextAlign::BASELINE_LEFT, "EUR/USD");
        it.printf(100, 205, id(font1), white, TextAlign::BASELINE_LEFT, "%$ %.4f", id(euro_price).state);
        if ((id(euro_change).state) >= 0 ) {
          it.printf(240, 205, id(font1), green, TextAlign::BASELINE_RIGHT, "%.1f %%", id(euro_change).state);
        } else {
          it.printf(240, 205, id(font1), red, TextAlign::BASELINE_RIGHT, "%.1f %%", id(euro_change).state);
        }

        it.strftime(120, 300, id(font2), green, TextAlign::CENTER, "%a %d-%m-%Y %H:%M", id(ha_time).now());

My display:

Thanks in advance.

Apparently it’s not easy. I’ve previously tried using std::setlocale(LC_ALL, "de_DE.UTF-8"), but couldn’t get it to work.

A workaround could be to import the HA sensor as a text_sensor and use the substitute filter to replace the point with a comma. You would, of course, have to adjust your printing accordingly.

I’m on my phone, so I can’t test whether this actually would work.

Thanks, I got the correct notation now :+1:t3:

part of code which I changed:

sensor:

  - platform: homeassistant
    id: euro_price
    entity_id: sensor.euro_price
    internal: true

  - platform: homeassistant
    id: euro_change
    entity_id: sensor.euro_change_24h
    internal: true

text_sensor:

  - platform: homeassistant
    id: euro_price_txt
    entity_id: sensor.euro_price
    filters:
      - substitute:
        - ". -> ," # point to comma

  - platform: homeassistant
    id: euro_change_txt
    entity_id: sensor.euro_change_24h
    filters:
      - substitute:
        - ". -> ," # point to comma
        - "- -> "  # minus sign to space because negative is red color

font:

  - file: 'DejaVuSans-Bold.ttf'
    id: font1
    size: 12
    extras:
      - file: "DejaVuSans-Bold.ttf"
        glyphs: [$,€]

color: # RGB

  - id: red
    hex: cc0000

  - id: green
    hex: '009900'

spi:

  clk_pin: GPIO9
  mosi_pin: GPIO6

display:

  - platform: st7789v
    id: esp32_st7798v_display
    model: Custom
    width: 240
    height: 320
    offset_height: 0
    offset_width: 0
    rotation: 0
    eightbitcolor: true
    cs_pin: GPIO4
    dc_pin: GPIO3
    reset_pin: GPIO5

    pages:

    - id: page01
      lambda: |-

        it.printf(0, 205, id(font1), white, TextAlign::BASELINE_LEFT, "EUR/USD");
        it.printf(100, 205, id(font1), white, TextAlign::BASELINE_LEFT, "$ %s", id(euro_price_txt).state.c_str());
        if ((id(euro_change).state) > 0 ) {
          it.printf(240, 205, id(font1), green, TextAlign::BASELINE_RIGHT, "%s %%", id(euro_change_txt).state.c_str());
        } else {
          it.printf(240, 205, id(font1), red, TextAlign::BASELINE_RIGHT, "%s %%", id(euro_change_txt).state.c_str());
        }
1 Like