Template time format still english instead german

Maybe, but I’m getting old and anyway I like to start the week easy.
:rolf:

Why ? Do you have a ‘bad’ accent ? Can’t be any worse than … (I’ve heard guys from Munchen complain about people from the South East of Bavaria ! (Maybe it’s anyone from the South East of ANY country ? :rofl: :rofl: :rofl:, nah, only kidding ! )

2 Likes

Thats it! Thanks a lot @Mutt and @Burningstone !

image

I read a little about to define the german translations and played a little with it but was not successful. I think I dont have the understanding yet how the reference between the code to display the date and the “translation” is made.

If I understand the entire code correctly: “weekdays” and “months” can be named anything, correct? I just put the definition behind it?
Also strftime is only used to display the “Date Number” and the year, right?
And: How is the beginning and end of the code defined? Or is this not necessary for python?

P.S. I accept Swiss German as a really cute form of german :smiley:

1 Like

Oooooh that’s a low blow ! :rofl:

Basically you need to gain access to HA’s python sandbox (an area where code can run in a low risk area, where evaluations can only do limited things like printing). To do this we submit them as templates. The template is rendered in Jinja2 a print formatting language, there are 4 things that can be put in Jinja2

  1. raw text - bad, the results can be unpredicatble
  2. comments
  3. evaluations
  4. print statements (bear with me, we put print statements in and this is what we get out)
{# this is a comment, I can put anything in here #}
{{ 'This is a print statement and I can use it to include standing text' }}
{# the following is an evaluation setting a variable to a name #}
{% set brian = 'A Very Naughty Boy !' %}
{# ... and printing that out (for example) : - #}
{{ 'Brian is ' ~ brian }}
{# prints "Brian is A Very Naughty Boy !" #}
{# the tilde charachter (~) concatenates (joins) strings #}
{# square brackets [] can be used to define an array, a list of items from which you can pick #}
{# so your weekdays are : - #}
{% set weekdays = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"] %}
{# and similarly your months are : - #}
{% set months = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"] %}
{# weekdays[3] takes the 4th element of 'weekdays', 0 is the first #}
{{ "Es ist " + weekdays[now().weekday()] + ", der " + now().strftime("%-d") + ". " + months[now().month - 1] + " " +  now().strftime("%Y")}}
{# This last is merely a print statement assembling all the little bits together #}

now().weekday() returns the day of the week for now(), 0 to 6, 0 = Monday, 1 = Tuesday etc
now().month returns 1 to 12 hence the -1 to align the array
And the rest is just your personal bent on arranging the wording.

Apparently there are 22 different ways of telling the time across Germany with one option being “It is 2 minutes past, 10 minutes to 3” So I won’t comment on your format.

Hope that helps

Yep ! could be called ‘yellow’ or ‘monkey_nuts’

This is your template (enter it into the template editor under developers tools)
If you create (say) a sensor it would look like : -

sensor:
  - platform: template
    sensors:
      today_is:
        entity_id: sensor.date
        friendly_name: Today Is : -
        value_template: >
          {% set yellow = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"] %}
          {% set monkey_nuts = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"] %}
          {{ "Es ist " + yellow[now().weekday()] + ", der " + now().strftime("%-d") + ". " + monkey_nuts[now().month - 1] + " " +  now().strftime("%Y")}}

the “>” indicates this is a multi-line template and thus a) starts on the line below b) doesn’t need quotes (otherwise put double quotes on the outside and singles on the inside)
[Note: I copied Burnings template, and he’s a bit sloppy with discipline ( it appears ! :roll_eyes: ) ]

This will appear as an entity when you restart.

2 Likes

Woaw…this explains a lot. Thanks @Mutt!

That means basically I can use templates for mathematical things too and convert them into a sensor? I get a raingauge delivered in hopefully less than a monkeynut and need to convert the pulses in rainfall (mm per square meter)

Is there somewhere a documentation readable for Germans with Twins who don’t care about a proper sleep schedule? Means: simple? :smiley:

Not really, the basic stuff is python (I just explained the jinja wrapping). Though Google may offer something. And many examples on this forum.
The sandbox does not support all python (that would be dangerous) but a limited subset.
Mathematical and time options are the most common uses. I would classify yours above to be a bit ‘text biased’ .
The template editor is your best friend, have a play.
Any issues, just ask a question, template specialists are a subset of people here but they are good and ‘mostly’ very helpful - explaining ‘why ?
We love a good puzzle.
As Marius says (a guy here on the forum) whatever the question, the answer is usually a template

2 Likes

Flo, (I assume that’s Florian ???)
There is another thread that goes into time and calculation in a bit more depth.
Yeah, I know, you will tend to see the same faces popping up in such threads.
It ‘may’ help as a reference if you need something in the future.

Note: Burning got the solution credit on this one too :angry: ( :rofl: ) but read the whole thread (it’s long one) for some of the wrinkles we worked out towards the end.
Mainly to get the idea of what is possible.

1 Like

For that I’d use the Python Script integration. It’s used a bit differently as it just provides a service, but in terms of functionality it’s a bit more flexible, as it’s really Python. Here I posted an example to calculate absolute humidity. It was also solved using templates by others. So there’s no right or wrong here. But I guess it’s good to know about the possible alternatives. :+1:

1 Like

Thats correct :slight_smile: But i get chills to hear the full name as I heard it only from my Mum and Grandmother when I was in big trouble :smiley:

Thanks for the link. Looks interesting and I think is the solution for my other problem I have: Shutting down a notification automation after it send the message. I have a rainsensor (a little to sensitive as it seems) and when it´s on it should send the mentioned message. Sadly that thing switches of to fast which results in a “rainfall of notifications” (pun intended)

Will dig through this and try to understand :slight_smile:

I assume when this raingauge will arrive you guys will have your puzzle. And maybe you´ll be first :slight_smile:

Ah this looks a little familar to the PHP scripts i stole from my other Smarthome Platform forums before :slight_smile:
Aaaand i think I´ll use this as I need the absolute humidity too :slight_smile:

But what is the difference between a service and a sensor in this case? Don´t i need a sensor anyways to start an automation? In my case it will be: If it rains x mm/m² don´t run the irrigation which should start at xxx am/pm

I’ve heard guys from Munchen complain about people from the South East of Bavaria

I’m working on a Bavarian time script. Can I get some help converting 7:45 to dreiviertel acht? :rofl:

1 Like

That would look awesome Home Assistant Oktoberfest Edition :joy:

I understood dreiviertel to mean three/quarters so 3/4 eight is 15 mins to 8.?
I don’t understand ?
Would this be 12 hr or 24 hr ?
I’m sure we could work something out but we’d need some more guidance for how to format the text.
For Example - all the minutes from (say) 3:00 to 4:00 and if that can be applied to all hours in the range.

1 Like

Yes. Dreiviertel Acht is 3/4 before eight and used in distinct areas in Germany. Honestly not all Germans get it ( mee too ) :sweat_smile:

I know that there is “Viertel” acht which is 7:15 (See…it’s complicated.)

So basically he would need

xx:15 = viertel
xx:30 = halb
xx:45 = Dreiviertel

And in 12 hours format.

But I would wait till he replies if it’s a joke or not :smile:

I understood dreiviertel to mean three/quarters so 3/4 eight is 15 mins to 8.?

Yes, you have it right. German is so much more logical than English when it comes to spelling, pronunciation and grammar but there are some “peculiarities”. Perhaps it’s a Bavarian thing. So while “half eight” in English means half-past eight, in German it means half-way to eight, or 7:30. “Three-quarter eight,” similarly, is three-quarters of the way to eight. It’s mind-boggling to an anglophone like myself but I’m sure English is more maddening to learn for my German friends since there are more exceptions than rules :smiley:

My bucket list project is to build one of these clocks powered by a SBC or some sorts. I’ll need to work out a way for it to display “kurz nach dreiviertel acht” :rofl:
https://storede.qlocktwo.com/de/qlocktwo-large

Edit: I am joking about the script but if you wanted a challenge, then there you go! :smiley: I do want to build that clock though.

The way the script would work would be, that you have an automation that calls the script as soon as one of the relevant sensors change. The service call would contain the entity IDs which are needed to calculate the absolute humidity.
The problem with all this is, that - at least in the example - it just fires an event. But you could also trigger an automation, or manually set the state of some dummy-sensor. So how you are going to use it is up to you. I myself never used it, so I don’t know which route would make sense from a practical point of view. And as this is also quite old, the exact code how to fire an event might have changed as well. But I think you’ll find some useful information when you dig deeper here in the forum while searching for topics related to the python-script integration. :+1:

BTW: For those who struggle with “viertel 8”, imagine the 8 is a Pizza. If you ate 3/4 of it, you only have “viertel Pizza” because you are 3/4 away from happiness.

1 Like

I’m currently building a word clock 1m Square, so this is doable
Mine would have 5 minute resolution and a cheat 4 dots to add 0 to 4 mins to give me a full minute resolution.
Having said that I still don’t understand your resolution as it seems just be on the quarter hour. eg when would it change ?

Edit: It must change (for efficiency) on a whole minute, say at 7 or 8 minutes past not 7:30 m:s

Having said that I still don’t understand your resolution as it seems just be on the quarter hour. eg when would it change ?

This is getting off topic :slight_smile: Once I get started I might start a thread on the subject, but my idea was to copy the QCLOCKTWO but with less precision. That clock changes for every minute, “Es ist sechs nach drei”, “Es ist viertel nach funf”, etc. I was thinking: +/- 1 minute of the quarters to just state the hour/halb/viertel/dreiviertel. For +2’ to +7’ have “kurz nach” the respective quarter and for -7’ to -2’ have “kurz vor” the respective quarter. If I need more precision that, I can look at my damn watch :wink: That gives me the hour broken down into 12 (not equal) segments. Should be amusing and give good enough time precision for a wall clock.

Hmmm off-topic …
The QClockTwo was one of the designs I looked at for my design and the weirdest was : -

I don’t like the moving parts though (maintenance)
I went with a 13 x 13 grid laser cut into 2mm copper plate
The hardest bit was selecting a good stencil font and squaring the resultant letter aspect ratios.
Yet to decide if I’ll go Raspberry Pi Zero W or Arduino

But that’s not my point if you can get your logic worked out to display we can get the text in a sensor, observe it over time and make any tweaks you need.

So … Any time after (say) 7 (but not 7 itself) the hour is listed as 8 ??? with the minutes shown as ???
(just make it easy for me :rofl:
Burning, feel free to jump in any time here :switzerland:

1 Like

OK, just to get this thread fully off the rails. Here’s how I see the “logic” :rofl:

might need to test it out. Also lingo is probably wrong around midnight… mainly because I don’t know german.

{% set hour = hour if minute < 8 else hour + 1 if hour + 1 < 24 else 0 %}
{% set i = minute // 15 - 1 %}
{% set quarters = ['viertal', 'halb', 'dreiviertel' ] %}
{% set quarter = quarters[i] if i >= 0 else '' %}
{% set remainder = minute % 15 %}
{% set end = 'Uhr' if i == -1 and remainder in [0,1] or i == 2 and remainder == 14 else '' %}
{% set shortly = 'kurts' 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 = 'nach' 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 ist', shortly, beforeafter, quarter, hour | str , end] %}
{{ items | reject('eq','') | list | join(' ') }}
2 Likes