Hello there,
How exiting is the new macro functionality introduced in 2023.4?
But what is the return type of them?
I’m trying to replace some stuff that I’m using in almost all my integration but I’m wondering what is the return type of the macro.
Let me explain:
I’ve plenty automation templates that start like so:
{% set is_weekend = now().isoweekday() in [6, 7] %}
{% set is_conge_scolaire = is_state('calendar.conges_scolaires', 'on') %}
{% set is_ferie = is_state('calendar.jours_feries_en_belgique', 'on') %}
All these (and other stuffs) are used later in conditions like:
{{ is_weekend or is_conge_scolaire or is_ferie }}
For non English speakers, it is my way to know that the kids are at home and change the house’s behaviour.
With HA 2023.4, I started to group all those repetitive set
commands in a date.jinja
file.
Here I am, proud of myself, with my macros:
{%- macro is_weekend() -%}
{{- now().isoweekday() in [6, 7] -}}
{%- endmacro -%}
{%- macro is_conge_scolaire() -%}
{{- is_state('calendar.conges_scolaires', 'on') -}}
{%- endmacro -%}
{%- macro is_ferie() -%}
{{- is_state('calendar.jours_feries_en_belgique', 'on') -}}
{%- endmacro -%}
And I started replacing all this in my automation templates:
- id: '12536874963'
alias: Too much screen time
description: ''
trigger:
- platform: template
value_template: >
{% import date.jinja as dt %}
{{ dt.is_weekend() or dt.is_conge_scolaire() or dt.is_ferie() }}
And, crash!, bang!, nothing is working anymore.
dt.is_weekend()
is returning True
(string), not True
(boolean).
So here is my question (longest intro ever, sorry): are the macro only about text returned values or did I miss something?
Because to make it work, I’ve to do this:
- id: '12536874963'
alias: Too much screen time
description: ''
trigger:
- platform: template
value_template: >
{% import date.jinja as dt %}
{{ dt.is_weekend() == 'True' or dt.is_conge_scolaire() == 'True' or dt.is_ferie() == 'True' }}
Which makes my eyes bleed.
Thank you for your help.