Today and tomorrow sunset and sunrise

Hi

I’m trying to define the today and tomorrow sunset and sunrise, i’m using this config

# Text sensors for displaying the next sunrise and sunset
text_sensor:
  - platform: sun
    name: Sun Next Sunrise
    type: sunrise
    id: sun_next_sunrise
  - platform: sun
    name: Sun Next Sunset
    type: sunset
    id: sun_next_sunset

  - platform: template
    name: "Today's Sunrise"
    id: todays_sunrise
    icon: "mdi:white-balance-sunny"
    update_interval: 60s
    internal: false
    lambda: |-
      auto sunrise = id(sun_component).sunrise(-1);
      if (sunrise.has_value()) {
        char buffer[64];
        time_t time = sunrise.value().timestamp;
        strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", localtime(&time));
        return {buffer};
      } else {
        return {"N/A"};
      }

  - platform: template
    name: "Today's Sunset"
    id: todays_sunset
    icon: "mdi:white-balance-sunny"
    update_interval: 60s
    internal: false
    lambda: |-
      auto sunset = id(sun_component).sunset(-1);
      if (sunset.has_value()) {
        char buffer[64];
        time_t time = sunset.value().timestamp;
        strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", localtime(&time));
        return {buffer};
      } else {
        return {"N/A"};
      }

  - platform: template
    name: "Next Sunrise"
    id: next_sunrise
    icon: "mdi:white-balance-sunny"
    update_interval: 60s
    internal: false
    lambda: |-
      auto sunrise = id(sun_component).sunrise(0);
      if (sunrise.has_value()) {
        char buffer[64];
        time_t time = sunrise.value().timestamp;
        strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", localtime(&time));
        return {buffer};
      } else {
        return {"N/A"};
      }
      
  - platform: template
    name: "Next Sunset"
    id: next_sunset
    icon: "mdi:white-balance-sunny"
    update_interval: 60s
    internal: false
    lambda: |-
      auto sunset = id(sun_component).sunset(0);
      if (sunset.has_value()) {
        char buffer[64];
        time_t time = sunset.value().timestamp;
        strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", localtime(&time));
        return {buffer};
      } else {
        return {"N/A"};
      }

but something is wrong as I get only the tomorrow values, but with different times (I’m really confused)

[22:10:14][V][text_sensor:013]: 'Today's Sunset': Received new state 2023-07-16 21:09:29
[22:10:14][D][text_sensor:064]: 'Today's Sunset': Sending state '2023-07-16 21:09:29'
[22:10:19][V][text_sensor:013]: 'Next Sunset': Received new state 2023-07-16 21:02:45
[22:10:19][D][text_sensor:064]: 'Next Sunset': Sending state '2023-07-16 21:02:45'
[22:10:20][V][text_sensor:013]: 'Today's Sunrise': Received new state 2023-07-16 05:47:34
[22:10:20][D][text_sensor:064]: 'Today's Sunrise': Sending state '2023-07-16 05:47:34'
[22:27:05][V][text_sensor:013]: 'Sun Next Sunrise': Received new state 05:48:42
[22:27:05][D][text_sensor:064]: 'Sun Next Sunrise': Sending state '05:48:42'
[22:27:08][V][text_sensor:013]: 'Sun Next Sunset': Received new state 21:08:21
[22:27:08][D][text_sensor:064]: 'Sun Next Sunset': Sending state '21:08:21'

any ideas?

You might want to look at the sun2 integration instead.
It provides those sensor values easily.

@WallyR thank you, how I can get the tomorrow value in esphome?

No idea about that.
Ask the question in the ESPHome section