Show temperature on MAX7219 only during daytime

Hi, how can I set my MAX7219digit display to show temperature only during day time and not from 10pm to 6am? Or dim?

time:
  - platform: homeassistant
    id: homeassistant_time

display:
  - platform: max7219digit
    cs_pin: D6
    num_chips: 4
    intensity: 2
    lambda: |-
      if (id(temperature).has_state())  {
      it.printf(0, 0, id(digit_font), "%.1f°C", id(temperature).state);
      } 
font:
  - file: "pixelmix.ttf"
    id: digit_font
    size: 8

It’s in the docs

There is nothing about time based switch off and on.

Use the Time component to figure out when to turn the display on/off (or set intensity).

Sorry I didn’t realize you couldn’t search the front page of esphome for the term “time”

Here, I did that for you Time Component — ESPHome

I’ve tried this but it does not work

time:
  - platform: homeassistant
    id: homeassistant_time

font:
  - file: "pixelmix.ttf"
    id: digit_font
    size: 8

display:
  - platform: max7219digit
    cs_pin: D6
    num_chips: 4
    intensity: 2
    lambda: |-
      if (id(homeassistant_time).hour >= 6 && id(homeassistant_time).hour < 22) {
        if (id(temperature).has_state()) {
          it.printf(0, 0, id(my_font), "%.1f°C", id(temperature).state);
        }
      } else {
        it.fill(0);
      }

You’re using a lambda and thus have to do it as show on the Time component page under the Use in Lambdas header.

auto time = id(homeassistant_time).now();
if time.hour ...

You don’t seem to be using the code that was given

it.turn_on_off(true or false)

I don’t understand this. Can you please write here part of lambda code which i need for this function? I could learn it from some example. I am quite a novice in lambda automation :slight_smile:

Using it.turn_on_off() :

    lambda: |-
      auto time = id(homeassistant_time).now();
      it.turn_on_off(time.hour >= 6 && time.hour < 22);

Or using it.itensity():

    lambda: |-
      auto time = id(homeassistant_time).now();
      if (time.hour >= 6 && time.hour < 22) {
        it.itensity(2);
      } else {
        it.itensity(0);
      }