Easy Time Macros for Templates!

Hello community!

:wave:

As you may know, 2023.4 offers a new global template macro option in Home Assistant.

How does this benefit you? The introduction of this feature allows me to easily share all the templates I’ve helped you create over the years in a single easy-to-use template library! All in your native language!

Introducing…

Easy Time Jinja

A 1-stop-shop for easy time calculations.

Get it from HACS!

These templates are now available in HACS, with a caveat. In order to see templates, you need to change your HACS settings to use experimental features.

Already have experimental features? Go straight to the page

Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

Adding experimental HACS features:

From your Integrations dashboard…
Open your Home Assistant instance and show your integrations.

Click on Configure on your HACS integration.

image

Check Enable experimental features and click submit.

A restart may be required.

Don’t use HACS?

Get it from the link below:

What’s inside???

  • Macros that work with entity_id’s, attributes, strings, and datetime objects.
  • Macros for relative times in your language.
  • Clock Macros.
  • Macros that count days.

For a full list of macros, check out the documents

Help Wanted!

Language Translations

I’m a native English speaker. I’m looking for help creating translations. Line 2 of the code has a dictionary with English translations. Please post in this thread if you’re uncomfortable creating PRs for translations. Any and all languages are welcome.

Time Calculation Ideas

I’ve combed through my responses to people on the forums and I’ve already added a few of the “most wanted” macros. I’m looking for more ideas. Please share them here!

Supported Languages

  • English
  • Dutch v1.0.3
  • Swedish v1.0.3
  • German v1.0.4
  • Danish v1.0.5
  • French v1.0.5.1
  • Italian v1.0.7
  • Portuguese v1.0.8
  • Croatian v1.0.8.1
  • Polish v1.0.9
  • Norwegian (bokmål & nynorsk) v1.0.9.1
  • Slavic v1.0.9.2
  • Russian v2.1.0

Coming Soon…

Support

Please post here for support.

Thank you.

34 Likes

Is the macro for Western Easter or Orthodox Easter…? The docs are a little unclear.

:laughing:

2 Likes

I didn’t know there were 2?!?? It’s definitely western :rofl:

'sv':{
    'and': 'och',
    'in': 'i',
    'ago': 'sedan',
    'now': 'nu',
    'lose': 'förlora',
    'gain': 'få',
    'time':{
      'format': '24-hr',
      'year': [
        'Å',
        'år',
        'år',
      ],
      'week': [
        'v',
        'vecka',
        'veckor',
      ],
      'day': [
        'd',
        'dag',
        'dagar',
      ],
      'hour': [
        't',
        'timme',
        'timmar',
      ],
      'minute': [
        'min',
        'minut',
        'minuter',
      ],
      'second': [
        'sek',
        'sekund',
        'sekunder',
      ],
    },
    'delta':{
      'today': 'idag',
      'tomorrow': 'imorgon',
      'yesterday': 'igår',
    },
    'days':[
      "måndag",
      "tisdag",
      "onsdag",
      "torsdag",
      "fredag",
      "lördag",
      "söndag",
    ],
    'months':[
      'januari',
      'februari',
      'mars',
      'april',
      'maj',
      'juni',
      'juli',
      'augusti',
      'september',
      'oktober',
      'november',
      'december',
    ]
  }

Please note there is two words I can’t translate without knowing how they are used in a sentence.

Lose 1 hour. Means you’ll lose -1 hour of time when dst changes
Gain 1 hour. Means you’ll gain +1 hour of time when dst changes.

Lost weight, gained weight. Gain = +1, lose = -1. Or give / take

Edit: what is sv?

Ok. Edited the post. Swedish.

1 Like

Very nice, I can’t wait.
This would be an easy way (i think) to make my automations simpler: sunscreen_last_changed > 10 minutes.

Nice Work!

Here is the German translation:

  'de':{
    '_language': 'Deutsch',
    'and': 'und',
    'in': 'in',
    'ago': 'vor',
    'now': 'jetzt',
    'lose': 'Du verlierst',
    'gain': 'Du gewinnst',
    'time':{
      'format': '24-hr',
      'year': [
        'J',
        'Jahr',
        'Jahre',
      ],
      'week': [
        'W',
        'Woche',
        'Wochen',
      ],
      'day': [
        'T',
        'Tag',
        'Tage',
      ],
      'hour': [
        'h',
        'Stunde',
        'Stunden',
      ],
      'minute': [
        'm',
        'Minute',
        'Minuten',
      ],
      'second': [
        's',
        'Sekunde',
        'Sekunden',
      ],
    },
    'delta':{
      'today': 'Heute',
      'tomorrow': 'Morgen',
      'yesterday': 'Gestern',
    },
    'days':[
      "Montag",
      "Dienstag",
      "Mittwoch",
      "Donnerstag",
      "Freitag",
      "Samstag",
      "Sonntag",
    ],
    'months':[
      'Januar',
      'Februar',
      'März',
      'April',
      'Mai',
      'Juni',
      'Juli',
      'August',
      'September',
      'October',
      'November',
      'Dezember',
    ]
  }

Cheers - Michael

3 Likes

Ooohh, you can share macros via HACS? Very cool…

Updated the post with new values

Yes you can, it’s available now too. With experimental features.

Thanks, added in 1.0.4

Petro keep in in mind that all languages do not use camel case.
I deliberately lower cases the day and month names since they are default lower case in swedish.
Only when they are the first word of a sentence are they capitalized, which should fall under normal sentencing rules.
The sentence “First Monday in January” is properly cased when written “Första måndagen i januari”.
Having capital day and month name would be wrong.

Now that I think about it, isn’t “first” and “last” something you might need translation for?

1 Like

Did not know that. Will fix in next update.

1 Like

Got the hacs update giving access to jinja templates. Very nice.

Time/date junkies may also be interested in GitHub - TheFes/relative-time-plus: Relative Time Macro with additional options

1 Like

Yep, that offers some different functionality that I do not use in my relative times. I put a link to it in the readme

1 Like

Very cool, Petro!

How about a days in month macro? If I looked correctly, the ones you have all work by weekday and won’t be covered by your “coming soon” next_day and last_day macros.

(Also, small typo in the first post: “Thanksgiving day is the 4th Thrusday in November.”)

1 Like

Yeah that can be added

1 Like

Danish:

'da':{
    'and': 'og',
    'in': 'i',
    'ago': 'siden',
    'now': 'nu',
    'lose': 'mister',
    'gain': 'tilføjer',
    'time':{
      'format': '24-hr',
      'year': [
        'Å',
        'år',
        'år',
      ],
      'week': [
        'u',
        'uge',
        'uger,
      ],
      'day': [
        'd',
        'dag',
        'dage',
      ],
      'hour': [
        't',
        'time',
        'timer',
      ],
      'minute': [
        'min',
        'minut',
        'minutter',
      ],
      'second': [
        'sek',
        'sekund',
        'sekunder',
      ],
    },
    'delta':{
      'today': 'i dag',
      'tomorrow': 'i morgen',
      'yesterday': 'i går',
    },
    'days':[
      "mandag",
      "tirsdag",
      "onsdag",
      "torsdag",
      "fredag",
      "lørdag",
      "søndag",
    ],
    'months':[
      'januar',
      'februar',
      'marts',
      'april',
      'maj',
      'juni',
      'juli',
      'august',
      'september',
      'oktober',
      'november',
      'december',
    ]
  }
1 Like

Had the same issue in danish, so I’ve just edited the danish version. Just in case that you already copied it.