Turning off display with COLOR_OFF

I have an SSD1306 128x64 display and I’m trying to turn it off between 00:00 and 08:00 AM
According to Display Component — ESPHome it should just be it.fill(COLOR_OFF); to turn off but it doesn’t work for me.

Here’s what I am trying:

i2c:
  sda: D1
  scl: D2
  scan: true
display:
  - platform: ssd1306_i2c
    model: "SH1106 128x64"
    lambda: |-
      auto now = id(esptime).now(); // local time
      if (now.hour < 8) {
        it.fill(COLOR_OFF);
      }
      else {
        it.fill(COLOR_ON);
      }
      it.printf(0, 0, id(calibri), "Solar Generation: %s", id(current_solar_generation).state.c_str());
      it.printf(0, 13, id(calibri), "Battery SOC: %s", id(solar_battery_soc).state.c_str());
      it.printf(0, 26, id(calibri), "Battery Power: %s", id(solar_battery_power).state.c_str());
      it.printf(0, 39, id(calibri), "House Load: %s", id(current_house_consumption).state.c_str());
      if (id(grid_status).state == "Exporting") {
        it.printf(0, 52, id(calibri), id(light_green), "Exporting: %s", id(current_grid_power).state.c_str());
      }
      else {
        it.printf(0, 52, id(calibri), id(light_red), "Importing: %s", id(current_grid_power).state.c_str());
      }

Any ideas why not working?

give the display an id, then it can be turn off by lambda call: id(xxxx).turn_off().

when you need it come back, use turn_on().

Good to know, I actually got the above to work by putting all my printf logic inside the else also :slight_smile: