Easy Time Macros for Templates!

Adding UoM didn’t change anything, but I added another sensor that is in seconds format so this one worked. Anyway to show “1 h 32 min” format instead of full “1 hour and 32 minutes”? {{ custom_time('sensor.total_sleep_0d_ago_in_seconds', 'hour, minute') }}

Hi, my request/idea below is not really a macro thing but…
I recently had to translate a few dates constructed in a template and the only repeatable option I found was to convert the date to a weekday, use the etm to translate and then add the date-number. As this is in a for/next loop, the only other alternatuve I knew (via a dict/list) made the code unreadable long
Would it be an option to add simple date-translating to this set of macro’s ?

edit, someything alike

{% from 'easy_time.jinja' import easy_translate %}

{# Overriding language or utc entity attribute #}
{{ easy_translate("2023-09-20 00:00:00", "%A %d",'de') }}

>> Mittwoch 20

This looks awsome - and it seems there have been/might come updates, so I want to install from HACS :slight_smile:

So enabled HACS experimental features, reload HACS-integration and no luck. Restart HA, and all custom frontend did not load. Click around manually and it was OK, but no luck getting the Easy-time in.

Noticed there was a new category under “add custom repository”, but easy-time was supoosedly already there. Trying to search/add it in integrations did not work, and in the top-menu there was only Integrations and Frontend to choose from.
Think it might be a HACS issue, but thought to ask in detail where I should find/install EasyTime in HACS (when experimental features are enabled)

(hacs “1.33.0”, unraid-container, core 2023.9.0

1 Like

yeah, My view was nothing like that, so started a post showing screenshots, and my little brain thought of why this might happen, , and thought of actually clearing browser cashe :wink:

so to avoid noob-errors and posts like this, perhaps add a line after the “add experimental features” to “remember to clear browser cashe - don’t be like Arve” :slight_smile:

And of course thanks a lot for the macros and the swift support :wink:

2.0.0

Breaking changes

  • every macro that starts with easy_ now rounds the value that is returned. To get old floor rounding back, add floor=True to the macro. E.g. easy_time('sensor.abc', floor=True)

New Features

  • All _time and _between macros now support a new argument, short. Setting short=True in these macros will output abbreviated times. E.g. 12hr 53min.
  • easy_time, easy_relative_time, and easy_time_between now round by default. Use floor=True to get back old functionality.
  • month and weekday now support datetime objects as inputs.

Bug Fixes

  • Fixed an issue with count_the_days returning a carriage return with the numerical day.

Optimizations

  • Translations should be faster.
  • All functions were optimized.
  • Reduced number of loops required to generate easy times.
  • Removed type conversions which slowed all _time and _between macros
  • Removed large memory footprint for phrase generation
4 Likes

2.0.0.3

Fixes

  • Fixed float → int conversion issue that sometimes caused values to be displayed with a decimal place.

getting this when enabling experimental:

all frontend elements except themes do not load.

image

no issues when I roll back to non-experimental…

After you enable experimental, you have to restart and clear your cache

1 Like

had already restarted but forgot to empty cache and hard reload. All good, Thanks for the tip!

Also love the look and feel of the list/filters (unless it was available in non-experimental and I missed it…)

1 Like

I have problems to compare to count_the_days output. Most probably there is something obviously, what I don’t see, but what?

This is working:

{% from 'easy_time.jinja' import count_the_days %}
{% set tage = count_the_days('2023-12-19')|int(default=0) %} 
{% if tage == 1 %}
  {% set tage = 'Morgen' %} 
{% endif %}
{{ tage }}

and returns “Morgen”.

But when I don’t want to int the return value, a compare is not working.

{% from 'easy_time.jinja' import count_the_days %}
{% set tage = count_the_days('2023-12-19') %} 
{% if tage == '1' %}
  {% set tage = 'Morgen' %} 
{% endif %}
{{ tage }}

returns “1”. Same für tage == 1

Why is the string compare not working here? Something hidden in the return value?

are you running an older version? There was a bug where count_the_days was returning 1\n where the \n is a carriage return.

1 Like

Yes. This was it. Working now. So my guess about “hidden” artifacts wasn’t that wrong. Thanks for the quick reply and hint.

Yeah, it bit me in the butt for quite sometime because I use that calc in other spots! It’s fresh in my mind.

Thank you for the nice library.
This is a really good idea.

I struggled quite a bit to install it using hacs as it was not showing. Until I went through the full thread here to find that I had to set HACS in experimental mode to see the Easy Time integration.

My browser is in ‘fr’, my OS (Win10) is in ‘fr’, my homeassistant instance is set to ‘fr’ and my user profile is set to ‘fr’.

Once installed, it took me a while to know that I had to edit the easy_time.jinja and hardcode my default_language in there to ‘fr’.
It probably mean that I’ll have to redo it at every update of your library ? Am I right ?

Let say that my son prefers ‘en’ and set this language in his ha profile.
Couldn’t we use the same template to display in ‘fr’ for me and in ‘en’ for him ?

Sorry if this all sounds silly… I did my best…

That’s only possible if you provide the language argument to macros based on the user. It won’t work for the frontend, but it would work for notifications.

Hi @petro , thanks for this Macro. For some reason, 12/31/23 returns ‘last Tuesday’ even though it was a Sunday. This happens for any date 12/26-12/31 it seems.

{% from 'easy_time.jinja' import speak_the_days %}
{{ speak_the_days("2023-12-31 00:00:00") }}

Result type: string
last Tuesday

Yeah, there seems to be an issue with the code, it will probably clear up on it’s own next week. I’ll have to take a look into this.

I have a couple of questions on this tool:

Is there a way of only showing the date and not the time when using as_datetime? For example, on the next DST, it works great but how can I only show the date?

You have an example on how to obtain Easter or Thanksgiving date. We know that those holidays are always on the same day of the week, but is there a way of showing the day of the week for a specific date such as what day of the week will July 4th or December 25th be?

Not really about this macro, but nonetheless:

{{ ("2024-02-26 11:23:45" | as_datetime).date() }}

The above will be according to your locale settings.

Or for custom control:

{{ ("2024-02-26 11:23:45" | as_datetime).strftime("%Y-%m-%d") }}

See The EPIC Time Conversion and Manipulation Thread!.

1 Like