DATETIME sensor template returns -1 in x.timestamp

I have a DATETIME template with an ON_VALUE option within that is a lambda that uses x.timestamp. This has contained number of seconds of the date time entered in the field. But now contains -1
When the pop-up is closed the date field on screen contains 07/02/2106
This has started happening since either 2026.3.0 or 2026.3.1

Code:

esphome:
  name: test-datetime
  friendly_name: Test DateTime

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "redacted"

ota:
  - platform: esphome
    password: "redacted"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Test-Datetime Fallback Hotspot"
    password: "redacted"

captive_portal:

globals:
  - id: durationSeconds
    type: int
    restore_value: no
    initial_value: "0"

time:
  - platform: homeassistant
    id: ha_time

datetime:
  - platform: template
    name: Unlock after time
    icon: mdi:timer-lock-open-outline
    type: DATETIME
    time_id: ha_time
    optimistic: True
    on_value: 
        then:
          - lambda: |-
              id(durationSeconds) = (x.timestamp - id(ha_time).now().timestamp);
              ESP_LOGW("main", "Duration (Seconds): %d", id(durationSeconds));
              ESP_LOGW("main", "timeNow (Seconds): %d", id(ha_time).now().timestamp);
              ESP_LOGW("main", "End Time (Seconds): %d", x.timestamp);

log file:

[12:49:10.019][D][api.connection:2440]: Home Assistant 2026.3.4 (192.168.1.132): connected
[12:49:40.207][D][datetime.datetime_entity:127]: 'Unlock after time' - Setting
[12:49:40.212][D][datetime.datetime_entity:130]:  Year: 2026
[12:49:40.215][D][datetime.datetime_entity:133]:  Month: 3
[12:49:40.221][D][datetime.datetime_entity:136]:  Day: 27
[12:49:40.226][D][datetime.datetime_entity:139]:  Hour: 0
[12:49:40.232][D][datetime.datetime_entity:142]:  Minute: 0
[12:49:40.235][D][datetime.datetime_entity:145]:  Second: 0
[12:49:40.243][D][datetime.datetime_entity:048]: 'Unlock after time' >> 2026-03-27 00:00:00
[12:49:40.248][W][main:052]: Duration (Seconds): -1774615780
[12:49:40.254][W][main:053]: timeNow (Seconds): 1774615779
[12:49:40.259][W][main:054]: End Time (Seconds): -1

Previous output:

[11:30:36.453][D][datetime.datetime_entity:127]: 'Unlock after time' - Setting
[11:30:36.454][D][datetime.datetime_entity:130]:  Year: 2026
[11:30:36.477][D][datetime.datetime_entity:133]:  Month: 3
[11:30:36.478][D][datetime.datetime_entity:136]:  Day: 27
[11:30:36.478][D][datetime.datetime_entity:139]:  Hour: 12
[11:30:36.478][D][datetime.datetime_entity:142]:  Minute: 0
[11:30:36.479][D][datetime.datetime_entity:145]:  Second: 0
[11:30:36.479][D][datetime.datetime_entity:048]: 'Unlock after time' >> 2026-03-27 12:00:00
[11:30:36.479][W][main:292]: Duration (Seconds): 1764
[11:30:36.480][W][main:293]: timeNow (Seconds): 1774611036
[11:30:36.481][W][main:294]: End Time (Seconds): 1774612800

My first step would be to change:

type: DATETIME

to

type: datetime

in line with the docs, recognising the apparent error in the config section that says type must be date or time then provides examples with datetime.

Thanks for the suggestion, but it makes no difference. Interestingly the type-ahead prompt gives DATETIME in uppercase.

Was this related to breaking changes in the recent release notes, about using the new API?
You do read the release notes carefully before hitting the update button don’t you?

I did note the changes to time component, but I’m not using any of the quoted functions - " ::mktime(), ::strftime(), setenv("TZ", ...), or tzset()". I’m only using .now() and .timestamp

I have simplified the code.

Removed the ON_VALUE entry
Removed the reference to the time component

The date passed from the pop-up back to the screen field is still 07/02/2106

I raised this on GITHUB. It is a bug and will be fixed in 2026.3.2