Show Input Datetime as value not as input

I have a input_datetime in my configuration that is updated using an automation. I want to display it in Home Assistant as a datetime value but it should not be editable. How can I do this?

I currently have this:

image

type: entities
entities:
  - entity: input_datetime.my_input
    name: Input
  - entity: sensor.my_datetime_sensor
    name: Date time (in dutch)

I want input_datetime.my_input to be displayed as sensor.my_datetime_sensor.

1 Like

Create a template sensor that holds the input_datetime value.

Solved it by adding the following template sensor to my configuration.yaml and using this sensor in th ui:

sensor:
- platform: template
  sensors:
    my_input:
      device_class: timestamp
      value_template: "{{ states('input_datetime.my_input') }}"
2 Likes

Above works on Chrome but in Safari it will display “Invalid date”. I needed to change the value_template to make it work in Safari:

sensor:
- platform: template
  sensors:
    my_input:
      device_class: timestamp
      value_template: "{{ as_timestamp(states('input_datetime.my_input')) | timestamp_utc | replace(' ', 'T') }}Z"

states('input_datetime.my_input') returns 2020-07-06 15:40:00 which Safari, on iOS, will display as “Invalid date” because it’s not a valid ISO 8601 formatted string.

I’ve changed the value to UTC, replaced the space with a T, and added the Z to signify the UTC timezone. The UI will translate it back to your own timezone.

Hand-rolling ISO8601 conversion seemed like a bad idea to me, especially so once I found .isoformat() in the docs (a warning note near the bottom of the Time section), but on first try it produced a value without a timezone.

After poking around some more I realized why — there was no timezone in the source data. There’s just day-month-year and hours-minutes. Makes sense actually. So I added as_local.

This is the sensor I have in the end:

sensor:
  - platform: template
    sensors:
      # ...
      next_alarm:
        device_class: timestamp
        value_template: "{{ (states('input_datetime.next_alarm') | as_datetime | as_local).isoformat() }}"
2 Likes

I know this is now three years later, but for future reference as I stumbled upon this thread with the same need:

You can now display an input_datetime as readonly in the entities card by setting the type: simple-entity option. So, updating the original example:

type: entities
entities:
  - entity: input_datetime.my_input
    name: Input
    type: simple-entity

This will show the input_datetime.my_input as a readonly date. Full documentation available at the Lovelace entities card documentation. Hope this somewhat helps!

7 Likes