A bit of yaml help please - template sensor

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?

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)') }}"

Screenshot from 2020-11-02 08-14-37

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/

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

TIP: If you want to remove the leading 0 in 02 simply add a hyphen to %d like this %-d

Screenshot from 2020-11-02 08-27-57

1 Like