Date/Time Sensors

Struggling to understand what I need to do here. I have this in my YAML

- platform: time_date
display_options:
- 'time'
- 'date'

But when I use a platform template, it does not default to my only date format and shows a date and time format. What do I need to add to the platform template to tell the sensor to only show the date?

Your syntax seems to be off. Please copy this

sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'

Thanks for the reply. This is what I have in there, matches yours. Was just how it copied over/after trying to add a code block for the first time.

please share what you see in sensor.date entity.

" This entity (“sensor.date”) does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail.

You can overwrite some attributes in the entity customizations section."

Could it be an issue here?

   value_template: > 
          {%- if states('input_boolean.f_start') == "off" -%}
          {{ now () }} 

I tried…

   value_template: > 
          {%- if states('input_boolean.f_start') == "off" -%}
          {{ now ('sensor.date') }} 

That is not the state. Go to the states panel in developer tools

This is all I see in there? What am I looking for specifically?

 sensor.date	2021-04-20	friendly_name: Date
icon: mdi:calendar

There are 3 columns in the states interface, entity name, state and attributes.

Also if you click on the entity name, the state and attributes are put in the panel at the top.

State
2021-04-20
State attributes (YAML, optional)

friendly_name: Date
icon: ‘mdi:calendar’

Then it is correct, are there any remaining problems?

That the template sensor displays the time also, to many decimal places.

As I understand it now( ) includes microseconds.

So what do I need to change in the template sensor to mate it display just the date? Thanks.

I think you want {{ states('sensor.date') }} in your template, or perhaps a reformatted version:

timestamp_custom is explained here, and the format string (my %A etc) here.

The platform: time_date declaration just makes the sensor.date and sensor.time entities available to your system [docs].

If that doesn’t solve your problem, please carefully explain what you are trying to achieve.

Thanks, so assuming I don’t want to define the timestamp, to confirm is the above correct? Because that now just displays an 11 digit number.

Depends what you mean by “correct”. You now have a working template that displays the UNIX timestamp — the number of seconds since the start of 1970 — for midnight at the beginning of the current day in UTC timezone. I assume that’s not what you want, but it is syntactically correct.

Please carefully read this which explains all the time functions. as_timestamp() converts a datetime object or string to a UNIX timestamp.

The timestamp_custom() then takes that standardised timestamp and displays it how you want it — I gave an example in the prior post.

What do you want it to display, exactly, for today’s date? More examples below: