Display a sensor's value only in a given time period

Hi,

I’d like to display a specific sensor on my ESP32 only in the summertime.
I have a time_homeassistant sensor and I can display the current date with

it.strftime(110, 122, id(openSansBold_font),TextAlign::BOTTOM_LEFT, "%d.%m.%y", id(time_homeassistant).now());

How would I check in this example if %m is <3 and >9 (so, between October and February?

Did you find the time functions here? That should get you a bit further along.

You might be better off locating the check in a binary sensor “is_summer” and then working with that.

1 Like

Thanks for the hint, so I’d think about something like:

auto month = id(sntp_time).now().month

I fail to understand if this is the correct syntax for obtaining the month and how to check the returned value…sorry, absolutely new to ESP32 and not an IT pro…

1 Like

This should be close.

You can test by changing .month() to .second()

binary_sensor:
  - platform: template
    id: its_summertime
    name: Its Summer Time 
    lambda: |-
      return
      id(time_homeassistant).now().month <3  &&
      id(time_homeassistant).now().month >9
      ;
      
display:
  - platform: ...
    # ...
    lambda: |-
        if (id(its_summertime).state) {
          it.strftime(110, 122, id(openSansBold_font),TextAlign::BOTTOM_LEFT, "%d.%m.%y", id(time_homeassistant).now());
        }
1 Like

Thank you!

1 Like