Clock 12 hour no padding doesn't work

Wondering if anyone knows why %-I does not work. it’s just blank.

%I Works and look like this e.g. 08:00
%-I Is supposed to look like this e.g. 8:00 but I get a blank screen

This works,

    lambda: |-
        it.strftime(33, 0, id(digit_font8), "%I:%M", id(homeassistant_time).now());

This does not.

    lambda: |-
        it.strftime(33, 0, id(digit_font8), "%-I:%M", id(homeassistant_time).now());

This is what I’m using it on.

spi:
  clk_pin: D0
  mosi_pin: D1

display:
  - platform: max7219digit
    id: display_max
    cs_pin: D2
    num_chips: 8
    rotate_chip: 0
    intensity: 0
    scroll_enable: false
    lambda: |-
        it.strftime(33, 0, id(digit_font8), "%-I:%M", id(homeassistant_time).now());

time:
  - platform: homeassistant
    id: homeassistant_time 

font:
  - file: 'pixelmix.ttf'
    id: digit_font8
    size: 8

in ESPhome strftime is kind of like a lite version. It does not have all of the options.

See:

Thanks … :slightly_frowning_face:

Is there any way to remove the padding? Or do we have to live with it?
07:00

Yes there is. :smile:

Easy peizy… lol :slight_smile:

Thank you !!

I thought of a different way of doing it with a HA template sensor that seems to work well.

I have a template sensor from long ago, before HA displayed 12h time format, easily.

HA template sensor:

sensor:
  - platform: template
    sensors:
      12h_time:
        friendly_name: "Readable time" 
        value_template: >
          {% set time = states('sensor.time') %}
          {% set hour = time[:2]|int %}
          {{ '{:2d}:{} {}'.format(hour if hour == 12 else hour % 12, time[3:5], 'PM' if hour>11 else 'AM') }}

And with my esphome config I have:

text_sensor:
  - platform: homeassistant
    name: Readable_time
    entity_id: sensor.12h_time
    id: readable_ha_time


display:
  - platform: ssd1322_spi
    model: "SSD1322 256x64"
    reset_pin: D0
    cs_pin: D8
    dc_pin: D1
    lambda: |-
      // Print time from HA text sensor, 
      it.printf(128, 58, id(font1), TextAlign::BASELINE_CENTER, "%s", id(readable_ha_time).state.c_str());

If it helps.

1 Like

Awesome… Thank you !!

@Akriss @Joe3 any idea on how to replace ‘crossed zeroes’ “0” with ‘capital O’ ? :slight_smile: That would, in addition to no-padding, make my perfect time display on dot matrix;P

And thank you for both ways of modifying string presentation form HA and lambda.

I think the quickest way would to change the font. You are most likely using this font PixelMix Font | dafont.com . That font has a line thru the zero.
There are lot of fonts to try,
This one for example: Dot Matrix Font | dafont.com Has no line thru the zero.

A quick search " dot matrix esphome font" I did on the net shows good results.
One of them has a another suggestion I thought looks nice: Reddit - Dive into anything

Hope it’s of help.