Service template don't work

The purpose of this automation is to turn off a component, I test with a lamp, only if no calendar is present at the date of the event’s End trigger

However, the automation never goes through “{% if (agenda.events | count) > 0 %}”

when I test the service below, it does indeed return 2 events

  • service: calendar.get_events
    target:
    entity_id:
    - calendar.42ruedesroches_gmail_com
    data:
    start_date_time: “2024-03-26 01:00:00”
    duration:
    days: 1
    response_variable: agenda

Result :

calendar.42ruedesroches_gmail_com:
events:
- start: “2024-03-23T23:00:00+01:00”
end: “2024-03-27T18:30:00+01:00”
summary: Vacances 1
- start: “2024-03-26T16:00:00+01:00”
end: “2024-03-29T16:30:00+01:00”
summary: Vacances 2
description: Les vacances se recoupent

alias: Fin evenement google calendar
description: ""
trigger:
  - platform: calendar
    event: end
    entity_id: calendar.42ruedesroches_gmail_com
condition: []
action:
  - service: calendar.get_events
    target:
      entity_id:
        - calendar.42ruedesroches_gmail_com
    data:
      start_date_time: "2024-03-26 01:00:00"
      duration:
        days: 1
    response_variable: agenda
  - service_template: |
      {% if (agenda.events | count) > 0 %}
        light.turn_on
      {% else %}
        light.turn_off
      {% endif %}
    entity_id: light.lave_linge_commutateur
mode: single

You need to use agenda['calendar.42ruedesroches_gmail_com'].events instead of agenda.events

1 Like

thanks, merci beaucoup.