Hello
Since October my template has stopped working, and the data is not updated
templates.yaml:
- trigger:
- platform: time_pattern
seconds: "/5"
action:
- service: calendar.get_events
data:
duration:
hours: 2160
minutes: 0
seconds: 0
start_date_time: "{{ today_at() }}"
target:
entity_id:
- calendar.booking
- calendar.airbnb
response_variable: calendars
- variables:
ev_list: |
{% set ns = namespace(cal_events=[]) %}
{%- for key, value in calendars.items() | unique(attribute='start') %}
{%- for event in value.events %}
{%- set ns.cal_events = ns.cal_events + [event] %}
{%- endfor %}
{%- endfor %}
{{ ns.cal_events | sort(attribute='start') | list }}
in_1_unix: |
{% set dif = 16*3600 %}
{{ as_timestamp(ev_list[0].start) + dif | float }}
out_1_unix: |
{% set dif = 11*3600 %}
{{ as_timestamp(ev_list[0].end) + dif | float }}
in_2_unix: |
{% set dif = 16*3600 %}
{{ as_timestamp(ev_list[1].start) + dif | float }}
out_2_unix: |
{% set dif = 11*3600 %}
{{ as_timestamp(ev_list[1].end) + dif | float }}
actual: |
{% if as_timestamp(now()) >= in_1_unix and as_timestamp(now()) <= out_1_unix %}
{{ 1 }}
{% else %}
{{ 0 }}
{% endif %}
sensor:
- name: reservas
unique_id: reservas
state: |
{% if actual == 1 %}
{{ "reserva_actual" }}
{% else %}
{{ "no_reserva_actual" }}
{% endif %}
attributes:
scheduled_events: "{{ ev_list }}"
in_1_unix: |
{{in_1_unix}}
in_1: |
{% from 'formatter.jinja' import format_date %}
{{format_date(in_1_unix)}}
out_1: |
{% from 'formatter.jinja' import format_date %}
{{format_date(out_1_unix)}}
in_2: |
{% from 'formatter.jinja' import format_date %}
{{format_date(in_2_unix)}}
out_2: |
{% from 'formatter.jinja' import format_date %}
{{format_date(out_2_unix)}}
icon: mdi:calendar'
custom_templates/formatter.jinja:
{% macro format_date(date_unix) %}
{% set weekdays = ['Lunes','Martes','Miércoles','Jueves','Viernes','Sábado','Domingo'] %}
{% set months = ["enero", "febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"] %}
{% set dt = date_unix | timestamp_custom("%Y-%m-%d %H:%M:%S") | as_datetime %}
{{weekdays[dt.weekday()] }}, {{ dt.day }} de {{ months[dt.month-1] }} {{ dt.year }}, {{ dt.hour }}:{{ dt.minute }}{{ dt.second }}
{% endmacro %}
calendar.booking entity attributes:
message: CLOSED - Not available
all_day: true
start_time: 2024-11-14 00:00:00
end_time: 2024-11-18 00:00:00
location:
description:
offset_reached: false
friendly_name: booking
calendar.airbnb entity attributes:
message: Reserved
all_day: true
start_time: 2024-12-06 00:00:00
end_time: 2024-12-09 00:00:00
location:
description: Reservation URL: https://www.airbnb.com/hosting/reservations/details/....
Phone Number (Last 4 Digits): xxx
offset_reached: false
friendly_name: airbnb
I get sensor.reservas entity old attributes. How is it possible? I’ve reload all YAML configuration, and I still get the old data:
scheduled_events:
- start: '2024-10-31'
end: '2024-11-03'
summary: CLOSED - Not available
- start: '2024-11-14'
end: '2024-11-18'
summary: CLOSED - Not available
in_1_unix: 1730386800
in_1: Jueves, 31 de octubre 2024, 16:00
out_1: Domingo, 3 de noviembre 2024, 11:00
in_2: Jueves, 14 de noviembre 2024, 16:00
out_2: Lunes, 18 de noviembre 2024, 11:00
icon: mdi:calendar'
friendly_name: reservas