Template time format still english instead german

hah, python stuck in my head.

Yah, i have no idea. I just copied @Bigfork’s image. Apparently z = ts in my brain.

I think this will be a bit different for any other language. I’ll post an english one later. Feeling a bit lazy atm.

Hmm, any updates here? I think there’s a bug in the first line where the hour is updated to +1 if the minute is greater than 8. I think this needs to be 38 (or something close to this. can’t test as I don’t have remote access to my HA). I think you want to update the hour only when the minute lands within the “half past” integer range (or in German the “30mins to the next hour” range). Anyway, if no updates, I can work with this, thanks a lot for all your efforts or rather, “Bemühungen” :wink:

Here you go. For a little bit of fun, I made at Swiss German format based on the code from OP above.

{% set hour = now().strftime("%-H") | int %}
{% set minute = now().strftime("%-M") | int %}

{% set hour = hour if minute < 23 else hour + 1 if hour + 1 < 24 else 0 %}
{% set hour = hour if hour < 13 and hour > 0 else hour - 12 if hour > 0 else 12 %}

{% set hourwords = ['zwöufi', 'eis', 'zwöi', 'drü', 'vieri', 'füfi', 'sächsi',
                    'sibni', 'achti', 'nuni', 'zäni', 'eufi','zwöufi'] %}
{% set hourword = hourwords[hour] if hour >= 0 else '' %}

{% set i = minute // 15 - 1 %}
{% set quarters = ['viertu ab', 'haubi', 'viertu vor' ] %}
{% set quarter = quarters[i] if i >= 0 else '' %}
{% set remainder = minute % 15 %}
{% set end = '' if i == -1 and remainder in [0,1] or i == 2 and remainder == 14 else '' %}
{% set shortly = 'kurz' if remainder not in [14,0,1] else '' %}
{% if remainder == 14 %}
  {% set quarter = quarters[i+1] if i + 1 < quarters | length else '' %}
{% endif %}
{% set beforeafter = '' %}
{% if shortly %}
  {% set beforeafter = 'ab' if remainder in range(2,8) else 'vor' %}
  {% if beforeafter == 'vor' %}
    {% set quarter = quarters[i+1] if i + 1 < quarters | length else '' %}
  {% endif %}
{% endif %}
{% set items = ['Es isch', shortly, beforeafter, quarter, hourword | string , end] %}
{{ items | reject('eq','') | list | join(' ') }}

Output String

Es isch viertu ab zwöi

far from perfect, but good enough for now. Will definately add the 10’s in there along with the quarters when I get more time, “10 past, zäni ab”, “20 past, zwänzg ab”, “10 to, zäni vor” …

1 Like