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