Hello everybody,
I am despairing of a simple code right now. I do not understand the logic here. Can anyone help me?
I want to check, if a grocy chore date is due. I added thee lines to my code to check the boolean:
{% set SENSOR ='sensor.grocy_chores' -%}
{%- for attr in states[SENSOR].attributes.chores -%}
{% if (attr.next_execution_assigned_to_user_id == 2) -%}
{{
{
'type': 'button',
'entity': SENSOR,
'attribute': attr,
'name': attr.name,
'tap_action':
{
'action': 'call-service',
'service': 'grocy.execute_chore',
'service_data':
{
'chore_id': attr.id,
'done_by': attr.next_execution_assigned_to_user_id,
}
}
}
}},
{% set t = now().strftime("%Y-%m-%d") -%}
{%- set date = attr.next_estimated_execution_time -%}
{{ date | as_timestamp | timestamp_custom('%Y-%m-%d') <= t }}
{%- endif -%}
{%- endfor %}
{% set SENSOR = 'sensor.grocy_tasks' -%}
{%- for attr in states[SENSOR].attributes.tasks -%}
{% if (attr.assigned_to_user_id == 3) -%}
{{
{
'type': 'button',
'entity': SENSOR,
'attribute': attr,
'name': attr.name,
'tap_action':
{
'action': 'call-service',
'service': 'grocy.complete_task',
'service_data':
{
'task_id': attr.id,
}
}
}
}},
{% set t = now().strftime("%Y-%m-%d") -%}
{%- set date = attr.next_estimated_execution_time -%}
{{ date | as_timestamp | timestamp_custom('%Y-%m-%d') <= t }}
{%- endif -%}
{%- endfor %}
It changes exaclty between true and false in each chore. But if I put this template in my if condition, it doesn’t work:
type: custom:auto-entities
card:
type: entities
title: Hausaufgaben
filter:
template: >-
{% set t = now().strftime("%Y-%m-%d") -%} {% set SENSOR
='sensor.grocy_chores' -%} {%- for attr in
states[SENSOR].attributes.chores-%}
{%- set date = attr.next_estimated_execution_time -%}
{%- if (date | as_timestamp | timestamp_custom('%Y-%m-%d') <= t) -%}
{%- if (attr.next_execution_assigned_to_user_id == 2) -%}
{{
{
'type': 'button',
'entity': SENSOR,
'attribute': attr,
'name': attr.name,
'tap_action':
{
'action': 'call-service',
'service': 'grocy.execute_chore',
'service_data':
{
'chore_id': attr.id,
'done_by': attr.next_execution_assigned_to_user_id,
}
}
}
}},
{% endif %}
{%- endif -%}
{%- endfor %}
What’s the problem? Why doesn’t it work?