Convert date and time template

Great, thanks a lot.
Works as I wanted.

Hi all,

I would like to use the format-tag for weekkday (%A) but HA shows only the en_US names and not the de_DE names. The UI is configured in gernman and I do not understand, why the weekday names are in english.

I am using the VM from HA and the OS is:

cat /etc/*release
3.16.1
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.16.1
PRETTY_NAME="Alpine Linux v3.16"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"

I cannot find any command to check the locales on the OS. Can anyone tell me how to switch to de_DE?

Thanks,
Spartacus

Home Assistant’s templating language is English and doesn’t support the operating system’s locale. That means strftime produce day and month names exclusively in English.

You’ll have to perform the translation yourself. For example:

['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'][now().weekday()] }}
1 Like

Hi,

ok, thanks, its a little bit strange, that this is not included, but its ok.

I don’t know if this is the right thread to ask this question, but I am having seemingly a timezone issue with timedelta calculation.
I am trying to calculate the remaining printing time by calculating the time delta between now and the

{% set done = as_timestamp(states("sensor.octoprint_estimated_finish_time")) %}
{% set current = now().timestamp() %}
{% set delta = done - current %}
Estimated finishing point is {{ done | timestamp_custom("%H:%M:%S")}} # 15:09:00
Current time is {{ now().timestamp() | timestamp_custom("%H:%M:%S") }} # 15:08:00
The delta between them is {{ delta | timestamp_custom("%H:%M:%S")}} # # 01:01:00

I can see, that the timezone of my current time and the sensor are correct (UTC+1).
But how do I get the formatter to use the UTC-timezone now, since it only describes the timedelta and no timezone?

Use datetimes instead of timestamps and you won’t have this confusion or issue.

{% set done = states("sensor.octoprint_estimated_finish_time") | as_datetime | as_local %}
{{ done - now() }}

It will most likely have microseconds. If you don’t want that…

{% set done = states("sensor.octoprint_estimated_finish_time") | as_datetime | as_local %}
{{ done - now().replace(microsecond=0) }}
2 Likes

I have also : “-1 day, 23:47:00” and need your help to make this example just “13 minutes”.

Thank You.