Custom date not updating in UI

Hello, I am using following code for custom date, I can see this does not updates itself.
Can you please let me know what should I do to change this please.

Thank you.

  - platform: template
    sensors:
      date_template:
        friendly_name: 'Date'
        value_template: '{{ as_timestamp(now()) | timestamp_custom("%d / %B(%m) / %Y - %A", True) }}'

Your template isn’t creating an entity which will trigger an update. If you’re only after the date (updated once a day) you can add unique_id: xxxxxxx, which will give you a sensor which can be updated by an automation - say, at midnight. Alternatively you can find docs on time templates which update automatically in “Working without Entities” here.

can you be more specific on that?

I’ve never seen that mentioned anywhere. Where did you find any reference to it?

Sorry! :smile: Here’s what I use to get the date:

platform: template
sensors: 
  today:
    unique_id: 'today'
    value_template: "{{ now().timestamp() | timestamp_custom:('%A %B %d') }}" 

This gives the date in the format “Thursday 15 October”. Without unique_id: ‘today’ it’s only a snapshot of the date at the moment configuration.yaml was loaded, but unique_id: ‘today’ creates a sensor sensor.today which can be updated in any automation (I use one that runs at midnight):

action:
- service: homeassistant.update_entity
  entity_id: sensor.today
    

Documentation (very brief) is here for unique_id and here for update_entity.

Why not create a date sensor and use it like this:

platform: template
sensors: 
  today_friendly_format:
    value_template: >
      {% set x = sensor.date %}
      {{ now().timestamp() | timestamp_custom:('%A %B %d') }}

instead of creating an automation?
The above will automatically update the sensor every day at midnight. If you want to update it every minute you can use the sensor.time instead of sensor.date

1 Like

That’s wrong. unique_id is used to to be able to edit the icon etc. in the UI. It’s even explained like that in the docs you linked…
With your automation you are updating the entity, unique_id is not needed for that. Change your unique_id to something else, but leave your automation the same and you’ll see that it continues to work.

1 Like

neither of those references you posted say anything about using “unique_id” in the way you think you are using it.

The reason it works in your code is because you are updating the date with an automation. It’s not updating because you added “unique_id” to the sensor config. The only thing unique_id does for you is it adds it to the entity registry.

If you leave it out you will still have an entity in the dev tools->states list called “sensor.today”. It just won’t show up in the entities list in the configuration menu. But it will still work exactly like it does now. Specifically, it won’t ever update until you force the update with an automation or by calling the entity_update service on that entity in some other way.

to the OP:

Just use the code as Burningstone suggested and it will work without the need to create any other automations.

1 Like