Skip to content

Commit a99794e

Browse files
committedMay 11, 2022
Update 2020-01-18-home-assistant-date-time-template-macros.md
* Simplify **Between hours** "Standard way" example. * Add **Between hours** "Shorter way" example.
1 parent 31db47a commit a99794e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed
 

‎_posts/2020-01-18-home-assistant-date-time-template-macros.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ date: 2020-01-18 21:00:00 -0700
44
categories: [Code Snippets]
55
tags: [Home Assistant, Jinja]
66
seo:
7-
date_modified: 2022-05-06 17:45:00 -0700
7+
date_modified: 2022-05-10 19:45:00 -0700
88
---
99

1010
Over time I have created a large library of date and time manipulation code which are used in my
@@ -157,11 +157,20 @@ Reference: [bennadel.com](https://www.bennadel.com/blog/1446-getting-the-nth-occ
157157
{% endraw %}```
158158
159159
### Between hours
160-
161160
```yaml{% raw %}
162-
{% if now().hour < 12 and now().hour > 6 %}
161+
# Standard way
162+
{% if 6 <= now().hour and now().hour < 12 %}
163+
0.25
164+
{% elif 12 <= now().hour and now().hour < 17 %}
165+
0.40
166+
{% else %}
167+
0.20
168+
{% endif %}
169+
170+
# Shorter way
171+
{% if 6 <= now().hour < 12 %}
163172
0.25
164-
{% elif now().hour > 12 and now().hour < 17 %}
173+
{% elif 12 <= now().hour < 17 %}
165174
0.40
166175
{% else %}
167176
0.20

0 commit comments

Comments
 (0)
Please sign in to comment.