lkeays
(Lkeays)
November 2, 2020, 1:03pm
1
Hi,
I’m trying to get the following:
13:45 - Tuesday (31 - 10)
I got this working:
13:45 (31 - 10)
- platform: template
sensors:
simple_time_date:
friendly_name: "Simple Time Date"
entity_id: sensor.time
value_template: "{{ as_timestamp(now()) | timestamp_custom('%H:%M \u2003 \u0028%d - %m\u0029') }}"
I got the code on another thread to get the weekdays
Today is {{ ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'][now().weekday()] }}
But after many many trials, I can’t get to merge the weekday code into the value_template…
Help please?
123
(Taras)
November 2, 2020, 1:13pm
2
If you are using version 0.117.X, this will produce the result you want:
- platform: template
sensors:
simple_time_date:
friendly_name: "Simple Time Date"
value_template: "{{ now().timestamp() | timestamp_custom('%H:%M - %A (%d - %m)') }}"
There’s no need to add the list of weekdays because the %A
parameter, in timestamp_custom
, displays the current day’s name (in English). However, you may need it if your ultimate goal is to display the day’s name in another language.
NOTE
Here’s a handy list of the options you can use with timestamp_custom
:
https://strftime.org/
lkeays
(Lkeays)
November 2, 2020, 1:23pm
3
123:
timestamp_custom
,
A Thousand Thanks!
I added the month so it now gives “14:20 - Monday, 02 November”
Your refference is gold. Thanks again.
- platform: template
sensors:
simple_time_date:
friendly_name: "Simple Time Date"
value_template: "{{ now().timestamp() | timestamp_custom('%H:%M - %A, %d %B') }}"
1 Like
123
(Taras)
November 2, 2020, 1:29pm
4
TIP: If you want to remove the leading 0
in 02
simply add a hyphen to %d
like this %-d
1 Like