Time and date sensor

Hi.
were is my time and date sensor entities?
cant find them.
just Finnish my new HA installation on RP 3B and
there no time/date sensor.
do i need to write something in Configuratin.yaml?

Thanks
Refael

Check if you have enabled the time_date platform in your configuration.yaml, also see this link: https://www.home-assistant.io/components/sensor.time_date/

Hi.
once again Thanks for the replay. you right. now it’s working.
Thanks .

Refael

I have mine enabled in yaml but only the first two work in the template editor, the rest return “unknown”.
ie
{{states(‘sensor.date’)}} returns 2020-01-17
{{states(‘sensor.time’)}} returns 11:29
{{states(‘sensor.time_date’)}} returns unknown

Is there a way to have the time display in 12 hour not 24

no there is not a way, unless… you are a programmer…

Wow, what a surprise. Why is not this activated by default? And on top of that… why is not said on all the references that you need this to be manually activated? It was really unexpected

What are you trying to do? Chances are, you don’t even need this sensor. You can do everything without it, automations, scripts, timing, etc. The only reason you’d want to add this is for display in the UI.

          {% set t = states('sensor.time') %}

And I think being able to display text and dates is common enough

that still doesn’t explain what you are trying to do. You don’t need the sensor for that.

{% set t = now().strftime('%H:%M') %}

Will get you the same thing. But if you’re trying to compare times in a template, there’s much easier ways now.

The way the time and date is displayed is governed by the language chosen for each user’s Profile.

For example, if I select this:

Screenshot from 2022-02-01 12-25-29

it will display time with AM/PM:

Screenshot from 2022-02-01 12-24-51

but if I choose this:
Screenshot from 2022-02-01 12-27-46

it displays it in 24h time:

Screenshot from 2022-02-01 12-23-58

However, that’s just for display purposes. The values of date/time-based sensors remain in ISO format.

Screenshot from 2022-02-01 12-30-21

ON mi specific example, I just wanted something that updates every second to keep a visual element up to date.
And the thing that lead me to this post was putting the current time on an external display.
Is this API then deprecated?

Nothing updates every second in HA unless you make an automation that does that (or you have a hardware sensor that does that). Templates are throttled to updates based on the input sensor or now() updates once per minute.

No, there’s just easier ways to do it now in templates.

This would be a template sensor that would update once per second.

template:
- trigger:
    - platform: time_pattern
      seconds: "/1"
  sensor:
  - name: time
    state: "{{ now().strftime('%H:%M:%S') }}"
2 Likes

Once per minute was good enough to my usecase, sorry for the confusion.
Thanks for the template in any case

Why “adesso” is wrong?

{{states('sensor.date')}}
{% set oggi = as_timestamp(states("sensor.date")) | timestamp_custom('%d/%m/%Y') %}
{{ oggi }}
<-------------------------->
{{states('sensor.time')}}
{% set adesso = as_timestamp(states('sensor.time')) | timestamp_custom('%H:%M') %}
{{ adesso }}

Because as_timestamp doesn’t convert a partial time string into a timestamp.

Excuse my ignorance…
If timestamp = date+time
See example here
and

as_timestamp doesn’t convert a partial time string into a timestamp.

why
as_timestamp convert a partial data string into a timestamp?
(see “oggi” in my screenshot)

Thanks for your attention.

It can only read partial timestamps left to right, and it has to start with the date.

Instead of asking this very narrow viewed question, how about you explain your end goal with the template. There have been many improvements to templates and dates over the past year.