m113
April 19, 2021, 9:25pm
1
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'
m113
April 20, 2021, 1:32am
3
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.
m113
April 20, 2021, 1:45am
5
" 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') }}
nickrout
(Nick Rout)
April 20, 2021, 7:00am
6
That is not the state. Go to the states panel in developer tools
m113
April 20, 2021, 7:04am
7
This is all I see in there? What am I looking for specifically?
sensor.date 2021-04-20 friendly_name: Date
icon: mdi:calendar
nickrout
(Nick Rout)
April 20, 2021, 7:08am
8
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.
m113
April 20, 2021, 7:16am
9
State
2021-04-20
State attributes (YAML, optional)
friendly_name: Date
icon: ‘mdi:calendar’
nickrout
(Nick Rout)
April 20, 2021, 7:21am
10
Then it is correct, are there any remaining problems?
m113
April 20, 2021, 7:22am
11
That the template sensor displays the time also, to many decimal places.
nickrout
(Nick Rout)
April 20, 2021, 8:34am
12
As I understand it now( ) includes microseconds.
m113
April 21, 2021, 8:28am
13
So what do I need to change in the template sensor to mate it display just the date? Thanks.
Troon
(Troon)
April 21, 2021, 8:35am
14
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.
m113
April 21, 2021, 8:52am
15
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.
Troon
(Troon)
April 21, 2021, 9:32am
16
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: