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.
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.
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):
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
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.
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.