Add relative timestamp state_content for input_datetime #24135
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed change
Currently the

timestamp
attribute ofinput_datetime
entities is displayed as a simple number:While sensors with

device_class: timestamp
display a relative time string:This PR adds a relative timestamp to the state_content selector of the input_datetime entity:


Note that it doesn't replace the timestamp, it just adds another option. A freely configurable "format selector" per datatype would be better, but that would mean bigger changes. (see #20618)
I implemented this by adding a map that allows an attribute to add multiple additional options to the option list.
While I was at it, I removed the digit grouping of the
timestamp
andyear
attributes, as they didn't make sense. I thought about using thehour
,minute
,second
,day
,month
,year
to render a single nicely formatted option, but that would be beyond the scope of this PR.Type of change
Example configuration
Checklist
If user exposed functionality or configuration variables are added/changed: