core icon indicating copy to clipboard operation
core copied to clipboard

strptime getting an error on evaluating datetime

Open akramh opened this issue 2 years ago • 4 comments

The problem

The below has been working for years for some reason it suddenly spitting this error. Any ideas what has changed

{{ strptime(states("sensor.time_date"), "%Y-%m-%dT%H:%M:%S") }}

ValueError: Template error: strptime got invalid input '12:22, 2022-11-05' when rendering template '{{ strptime(states("sensor.time_date"), "%Y-%m-%dT%H:%M:%S") }}' but no default was specified

Home Assistant 2022.11.1 Supervisor 2022.10.2 Operating System 6.6 Frontend 20221102.1 - latest

What version of Home Assistant Core has the issue?

2022.11.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

No response

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

akramh avatar Nov 05 '22 19:11 akramh

The below has been working for years ... states("sensor.time_date")

What is sensor.time_date? Which integration produces that sensor?

It's not a sensor from the Time & Date integration because it creates an entity called sensor.date_time.

tdejneka avatar Nov 05 '22 22:11 tdejneka

It is from Time & Date. Am i using an older version then? see below

image

akramh avatar Nov 06 '22 14:11 akramh

full result here showing the sensor works fine.

image

akramh avatar Nov 06 '22 14:11 akramh

You're right; I was mistaken. sensor.time_date is produced by the Time & Date integration.

  • sensor.date_time displays date first followed by time.
  • sensor.time_date displays time first followed by date.

You're saying sensor.time_date used to display the same way as sensor.date_time? Which version of Home Assistant did that?

tdejneka avatar Nov 06 '22 15:11 tdejneka

ValueError: Template error: strptime got invalid input '12:22, 2022-11-05' when rendering template '{{ strptime(states("sensor.time_date"), "%Y-%m-%dT%H:%M:%S") }}' but no default was specified

Am I wrong or the input string is not in the specified format ?

Simone

chemelli74 avatar Nov 07 '22 00:11 chemelli74

"%Y-%m-%dT%H:%M:%S" clearly expects the supplied string to begin with the date and end with the time. However, that's the order presented by sensor.date_time not sensor.time_date. Yet the claim is that the template "worked for years" with sensor.time_date.

I don't see how that's possible unless previous versions of sensor.time_date presented the date first which is the implied claim of "worked for years". To my knowledge, there's been no change in how sensor.time_date reports its value (time first, date last).

tdejneka avatar Nov 07 '22 21:11 tdejneka