I’m trying to toggle some behaviour on alternating weeks. I’ve got the following:
(((now() - as_local(as_datetime("2025-4-4 00:00:00"))).days // 7) % 2) == 0
which works just fine in the dev tools template tester. Unfortunately when testing this in a condition, it’s always false.
I’ve tested multiple dates using:
(((as_local(as_datetime("2025-4-4 18:00:00")) - as_local(as_datetime("2025-4-4 00:00:00"))).days // 7) % 2) == 0
(((as_local(as_datetime("2025-4-11 18:00:00")) - as_local(as_datetime("2025-4-4 00:00:00"))).days // 7) % 2) == 0
Again, works in the tester, fails in the condition. Any idea what’s going on here?
123
(Taras)
April 5, 2025, 12:17pm
2
Post how it appears in your automation (in YAML format). I assume it’s part of a Template Condition.
myle
(StePhan McKillen (Other kiwi Here))
April 5, 2025, 12:17pm
3
should new() be now() ???
Typo here. Not in the code.
YAML view shows the static date test as:
condition: template
value_template: >-
(((as_local(as_datetime("2025-4-18 18:00:00")) -
as_local(as_datetime("2025-4-4 00:00:00"))).days // 7) % 2) == 0
123
(Taras)
April 5, 2025, 12:22pm
6
The template is missing its outer double-braces.
condition: template
value_template: >-
{{ (((as_local(as_datetime("2025-4-18 18:00:00")) -
as_local(as_datetime("2025-4-4 00:00:00"))).days // 7) % 2) == 0 }}
Without the double-braces, it’s not interpreted as a template but a literal string.
Sigh… that’s not easy to spot.
Feature request opened: